about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-11-12 14:33:21 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-12 14:36:10 +0100
commit09218d4c0152013750dd1c127d3c8267dc45f880 (patch)
tree7cd9975b84a28de92403c80f483d08e471b10155 /app/services
parentcd765f26a9610e160ffd347637fca40d7b80164e (diff)
Use full-text search for autosuggestions
Diffstat (limited to 'app/services')
-rw-r--r--app/services/search_service.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/services/search_service.rb b/app/services/search_service.rb
new file mode 100644
index 000000000..d9b627853
--- /dev/null
+++ b/app/services/search_service.rb
@@ -0,0 +1,25 @@
+class SearchService < BaseService
+  def call(query, resolve = false)
+    return if query.blank?
+
+    username, domain = query.split('@')
+
+    if domain.nil?
+      search_all(username)
+    else
+      search_or_resolve(username, domain, resolve)
+    end
+  end
+
+  private
+
+  def search_all(username)
+    Account.search_for(username)
+  end
+
+  def search_or_resolve(username, domain, resolve)
+    results = Account.search_for("#{username} #{domain}")
+    return [FollowRemoteAccountService.new.call("#{username}@#{domain}")] if results.empty? && resolve
+    results
+  end
+end