Patch #30037 » 30037-allow-single-multibyte-search-keyword.diff
| lib/redmine/search.rb (working copy) | ||
|---|---|---|
|
# 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
|
||
|
@tokens = @tokens.uniq.select {|w| w.length > 1 }
|
||
|
# tokens must be at least 2 characters long for ASCII characters
|
||
|
# but single character tokens are allowed for multibyte characters
|
||
|
@tokens = @tokens.uniq.select {|w| w.bytesize > 1 }
|
||
|
# no more than 5 tokens to search for
|
||
|
@tokens.slice! 5..-1
|
||
|
end
|
||
| test/unit/search_test.rb (working copy) | ||
|---|---|---|
|
assert_equal ['Special', 'chars', 'in a phrase Öö'], f.tokens
|
||
|
end
|
||
|
def test_fetcher_should_ignore_too_short_tokens
|
||
|
f = Redmine::Search::Fetcher.new('x yz 雲 天空', User.anonymous, %w(issues), Project.all)
|
||
|
assert_equal ['yz', '雲', '天空'], f.tokens
|
||
|
end
|
||
|
private
|
||
|
def remove_permission(role, permission)
|
||