]> source.dussan.org Git - redmine.git/commitdiff
Move SQL LIKE tokens to acts_as_searchable.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 17 Feb 2010 20:20:51 +0000 (20:20 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 17 Feb 2010 20:20:51 +0000 (20:20 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3445 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/search_controller.rb
vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb

index eae38016f53275e569bfab6fcb04c2a431192354..0f0a4e6aec3bc78cd7b4f850547f72e2011e268f 100644 (file)
@@ -67,16 +67,14 @@ class SearchController < ApplicationController
     
     if !@tokens.empty?
       # no more than 5 tokens to search for
-      @tokens.slice! 5..-1 if @tokens.size > 5
-      # strings used in sql like statement
-      like_tokens = @tokens.collect {|w| "%#{w.downcase}%"}      
+      @tokens.slice! 5..-1 if @tokens.size > 5  
       
       @results = []
       @results_by_type = Hash.new {|h,k| h[k] = 0}
       
       limit = 10
       @scope.each do |s|
-        r, c = s.singularize.camelcase.constantize.search(like_tokens, projects_to_search,
+        r, c = s.singularize.camelcase.constantize.search(@tokens, projects_to_search,
           :all_words => @all_words,
           :titles_only => @titles_only,
           :limit => (limit+1),
index 9a81f363f162921c0dbb36c84fb7737d7b681618..9106d7bd784dab2a4dc6b31bd679f84820846a31 100644 (file)
@@ -97,7 +97,7 @@ module Redmine
             
             sql = (['(' + token_clauses.join(' OR ') + ')'] * tokens.size).join(options[:all_words] ? ' AND ' : ' OR ')
             
-            find_options[:conditions] = [sql, * (tokens * token_clauses.size).sort]
+            find_options[:conditions] = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
             
             project_conditions = []
             project_conditions << (searchable_options[:permission].nil? ? Project.visible_by(User.current) :