about summary refs log tree commit diff
path: root/app/services/search_service.rb
blob: 9e8ee6220bc5c7fd28265b052255f7b42e296a7b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class SearchService < BaseService
  def call(query, limit, resolve = false)
    return if query.blank?

    username, domain = query.split('@')

    results = if domain.nil?
      Account.search_for(username)
    else
      Account.search_for("#{username} #{domain}")
    end

    results = results.limit(limit).with_counters

    if resolve && results.empty? && !domain.nil?
      results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")]
    end

    results
  end
end