summaryrefslogtreecommitdiff
path: root/app/finders/projects/topics_finder.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/finders/projects/topics_finder.rb')
-rw-r--r--app/finders/projects/topics_finder.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/app/finders/projects/topics_finder.rb b/app/finders/projects/topics_finder.rb
new file mode 100644
index 00000000000..7c3abc27cf7
--- /dev/null
+++ b/app/finders/projects/topics_finder.rb
@@ -0,0 +1,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_total_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