2016-11-15 17:56:29 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-12 15:33:21 +02:00
|
|
|
class SearchService < BaseService
|
2017-03-17 21:47:38 +02:00
|
|
|
def call(query, limit, resolve = false, account = nil)
|
2017-03-22 03:32:27 +02:00
|
|
|
results = { accounts: [], hashtags: [], statuses: [] }
|
2016-11-12 15:33:21 +02:00
|
|
|
|
2017-03-31 23:44:12 +03:00
|
|
|
return results if query.blank?
|
|
|
|
|
2017-03-22 03:32:27 +02:00
|
|
|
if query =~ /\Ahttps?:\/\//
|
|
|
|
resource = FetchRemoteResourceService.new.call(query)
|
2016-11-12 15:33:21 +02:00
|
|
|
|
2017-03-22 03:32:27 +02: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-12 15:49:28 +02:00
|
|
|
end
|
2016-11-12 15:33:21 +02:00
|
|
|
|
|
|
|
results
|
|
|
|
end
|
|
|
|
end
|