<commit_before>class SearchController < ApplicationController
  before_filter :load_vars, only: :index
  before_filter :load_markdown, only: :index

  MIN_QUERY_CHARS = 2

  def index
    if not @search_query
      redirect_to new_search_path
    end

    count_search_results

    search_projects if @search_category == :projects
    search_workflows if @search_category == :workflows
    search_modules if @search_category == :modules
    search_results if @search_category == :results
    search_tags if @search_category == :tags
    search_reports if @search_category == :reports
    search_protocols if @search_category == :protocols
    search_steps if @search_category == :steps
    search_checklists if @search_category == :checklists
    search_samples if @search_category == :samples
    search_assets if @search_category == :assets
    search_tables if @search_category == :tables
    search_comments if @search_category == :comments

    @search_pages = (@search_count.to_f / SEARCH_LIMIT.to_f).ceil
    @start_page = @search_page - 2
    @start_page = 1 if @start_page < 1
    @end_page = @start_page + 4

    if @end_page > @search_pages
      @end_page = @search_pages
      @start_page = @end_page - 4
      @start_page = 1 if @start_page < 1
    end
  end

  def new
  end

  private

  def load_vars
    @search_query = params[:q] || ''
    @search_category = params[:category] || ''
    @search_category = @search_category.to_sym
    @search_page = params[:page].to_i || 1
    @display_query = @search_query
    # splits the search query to validate all entries
    @splited_query = @search_query.split()

    if @splited_query.first.length < MIN_QUERY_CHARS
      flash[:error] = t'search.index.error.query_length', n: MIN_QUERY_CHARS
      redirect_to :back
    else
      @splited_query.each_with_index do |w, i|
        if @splited_query.length > 1 && w.length < MIN_QUERY_CHARS
          @splited_query.slice!(i)
        end
      end
    end

    @search_query = @splited_query.join(' ')

    if @search_page < 1
      @search_page = 1
    end
  end

# Initialize markdown parser
  def load_markdown<commit_msg>fixed hound<commit_after>class SearchController < ApplicationController
  before_filter :load_vars, only: :index
  before_filter :load_markdown, only: :index

  MIN_QUERY_CHARS = 2

  def index
    if not @search_query
      redirect_to new_search_path
    end

    count_search_results

    search_projects if @search_category == :projects
    search_workflows if @search_category == :workflows
    search_modules if @search_category == :modules
    search_results if @search_category == :results
    search_tags if @search_category == :tags
    search_reports if @search_category == :reports
    search_protocols if @search_category == :protocols
    search_steps if @search_category == :steps
    search_checklists if @search_category == :checklists
    search_samples if @search_category == :samples
    search_assets if @search_category == :assets
    search_tables if @search_category == :tables
    search_comments if @search_category == :comments

    @search_pages = (@search_count.to_f / SEARCH_LIMIT.to_f).ceil
    @start_page = @search_page - 2
    @start_page = 1 if @start_page < 1
    @end_page = @start_page + 4

    if @end_page > @search_pages
      @end_page = @search_pages
      @start_page = @end_page - 4
      @start_page = 1 if @start_page < 1
    end
  end

  def new
  end

  private

  def load_vars
    @search_query = params[:q] || ''
    @search_category = params[:category] || ''
    @search_category = @search_category.to_sym
    @search_page = params[:page].to_i || 1
    @display_query = @search_query
    # splits the search query to validate all entries
    @splited_query = @search_query.split

    if @splited_query.first.length < MIN_QUERY_CHARS
      flash[:error] = t'search.index.error.query_length', n: MIN_QUERY_CHARS
      redirect_to :back
    else
      @splited_query.each_with_index do |w, i|
        if @splited_query.length > 1 && w.length < MIN_QUERY_CHARS
          @splited_query.slice!(i)
        end
      end
    end

    @search_query = @splited_query.join(' ')

    if @search_page < 1
      @search_page = 1
    end
  end

# Initialize markdown parser
  def load_markdown
{'fraction_non_alphanumeric': 0.08716026241799438, 'fraction_numerical': 0.005623242736644799, 'mean_word_length': 3.3384146341463414, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, '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': '111568', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1343, 'n_words': 334}