discourse/app/controllers/admin/search_logs_controller.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

27 lines
792 B
Ruby

# frozen_string_literal: true
class Admin::SearchLogsController < Admin::AdminController
def index
period = params[:period] || "all"
search_type = params[:search_type] || "all"
render_serialized(SearchLog.trending(period&.to_sym, search_type&.to_sym), SearchLogsSerializer)
end
def term
params.require(:term)
term = params[:term]
period = params[:period] || "quarterly"
search_type = params[:search_type] || "all"
details = SearchLog.term_details(term, period&.to_sym, search_type&.to_sym)
raise Discourse::NotFound if details.blank?
result = Search.execute(params[:term], guardian: guardian)
details[:search_result] = serialize_data(result, GroupedSearchResultSerializer, result: result)
render_json_dump(term: details)
end
end