2016-11-16 02:56:29 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-13 00:33:21 +11:00
|
|
|
class SearchService < BaseService
|
2017-03-18 06:47:38 +11:00
|
|
|
def call(query, limit, resolve = false, account = nil)
|
2017-03-22 12:32:27 +11:00
|
|
|
return if query.blank?
|
2016-11-13 00:33:21 +11:00
|
|
|
|
2017-03-22 12:32:27 +11:00
|
|
|
results = { accounts: [], hashtags: [], statuses: [] }
|
2016-11-13 00:33:21 +11:00
|
|
|
|
2017-03-22 12:32:27 +11:00
|
|
|
if query =~ /\Ahttps?:\/\//
|
|
|
|
resource = FetchRemoteResourceService.new.call(query)
|
2016-11-13 00:33:21 +11:00
|
|
|
|
2017-03-22 12:32:27 +11:00
|
|
|
results[:accounts] << resource if resource.is_a?(Account)
|
|
|
|
results[:statuses] << resource if resource.is_a?(Status)
|
|
|
|
else
|
|
|
|
results[:accounts] = AccountSearchService.new.call(query, limit, resolve, account)
|
|
|
|
results[:hashtags] = Tag.search_for(query.gsub(/\A#/, ''), limit) unless query.start_with?('@')
|
2016-11-13 00:49:28 +11:00
|
|
|
end
|
2016-11-13 00:33:21 +11:00
|
|
|
|
|
|
|
results
|
|
|
|
end
|
|
|
|
end
|