summaryrefslogtreecommitdiffstats
path: root/lib/redmine
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 /lib/redmine
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 'lib/redmine')
-rw-r--r--lib/redmine/search.rb26
1 files changed, 17 insertions, 9 deletions
diff --git a/lib/redmine/search.rb b/lib/redmine/search.rb
index 3aeedbcd2..7eae79b5e 100644
--- a/lib/redmine/search.rb
+++ b/lib/redmine/search.rb
@@ -57,15 +57,7 @@ module Redmine
@projects = projects
@cache = options.delete(:cache)
@options = options
-
- # extract tokens from the question
- # eg. hello "bye bye" => ["hello", "bye bye"]
- @tokens = @question.scan(%r{((\s|^)"[^"]+"(\s|$)|\S+)}).collect {|m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '')}
- # tokens must be at least 2 characters long
- # but for Chinese characters (Chinese HANZI/Japanese KANJI), tokens can be one character
- @tokens = @tokens.uniq.select {|w| w.length > 1 || w =~ /\p{Han}/}
- # no more than 5 tokens to search for
- @tokens.slice! 5..-1
+ @tokens = Tokenizer.new(@question).tokens
end
# Returns the total result count
@@ -135,6 +127,22 @@ module Redmine
end
end
+ class Tokenizer
+ def initialize(question)
+ @question = question.to_s
+ end
+
+ def tokens
+ # extract tokens from the question
+ # eg. hello "bye bye" => ["hello", "bye bye"]
+ tokens = @question.scan(%r{((\s|^)"[^"]+"(\s|$)|\S+)}).collect {|m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '')}
+ # tokens must be at least 2 characters long
+ # but for Chinese characters (Chinese HANZI/Japanese KANJI), tokens can be one character
+ # no more than 5 tokens to search for
+ tokens.uniq.select{|w| w.length > 1 || w =~ /\p{Han}/}.first 5
+ end
+ end
+
module Controller
def self.included(base)
base.extend(ClassMethods)