donphan/app/services/search_service.rb

22 lines
486 B
Ruby
Raw Normal View History

class SearchService < BaseService
2016-11-12 13:49:28 +00:00
def call(query, limit, resolve = false)
return if query.blank?
username, domain = query.split('@')
2016-11-12 13:49:28 +00:00
results = if domain.nil?
Account.search_for(username)
else
2016-11-12 13:49:28 +00:00
Account.search_for("#{username} #{domain}")
end
2016-11-12 13:49:28 +00:00
results = results.limit(limit).with_counters
2016-11-12 13:49:28 +00:00
if resolve && results.empty? && !domain.nil?
results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")]
end
results
end
end