about summary refs log tree commit diff
path: root/app/services/search_service.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-03-17 20:47:38 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-03-17 20:48:14 +0100
commitad0d82d3cee27839371b3182b434d8e78092890a (patch)
tree1028396d66d956c2a1ed696e59a9e4c41c123fed /app/services/search_service.rb
parent22f9399cc30b2fa41a2813ccf559b7fd05be251d (diff)
Make account search blazing fast and rank followers/followees higher in the results
Diffstat (limited to 'app/services/search_service.rb')
-rw-r--r--app/services/search_service.rb7
1 files changed, 3 insertions, 4 deletions
diff --git a/app/services/search_service.rb b/app/services/search_service.rb
index 6f740e149..19fc16973 100644
--- a/app/services/search_service.rb
+++ b/app/services/search_service.rb
@@ -1,7 +1,7 @@
 # frozen_string_literal: true
 
 class SearchService < BaseService
-  def call(query, limit, resolve = false)
+  def call(query, limit, resolve = false, account = nil)
     return if query.blank? || query.start_with?('#')
 
     username, domain = query.gsub(/\A@/, '').split('@')
@@ -9,13 +9,12 @@ class SearchService < BaseService
 
     if domain.nil?
       exact_match = Account.find_local(username)
-      results     = Account.search_for(username)
+      results     = account.nil? ? Account.search_for(username, limit) : Account.advanced_search_for(username, account, limit)
     else
       exact_match = Account.find_remote(username, domain)
-      results     = Account.search_for("#{username} #{domain}")
+      results     = account.nil? ? Account.search_for("#{username} #{domain}", limit) : Account.advanced_search_for("#{username} #{domain}", account, limit)
     end
 
-    results = results.limit(limit).to_a
     results = [exact_match] + results.reject { |a| a.id == exact_match.id } if exact_match
 
     if resolve && !exact_match && !domain.nil?