summaryrefslogtreecommitdiff
path: root/app/finders/projects/topics_finder.rb
blob: c26b166a786c5135bd13d239a97ea5a0b048095b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

# Used to filter project topics by a set of params
#
# Arguments:
#   params:
#     search: string
module Projects
  class TopicsFinder
    def initialize(params: {})
      @params = params
    end

    def execute
      topics = Projects::Topic.order_by_non_private_projects_count
      by_search(topics)
    end

    private

    attr_reader :current_user, :params

    def by_search(topics)
      return topics unless params[:search].present?

      topics.search(params[:search]).reorder_by_similarity(params[:search])
    end
  end
end