summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorMarius Balteanu <marius.balteanu@zitec.com>2021-10-05 19:54:31 +0000
committerMarius Balteanu <marius.balteanu@zitec.com>2021-10-05 19:54:31 +0000
commit506fc9d74cdb67af2eaea27662420ec07e32b2f3 (patch)
tree523ac0beb65ba62944c99924397c45669d0f23d6 /app
parent04e27aa1616f78381fab69b2b72ba5874e4cc557 (diff)
downloadredmine-506fc9d74cdb67af2eaea27662420ec07e32b2f3.tar.gz
redmine-506fc9d74cdb67af2eaea27662420ec07e32b2f3.zip
Tokenize search parameter in order to allow multiple search terms in:
* the "contains" operator of text filters * in issue autocomplete Patch by Jens Krämer. git-svn-id: http://svn.redmine.org/redmine/trunk@21238 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/models/issue.rb3
-rw-r--r--app/models/query.rb24
2 files changed, 20 insertions, 7 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 70b408a21..55962f0fe 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -100,9 +100,8 @@ class Issue < ActiveRecord::Base
ids.any? ? where(:assigned_to_id => ids) : none
end)
scope :like, (lambda do |q|
- q = q.to_s
if q.present?
- where("LOWER(#{table_name}.subject) LIKE LOWER(?)", "%#{sanitize_sql_like q}%")
+ where(*::Query.tokenized_like_conditions("#{table_name}.subject", q))
end
end)
diff --git a/app/models/query.rb b/app/models/query.rb
index bafdd3c2c..024fe591e 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -1440,11 +1440,25 @@ class Query < ActiveRecord::Base
prefix = suffix = nil
prefix = '%' if options[:ends_with]
suffix = '%' if options[:starts_with]
- prefix = suffix = '%' if prefix.nil? && suffix.nil?
- value = queried_class.sanitize_sql_like value
- queried_class.sanitize_sql_for_conditions(
- [Redmine::Database.like(db_field, '?', :match => options[:match]), "#{prefix}#{value}#{suffix}"]
- )
+ if prefix || suffix
+ value = queried_class.sanitize_sql_like value
+ queried_class.sanitize_sql_for_conditions(
+ [Redmine::Database.like(db_field, '?', :match => options[:match]), "#{prefix}#{value}#{suffix}"]
+ )
+ else
+ queried_class.sanitize_sql_for_conditions(
+ ::Query.tokenized_like_conditions(db_field, value, **options)
+ )
+ end
+ end
+
+ def self.tokenized_like_conditions(db_field, value, **options)
+ tokens = Redmine::Search::Tokenizer.new(value).tokens
+ tokens = [value] unless tokens.present?
+ sql, values = tokens.map do |token|
+ [Redmine::Database.like(db_field, '?', options), "%#{sanitize_sql_like token}%"]
+ end.transpose
+ [sql.join(" AND "), *values]
end
# Adds a filter for the given custom field