diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-12-14 18:54:55 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-12-14 18:54:55 +0000 |
commit | 58610ec52af2249c4c5eebf35e11cd827a7966ab (patch) | |
tree | b699b63943e7de4638a1c7c8ec03e21325f69ea4 /vendor/plugins | |
parent | 38b185f1dc4d296eb49c94a3ccff7496b1367c84 (diff) | |
download | redmine-58610ec52af2249c4c5eebf35e11cd827a7966ab.tar.gz redmine-58610ec52af2249c4c5eebf35e11cd827a7966ab.zip |
Search engine: issue custom fields can now be searched.
Each issue custom field (excepting numeric, date and boolean fields) can be marked as "Searchable" (default to false).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@994 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'vendor/plugins')
-rw-r--r-- | vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb | 23 |
1 files changed, 21 insertions, 2 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 e2a323abb..1dd88978c 100644 --- a/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb +++ b/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb @@ -49,6 +49,9 @@ module Redmine raise 'No date column defined defined.' end + # Should we search custom fields on this model ? + searchable_options[:search_custom_fields] = !reflect_on_association(:custom_values).nil? + send :include, Redmine::Acts::Searchable::InstanceMethods end end @@ -67,11 +70,27 @@ module Redmine 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 ') + token_clauses = columns.collect {|column| "(LOWER(#{column}) LIKE ?)"} + + if !options[:titles_only] && searchable_options[:search_custom_fields] + searchable_custom_field_ids = CustomField.find(:all, + :select => 'id', + :conditions => { :type => "#{self.name}CustomField", + :searchable => true }).collect(&:id) + if searchable_custom_field_ids.any? + custom_field_sql = "#{table_name}.id IN (SELECT customized_id FROM #{CustomValue.table_name}" + + " WHERE customized_type='#{self.name}' AND customized_id=#{table_name}.id AND LOWER(value) LIKE ?" + + " AND #{CustomValue.table_name}.custom_field_id IN (#{searchable_custom_field_ids.join(',')}))" + token_clauses << custom_field_sql + end + end + + sql = ([token_clauses.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 * columns.size).sort] + find_options[:conditions] = [sql, * (tokens * token_clauses.size).sort] results = with_scope(:find => {:conditions => ["#{searchable_options[:project_key]} = ?", project.id]}) do find(:all, find_options) |