0
0
instrumental/app/services/search_service.rb

22 lines
669 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class SearchService < BaseService
def call(query, limit, resolve = false, account = nil)
results = { accounts: [], hashtags: [], statuses: [] }
2017-04-01 05:44:12 +09:00
return results if query.blank?
if query =~ /\Ahttps?:\/\//
resource = FetchRemoteResourceService.new.call(query)
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 22:49:28 +09:00
end
results
end
end