<commit_before>class SearchesController < ApplicationController
  before_filter :login_required, :except => %w[index]

  subtabs :index => [[:newest, %w(created_at desc)], [:hot, [%w(hotness desc), %w(views_count desc)]], [:votes, %w(votes_average desc)], [:activity, %w(activity_at desc)], [:expert, %w(created_at desc)]],
          :unanswered => [[:newest, %w(created_at desc)], [:votes, %w(votes_average desc)], [:mytags, %w(created_at desc)]],
          :show => [[:votes, %w(votes_average desc)], [:oldest, %w(created_at asc)], [:newest, %w(created_at desc)]]

  def index
    options = {}
    unless params[:q].blank?
      pharse = params[:q]
#       @search_tags = pharse.scan(/\[(\w+)\]/).flatten
      @search_text = pharse.gsub(/\[(\w+)\]/, "")
#       options[:tags] = {:$all => @search_tags} unless @search_tags.empty?
      options[:group_id] = current_group.id
      options[:banned] = false

      if params[:language]
        pharse += " lang:#{params[:language]}"
      end

      if params[:accepted]
        pharse += " is:accepted"
      end

      if params[:answered]
        pharse += " is:answered"
      end

      @search = Search.new(:query => pharse)

      if !@search_text.blank?
        # FIXME:filter is blocking mongodb
#         @questions = Question.(@search_text, options)

        @questions = Question.search(@search_text).where(options).page(params["page"])

        # @questions = Question.filter(@search_text, options)
        # @highlight = @questions.parsed_query[:tokens].to_a
#         @questions = Question.where(options).page(params["page"])
        @highlight = ""
      else
        @questions = Question.where(options).page(params["page"])
      end<commit_msg>fix exception when searching tags<commit_after>class SearchesController < ApplicationController
  before_filter :login_required, :except => %w[index]

  subtabs :index => [[:newest, %w(created_at desc)], [:hot, [%w(hotness desc), %w(views_count desc)]], [:votes, %w(votes_average desc)], [:activity, %w(activity_at desc)], [:expert, %w(created_at desc)]],
          :unanswered => [[:newest, %w(created_at desc)], [:votes, %w(votes_average desc)], [:mytags, %w(created_at desc)]],
          :show => [[:votes, %w(votes_average desc)], [:oldest, %w(created_at asc)], [:newest, %w(created_at desc)]]

  def index
    options = {}
    unless params[:q].blank?
      pharse = params[:q]
      @search_tags = pharse.scan(/\[(\w+)\]/).flatten
      @search_text = pharse.gsub(/\[(\w+)\]/, "")
      options[:tags] = @search_tags unless @search_tags.empty?
      options[:group_id] = current_group.id
      options[:banned] = false

      if params[:language]
        pharse += " lang:#{params[:language]}"
      end

      if params[:accepted]
        pharse += " is:accepted"
      end

      if params[:answered]
        pharse += " is:answered"
      end

      @search = Search.new(:query => pharse)

      if !@search_text.blank?
        # FIXME:filter is blocking mongodb
#         @questions = Question.(@search_text, options)

        @questions = Question.search(@search_text).where(options).page(params["page"])

        # @questions = Question.filter(@search_text, options)
        # @highlight = @questions.parsed_query[:tokens].to_a
#         @questions = Question.where(options).page(params["page"])
        @highlight = ""
      else
        @questions = Question.where(options).page(params["page"])
      end
{'fraction_non_alphanumeric': 0.17545904983969687, 'fraction_numerical': 0.0, 'mean_word_length': 3.284644194756554, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, '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': '3503951', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1091, 'n_words': 216}