<commit_before>require 'whitehall/document_filter/filterer'
module Whitehall
  module NotQuiteAsFakeSearch
    def self.stop_faking_it_quite_so_much!
      store = Whitehall::NotQuiteAsFakeSearch::Store.new
      SearchIndex.indexer_class.store = store
      Whitehall.government_search_client = Whitehall::NotQuiteAsFakeSearch::GdsApiRummager.new(
        SearchIndex.government_search_index_path, store
      )
      Whitehall.search_client = Whitehall::NotQuiteAsFakeSearch::GdsApiRummager.new(
        SearchIndex.government_search_index_path, store
      )
      Whitehall.search_backend = Whitehall::DocumentFilter::AdvancedSearchRummager
    end

    def self.start_faking_it_again!
      SearchIndex.indexer_class.store = nil
    end

    class GdsApiRummager
      def initialize(index_name, store, field_mappings = nil)
        @index_name = index_name
        @field_mappings = field_mappings || default_field_mappings
        @store = store
      end

      def search(params)
        params = params.stringify_keys
        keywords = params.delete("q")
        order = { public_timestamp: "desc" }
        per_page = params.delete("count").to_i
        page = params.delete("start").to_i
        params.delete("fields")
        params.delete("order")
        apply_filters(keywords, params, order, per_page, page, true)
      end

      def autocomplete(*_args)
        raise "Not implemented"
      end

      def advanced_search(params)
        params = params.stringify_keys
        raise "Pagination params are required." if params["per_page"].nil? || params["page"].nil?<commit_msg>Inverse fake search global var changes<commit_after>require 'whitehall/document_filter/filterer'
module Whitehall
  module NotQuiteAsFakeSearch
    def self.stop_faking_it_quite_so_much!
      @search_indexer_class_store = SearchIndex.indexer_class.store
      store = Whitehall::NotQuiteAsFakeSearch::Store.new
      SearchIndex.indexer_class.store = store

      @government_search_client = Whitehall.government_search_client
      Whitehall.government_search_client = Whitehall::NotQuiteAsFakeSearch::GdsApiRummager.new(
        SearchIndex.government_search_index_path, store
      )

      @search_client = Whitehall.search_client
      Whitehall.search_client = Whitehall::NotQuiteAsFakeSearch::GdsApiRummager.new(
        SearchIndex.government_search_index_path, store
      )

      @search_backend = Whitehall.search_backend
      Whitehall.search_backend = Whitehall::DocumentFilter::AdvancedSearchRummager
    end

    def self.start_faking_it_again!
      SearchIndex.indexer_class.store = @search_indexer_class_store
      Whitehall.government_search_client = @government_search_client
      Whitehall.search_client = @search_client
      Whitehall.search_backend = @search_backend
    end

    class GdsApiRummager
      def initialize(index_name, store, field_mappings = nil)
        @index_name = index_name
        @field_mappings = field_mappings || default_field_mappings
        @store = store
      end

      def search(params)
        params = params.stringify_keys
        keywords = params.delete("q")
        order = { public_timestamp: "desc" }
        per_page = params.delete("count").to_i
        page = params.delete("start").to_i
        params.delete("fields")
        params.delete("order")
        apply_filters(keywords, params, order, per_page, page, true)
      end

      def autocomplete(*_args)
        raise "Not implemented"
      end

      def advanced_search(params)
        params = params.stringify_keys
        raise "Pagination params are required." if params["per_page"].nil? || params["page"].nil?
{'fraction_non_alphanumeric': 0.08136986301369863, 'fraction_numerical': 0.0, 'mean_word_length': 3.3776978417266186, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1202166', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1037, 'n_words': 184}