search_controller.rb 819 B

12345678910111213141516171819202122232425262728293031323334
  1. # frozen_string_literal: true
  2. class Api::V2::SearchController < Api::BaseController
  3. include Authorization
  4. RESULTS_LIMIT = 20
  5. before_action -> { doorkeeper_authorize! :read, :'read:search' }
  6. before_action :require_user!
  7. def index
  8. @search = Search.new(search_results)
  9. render json: @search, serializer: REST::SearchSerializer
  10. rescue Mastodon::SyntaxError
  11. unprocessable_entity
  12. rescue ActiveRecord::RecordNotFound
  13. not_found
  14. end
  15. private
  16. def search_results
  17. SearchService.new.call(
  18. params[:q],
  19. current_account,
  20. limit_param(RESULTS_LIMIT),
  21. search_params.merge(resolve: truthy_param?(:resolve), exclude_unreviewed: truthy_param?(:exclude_unreviewed))
  22. )
  23. end
  24. def search_params
  25. params.permit(:type, :offset, :min_id, :max_id, :account_id)
  26. end
  27. end