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-22 02:32:27 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-03-22 02:32:27 +0100
commit05cf086766396745219582951f9b792ac5ed2bfb (patch)
tree8ea8471b0565847f41fca533d0e100b181593fa0 /app/services/search_service.rb
parent98571b0ce4b63c5ce4198681fa4e3800938f4c9e (diff)
New API method: /api/v1/search
Returns accounts, statuses, hashtags arrays
Diffstat (limited to 'app/services/search_service.rb')
-rw-r--r--app/services/search_service.rb23
1 files changed, 9 insertions, 14 deletions
diff --git a/app/services/search_service.rb b/app/services/search_service.rb
index 19fc16973..159c03713 100644
--- a/app/services/search_service.rb
+++ b/app/services/search_service.rb
@@ -2,23 +2,18 @@
 
 class SearchService < BaseService
   def call(query, limit, resolve = false, account = nil)
-    return if query.blank? || query.start_with?('#')
+    return if query.blank?
 
-    username, domain = query.gsub(/\A@/, '').split('@')
-    domain = nil if TagManager.instance.local_domain?(domain)
+    results = { accounts: [], hashtags: [], statuses: [] }
 
-    if domain.nil?
-      exact_match = Account.find_local(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.nil? ? Account.search_for("#{username} #{domain}", limit) : Account.advanced_search_for("#{username} #{domain}", account, limit)
-    end
+    if query =~ /\Ahttps?:\/\//
+      resource = FetchRemoteResourceService.new.call(query)
 
-    results = [exact_match] + results.reject { |a| a.id == exact_match.id } if exact_match
-
-    if resolve && !exact_match && !domain.nil?
-      results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")]
+      results[:accounts] << resource if resource.is_a?(Account)
+      results[:statuses] << resource if resource.is_a?(Status)
+    else
+      results[:accounts] = AccountSearchService.new.call(query, limit, resolve, account)
+      results[:hashtags] = Tag.search_for(query.gsub(/\A#/, ''), limit) unless query.start_with?('@')
     end
 
     results