You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SearchService < BaseService
|
|
|
|
def call(query, limit, resolve = false)
|
|
|
|
return if query.blank? || query.start_with?('#')
|
|
|
|
|
|
|
|
username, domain = query.gsub(/\A@/, '').split('@')
|
|
|
|
|
|
|
|
results = if domain.nil?
|
|
|
|
Account.search_for(username)
|
|
|
|
else
|
|
|
|
Account.search_for("#{username} #{domain}")
|
|
|
|
end
|
|
|
|
|
|
|
|
results = results.limit(limit)
|
|
|
|
|
|
|
|
if resolve && results.empty? && !domain.nil?
|
|
|
|
results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")]
|
|
|
|
end
|
|
|
|
|
|
|
|
results
|
|
|
|
end
|
|
|
|
end
|