gearheads
/
mastodon
Archived
2
0
Fork 0
This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
mastodon/app/services/search_service.rb

22 lines
661 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class SearchService < BaseService
def call(query, limit, resolve = false, account = nil)
return if query.blank?
results = { accounts: [], hashtags: [], statuses: [] }
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 14:49:28 +01:00
end
results
end
end