2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-31 07:02:26 -05:00
|
|
|
class Admin::SearchLogsController < Admin::StaffController
|
2017-11-14 18:13:50 -06:00
|
|
|
def index
|
|
|
|
period = params[:period] || "all"
|
2017-11-28 11:54:27 -06:00
|
|
|
search_type = params[:search_type] || "all"
|
|
|
|
render_serialized(SearchLog.trending(period&.to_sym, search_type&.to_sym), SearchLogsSerializer)
|
2017-11-14 18:13:50 -06:00
|
|
|
end
|
|
|
|
|
2017-12-19 20:41:31 -06:00
|
|
|
def term
|
|
|
|
params.require(:term)
|
|
|
|
|
|
|
|
term = params[:term]
|
2018-01-15 20:23:22 -06:00
|
|
|
period = params[:period] || "quarterly"
|
2017-12-19 20:41:31 -06:00
|
|
|
search_type = params[:search_type] || "all"
|
|
|
|
|
|
|
|
details = SearchLog.term_details(term, period&.to_sym, search_type&.to_sym)
|
|
|
|
raise Discourse::NotFound if details.blank?
|
|
|
|
|
2018-01-17 01:27:33 -06:00
|
|
|
result = Search.execute(params[:term], guardian: guardian)
|
2018-01-16 04:29:22 -06:00
|
|
|
details[:search_result] = serialize_data(result, GroupedSearchResultSerializer, result: result)
|
2017-12-19 20:41:31 -06:00
|
|
|
render_json_dump(term: details)
|
|
|
|
end
|
2017-11-14 18:13:50 -06:00
|
|
|
end
|