<commit_before># frozen_string_literal: true

module GobiertoCommon
  module Api
    module V1
      class SearchController < ApiBaseController

        # GET /api/v1/search?query=term&filters[searchable_type][]=GobiertoPeople::Person&page[number]=1&page[size]=5
        def query
          search_result = current_site.multisearch(params[:query]).where(filters_params).page(page_params[:number]).per(page_params[:size])

          render(
            json: search_result,
            each_serializer: GobiertoCommon::SearchDocumentSerializer,
            adapter: :json_api,
            meta: {
              hits_count: search_result.total_count,
              page: search_result.current_page,
              per_page: search_result.limit_value
            }
          )
        end

        private

        def filters_params
          @filters_params ||= params.fetch(:filters, {}).permit(searchable_type: [])
        end

        def page_params
          @page_params ||= params.fetch(:page, {}).permit(:number, :size)
        end
      end
    end
  end
end
<commit_msg>Remove unnecessary queries in search API controller<commit_after># frozen_string_literal: true

module GobiertoCommon
  module Api
    module V1
      class SearchController < ApiBaseController

        # GET /api/v1/search?query=term&filters[searchable_type][]=GobiertoPeople::Person
        def query
          search_result = current_site.multisearch(params[:query]).where(filters_params).limit(25)

          render(
            json: search_result,
            each_serializer: GobiertoCommon::SearchDocumentSerializer,
            adapter: :json_api,
          )
        end

        private

        def filters_params
          @filters_params ||= params.fetch(:filters, {}).permit(searchable_type: [])
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.09130672498633133, 'fraction_numerical': 0.004373974849644614, 'mean_word_length': 2.446327683615819, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '978573', 'n_tokens_mistral': 515, 'n_tokens_neox': 509, 'n_words': 94}