diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-10-15 16:53:39 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-10-15 16:53:39 +0000 |
commit | b9cc65db61016f88cb63ce639df078f541a3e5a1 (patch) | |
tree | 7f615c79d93d00967980ab5c153e07ab72a46636 /vendor/plugins/acts_as_searchable | |
parent | 74ecb37be657611fdc239d808d96f6932d61d3d0 (diff) | |
download | redmine-b9cc65db61016f88cb63ce639df078f541a3e5a1.tar.gz redmine-b9cc65db61016f88cb63ce639df078f541a3e5a1.zip |
Search engine: added a checkbox to search titles only (usefull when searching on common words).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@842 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'vendor/plugins/acts_as_searchable')
-rw-r--r-- | vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb b/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb index ee4d5d6f8..e2a323abb 100644 --- a/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb +++ b/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb @@ -59,24 +59,26 @@ module Redmine end module ClassMethods - def search(tokens, all_tokens, project, options={}) + def search(tokens, project, options={}) tokens = [] << tokens unless tokens.is_a?(Array) find_options = {:include => searchable_options[:include]} find_options[:limit] = options[:limit] if options[:limit] find_options[:order] = "#{searchable_options[:date_column]} " + (options[:before] ? 'DESC' : 'ASC') - - sql = ([ '(' + searchable_options[:columns].collect {|column| "(LOWER(#{column}) LIKE ?)"}.join(' OR ') + ')' ] * tokens.size).join(all_tokens ? ' AND ' : ' OR ') + columns = searchable_options[:columns] + columns.slice!(1..-1) if options[:titles_only] + + sql = ([ '(' + columns.collect {|column| "(LOWER(#{column}) LIKE ?)"}.join(' OR ') + ')' ] * tokens.size).join(options[:all_words] ? ' AND ' : ' OR ') if options[:offset] sql = "(#{sql}) AND (#{searchable_options[:date_column]} " + (options[:before] ? '<' : '>') + "'#{connection.quoted_date(options[:offset])}')" end - find_options[:conditions] = [sql, * (tokens * searchable_options[:columns].size).sort] + find_options[:conditions] = [sql, * (tokens * columns.size).sort] results = with_scope(:find => {:conditions => ["#{searchable_options[:project_key]} = ?", project.id]}) do find(:all, find_options) end - if searchable_options[:with] + if searchable_options[:with] && !options[:titles_only] searchable_options[:with].each do |model, assoc| - results += model.to_s.camelcase.constantize.search(tokens, all_tokens, project, options).collect {|r| r.send assoc} + results += model.to_s.camelcase.constantize.search(tokens, project, options).collect {|r| r.send assoc} end results.uniq! end |