You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
661 B

  1. # frozen_string_literal: true
  2. class SearchService < BaseService
  3. def call(query, limit, resolve = false, account = nil)
  4. return if query.blank?
  5. results = { accounts: [], hashtags: [], statuses: [] }
  6. if query =~ /\Ahttps?:\/\//
  7. resource = FetchRemoteResourceService.new.call(query)
  8. results[:accounts] << resource if resource.is_a?(Account)
  9. results[:statuses] << resource if resource.is_a?(Status)
  10. else
  11. results[:accounts] = AccountSearchService.new.call(query, limit, resolve, account)
  12. results[:hashtags] = Tag.search_for(query.gsub(/\A#/, ''), limit) unless query.start_with?('@')
  13. end
  14. results
  15. end
  16. end