2017-03-21 18:32:27 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-07 11:09:25 -07:00
|
|
|
class Api::V1::SearchController < Api::BaseController
|
2017-11-14 16:53:33 -08:00
|
|
|
include Authorization
|
|
|
|
|
Add type, limit, offset, min_id, max_id, account_id to search API (#10091)
* Add type, limit, offset, min_id, max_id, account_id to search API
Fix #8939
* Make the offset work on accounts and hashtags search as well
* Assure brakeman we are not doing mass assignment here
* Do not allow paginating unless a type is chosen
* Fix search query and index id field on statuses instead of created_at
2019-02-26 06:21:36 -08:00
|
|
|
RESULTS_LIMIT = 20
|
2017-05-30 18:11:54 -07:00
|
|
|
|
2018-07-05 09:31:35 -07:00
|
|
|
before_action -> { doorkeeper_authorize! :read, :'read:search' }
|
2017-07-11 08:08:26 -07:00
|
|
|
before_action :require_user!
|
|
|
|
|
2017-03-21 18:32:27 -07:00
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
def index
|
Add type, limit, offset, min_id, max_id, account_id to search API (#10091)
* Add type, limit, offset, min_id, max_id, account_id to search API
Fix #8939
* Make the offset work on accounts and hashtags search as well
* Assure brakeman we are not doing mass assignment here
* Do not allow paginating unless a type is chosen
* Fix search query and index id field on statuses instead of created_at
2019-02-26 06:21:36 -08:00
|
|
|
@search = Search.new(search_results)
|
2017-07-06 19:02:06 -07:00
|
|
|
render json: @search, serializer: REST::SearchSerializer
|
2017-05-30 18:11:54 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def search_results
|
|
|
|
SearchService.new.call(
|
|
|
|
params[:q],
|
Add type, limit, offset, min_id, max_id, account_id to search API (#10091)
* Add type, limit, offset, min_id, max_id, account_id to search API
Fix #8939
* Make the offset work on accounts and hashtags search as well
* Assure brakeman we are not doing mass assignment here
* Do not allow paginating unless a type is chosen
* Fix search query and index id field on statuses instead of created_at
2019-02-26 06:21:36 -08:00
|
|
|
current_account,
|
|
|
|
limit_param(RESULTS_LIMIT),
|
|
|
|
search_params.merge(resolve: truthy_param?(:resolve))
|
2017-05-30 18:11:54 -07:00
|
|
|
)
|
|
|
|
end
|
Add type, limit, offset, min_id, max_id, account_id to search API (#10091)
* Add type, limit, offset, min_id, max_id, account_id to search API
Fix #8939
* Make the offset work on accounts and hashtags search as well
* Assure brakeman we are not doing mass assignment here
* Do not allow paginating unless a type is chosen
* Fix search query and index id field on statuses instead of created_at
2019-02-26 06:21:36 -08:00
|
|
|
|
|
|
|
def search_params
|
|
|
|
params.permit(:type, :offset, :min_id, :max_id, :account_id)
|
|
|
|
end
|
2017-03-21 18:32:27 -07:00
|
|
|
end
|