<commit_before># frozen_string_literal: true

# :nodoc:
class ExplorationController < ApplicationController
  def new
    begin
      @exploration_state = enact_search(collect_user_preferences)
    rescue ArgumentError => e
      @exploration_state = ExplorationState.new(exception: e)
    end

    respond_to do |format|
      format.json { render }
      format.html { render }
    end
  end

  def index
    @exploration_state = ExplorationState.new(collect_user_preferences)

    respond_to do |format|
      format.json { render }
      format.html { render }
    end
  end

  private

  def enact_search(user_prefs)
    state = SearchCommand.new(user_prefs, Regions)

    if state.search_status == :single_result
      state = explain_or_enact_query state
    end

    ExplorationState.new(state)
  end

  def collect_user_preferences
    UserPreferences.new(ActionController::Parameters.new(params))
  end

  def explain_or_enact_query(search_cmd)
    qc = params[:explain] ? explain_query(search_cmd) : enact_query(search_cmd)
    qc.perform_query
    qc
  end

  def enact_query(search_cmd)
    QueryCommand.new(search_cmd)
  end

  def explain_query(search_cmd)
    ExplainQueryCommand.new(search_cmd)
  end<commit_msg>Fix regression: no need to wrap params when used from a controller. Side effect of fixing tests!<commit_after># frozen_string_literal: true

# :nodoc:
class ExplorationController < ApplicationController
  def new
    begin
      @exploration_state = enact_search(collect_user_preferences)
    rescue ArgumentError => e
      @exploration_state = ExplorationState.new(exception: e)
    end

    respond_to do |format|
      format.json { render }
      format.html { render }
    end
  end

  def index
    @exploration_state = ExplorationState.new(collect_user_preferences)

    respond_to do |format|
      format.json { render }
      format.html { render }
    end
  end

  private

  def enact_search(user_prefs)
    state = SearchCommand.new(user_prefs, Regions)

    if state.search_status == :single_result
      state = explain_or_enact_query state
    end

    ExplorationState.new(state)
  end

  def collect_user_preferences
    UserPreferences.new(params)
  end

  def explain_or_enact_query(search_cmd)
    qc = params[:explain] ? explain_query(search_cmd) : enact_query(search_cmd)
    qc.perform_query
    qc
  end

  def enact_query(search_cmd)
    QueryCommand.new(search_cmd)
  end

  def explain_query(search_cmd)
    ExplainQueryCommand.new(search_cmd)
  end
{'fraction_non_alphanumeric': 0.06940566414040686, 'fraction_numerical': 0.0, 'mean_word_length': 3.568306010928962, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '239084', 'n_tokens_mistral': 814, 'n_tokens_neox': 778, 'n_words': 169}