<commit_before>class OperatorsController < ApplicationController
  
  skip_before_filter :make_cachable
  before_filter :long_cache
  before_filter :find_operator, :except => [:index]
  before_filter :setup_shared_title, :except => [:index]
  
  
  def index
    @operator_list_threshold = 20
    @operator_initial_chars = []
    @operator_count = 0
    operators = []
    conditions = []
    if params[:query]=~ /[[:alnum:]]{1}/ # at least one alphanum... but maybe choke it? 
      @search_query = params[:query].downcase
      conditions << "(lower(name) like ? OR lower(short_name) like ?)"
      2.times{ conditions << "%%#{@search_query}%%" }
      operators_by_letter = MySociety::Util.by_letter(Operator.find(:all, :conditions => conditions), :upcase){|o| o.name }
      operators_by_letter.each_value {|ops| @operator_count  += ops.size }
    else
      operators_by_letter = Operator.all_by_letter # memoized
      @operator_count = Operator.count(:all)
    end
    if @operator_count > @operator_list_threshold<commit_msg>tidy up unhelpful whitespace in search terms<commit_after>class OperatorsController < ApplicationController
  
  skip_before_filter :make_cachable
  before_filter :long_cache
  before_filter :find_operator, :except => [:index]
  before_filter :setup_shared_title, :except => [:index]
  
  
  def index
    @operator_list_threshold = 20
    @operator_initial_chars = []
    @operator_count = 0
    operators = []
    conditions = []
    if params[:query]=~ /[[:alnum:]]{1}/ # at least one alphanum... but maybe choke it? 
      @search_query = params[:query].downcase.gsub(/\s+/, " ").strip  # multiple spaces most likely to be in error 
      conditions << "(lower(name) like ? OR lower(short_name) like ?)"
      2.times{ conditions << "%%#{@search_query}%%" }
      operators_by_letter = MySociety::Util.by_letter(Operator.find(:all, :conditions => conditions), :upcase){|o| o.name }
      operators_by_letter.each_value {|ops| @operator_count  += ops.size }
    else
      operators_by_letter = Operator.all_by_letter # memoized
      @operator_count = Operator.count(:all)
    end
    if @operator_count > @operator_list_threshold
{'fraction_non_alphanumeric': 0.12644208583294878, 'fraction_numerical': 0.0046146746654360865, 'mean_word_length': 3.9839080459770115, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '4540231', 'n_tokens_mistral': 692, 'n_tokens_neox': 682, 'n_words': 146}