<commit_before>class Admin::SearchesController < Admin::AdminController

  def show
    @query = params[:q]
    if is_number?(@query)
      find_petition_by_id(@query)
    elsif is_email?(@query)
      find_signatures_by_email(@query)
    else
      find_petitions_by_keyword(@query)
    end
  end

  private
  def find_petition_by_id(query)
    begin
      petition = Petition.find(query.to_i)
      redirect_to admin_petition_url(petition)
    rescue ActiveRecord::RecordNotFound
      flash[:error] = "Cannot find petition with id: #{query}"
      redirect_to admin_petitions_url
    end
  end

  def find_signatures_by_email(query)
    @signatures = Signature.for_email(query).paginate(:page => params[:page], :per_page => 50)
  end

  def find_petitions_by_keyword(query)
    redirect_to(controller: 'admin/petitions', action: 'index', q: query)
  end

  def is_number?(query)
    /^\d+$/ =~ query
  end

  def is_email?(query)
    query.include?('@')
  end
end<commit_msg>Avoid passing `@query` around everywhere in searches_controller<commit_after>class Admin::SearchesController < Admin::AdminController

  def show
    if query_is_number?
      find_petition_by_id
    elsif query_is_email?
      find_signatures_by_email
    else
      find_petitions_by_keyword
    end
  end

  private
  def query
    @query ||= params.fetch(:q, '')
  end

  def find_petition_by_id
    begin
      petition = Petition.find(query.to_i)
      redirect_to admin_petition_url(petition)
    rescue ActiveRecord::RecordNotFound
      flash[:error] = "Cannot find petition with id: #{query}"
      redirect_to admin_petitions_url
    end
  end

  def find_signatures_by_email
    @signatures = Signature.for_email(query).paginate(page: params[:page], per_page: 50)
  end

  def find_petitions_by_keyword
    redirect_to(controller: 'admin/petitions', action: 'index', q: query)
  end

  def query_is_number?
    /^\d+$/ =~ query
  end

  def query_is_email?
    query.include?('@')
  end
end
{'fraction_non_alphanumeric': 0.09696969696969697, 'fraction_numerical': 0.00202020202020202, 'mean_word_length': 3.705463182897862, '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': '3860258', 'n_tokens_mistral': 677, 'n_tokens_neox': 648, 'n_words': 140}