<commit_before>ActiveScaffold rescue
  raise "#### Depends on ActiveScaffold. Enable the plugin first ####"
begin
  gem "thinking-sphinx"
rescue Gem::LoadError
  raise "#### Thinking Sphinx gem not installed ####"
end
 


ActiveScaffold::Config::Search.class_eval do
	# Add the 'engine' configuration option
  def engine
    unless @engine
      @engine
      # Default to SQL
      self.engine = 'sql'
    end
    @engine
  end

  def engine=(val)
    @engine = val
  end
  
 	# Add the 'model_name' configuration option
  def model_name
    unless @model_name
      @model_name
      self.model_name = nil
    end
    @model_name
  end 

  def model_name=(val)  
    @model_name = val
  end  
end


ActiveScaffold::Actions::Search.class_eval do
	
	alias_method :do_original_search, :do_search
	
  protected  
	def do_search
		# Thinking Sphinx is configured, use it
		if active_scaffold_config.search.engine == "thinking_sphinx"
      # We need to parse the raw query_string here since the params hash has not yet been created.
			@query = CGI.parse(request.query_string)['search'].to_s.strip rescue ''
			
      unless @query.empty?
				begin
					# Run the search, returning only the ids
					active_scaffold_config.search.model_name.nil? ? @model_name = self.controller_name : @model_name = active_scaffold_config.search.model_name
					
					puts "\n\n\n\n\n\n\n\n\n#{@model_name}\n\n\n\n\n\n\n\n\n\n"
					
				  sphinx_results = @model_name.classify.constantize.search(@query, :select => :id, :limit => 50)
          # puts sphinx_results.collect { |x| x.id }				  
				rescue NoMethodError
					# There is no search method on the model, probably no indexes configured
					# Fallback to default SQL search
					do_original_search
					return
				end
				
				# Create the conditions
				search_conditions = { :id => sphinx_results.collect { |x| x.id } }<commit_msg>modified to work with active scaffold 3.1<commit_after>ActiveScaffold rescue
  raise "#### Depends on ActiveScaffold. Enable the plugin first ####"
begin
  gem "thinking-sphinx"
rescue Gem::LoadError
  raise "#### Thinking Sphinx gem not installed ####"
end
 


ActiveScaffold::Config::Search.class_eval do
	# Add the 'engine' configuration option
  def engine
    unless @engine
      @engine
      # Default to SQL
      self.engine = 'sql'
    end
    @engine
  end

  def engine=(val)
    @engine = val
  end
  
 	# Add the 'model_name' configuration option
  def model_name
    unless @model_name
      @model_name
      self.model_name = nil
    end
    @model_name
  end 

  def model_name=(val)  
    @model_name = val
  end  
end


ActiveScaffold::Actions::Search.class_eval do
	
	alias_method :do_original_search, :do_search
	
  protected  
	def do_search
		# Thinking Sphinx is configured, use it
		if active_scaffold_config.search.engine == "thinking_sphinx"
      # We need to parse the raw query_string here since the params hash has not yet been created.
      query = search_params.to_s.strip rescue ''
			
      unless query.empty?
				begin
					# Run the search, returning only the ids
					active_scaffold_config.search.model_name.nil? ? @model_name = self.controller_name : @model_name = active_scaffold_config.search.model_name
				
				  sphinx_results = @model_name.classify.constantize.search('*' + query + '*', :select => :id, :limit => 50)
				
        rescue NoMethodError
					# There is no search method on the model, probably no indexes configured
					# Fallback to default SQL search
					do_original_search
					return
				end
				
				# Create the conditions
        ids = sphinx_results.collect { |x| x.id }

        search_conditions = {}
				search_conditions = { :id => ids }
{'fraction_non_alphanumeric': 0.08839479392624729, 'fraction_numerical': 0.0016268980477223427, 'mean_word_length': 2.9539121114683815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3068836', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1152, 'n_words': 328}