Use full-text search for autosuggestions
This commit is contained in:
parent
cd765f26a9
commit
09218d4c01
14 changed files with 153 additions and 39 deletions
25
app/services/search_service.rb
Normal file
25
app/services/search_service.rb
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue