Patch #30037 » 30037-allow-single-multibyte-search-keyword.diff
| lib/redmine/search.rb (working copy) | ||
|---|---|---|
| 59 | 59 |
# extract tokens from the question |
| 60 | 60 |
# eg. hello "bye bye" => ["hello", "bye bye"] |
| 61 | 61 |
@tokens = @question.scan(%r{((\s|^)"[^"]+"(\s|$)|\S+)}).collect {|m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '')}
|
| 62 |
# tokens must be at least 2 characters long |
|
| 63 |
@tokens = @tokens.uniq.select {|w| w.length > 1 }
|
|
| 62 |
# tokens must be at least 2 characters long for ASCII characters |
|
| 63 |
# but single character tokens are allowed for multibyte characters |
|
| 64 |
@tokens = @tokens.uniq.select {|w| w.bytesize > 1 }
|
|
| 64 | 65 |
# no more than 5 tokens to search for |
| 65 | 66 |
@tokens.slice! 5..-1 |
| 66 | 67 |
end |
| test/unit/search_test.rb (working copy) | ||
|---|---|---|
| 194 | 194 |
assert_equal ['Special', 'chars', 'in a phrase Öö'], f.tokens |
| 195 | 195 |
end |
| 196 | 196 | |
| 197 |
def test_fetcher_should_ignore_too_short_tokens |
|
| 198 |
f = Redmine::Search::Fetcher.new('x yz 雲 天空', User.anonymous, %w(issues), Project.all)
|
|
| 199 |
assert_equal ['yz', '雲', '天空'], f.tokens |
|
| 200 |
end |
|
| 201 | ||
| 197 | 202 |
private |
| 198 | 203 | |
| 199 | 204 |
def remove_permission(role, permission) |