]> source.dussan.org Git - redmine.git/commitdiff
Allow single Chinese character as a search keyword (#30037).
authorGo MAEDA <maeda@farend.jp>
Fri, 30 Nov 2018 15:42:30 +0000 (15:42 +0000)
committerGo MAEDA <maeda@farend.jp>
Fri, 30 Nov 2018 15:42:30 +0000 (15:42 +0000)
Patch by Go MAEDA.

git-svn-id: http://svn.redmine.org/redmine/trunk@17667 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/search.rb
test/unit/search_test.rb

index 6740221515abb89f2f91470b443f33a6c3979671..e88736f55a80b80a25417158ed0fd52abf68e41f 100644 (file)
@@ -60,7 +60,8 @@ module Redmine
         # 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 }
+        # but for Chinese characters (汉字/漢字), 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
       end
index ab2bab1ffbea90d1eddb956fa7fdd5154e8ee36a..a6ae15d0b79ed8138e1802bc30b77aad2d25a4a5 100644 (file)
@@ -194,6 +194,11 @@ class SearchTest < ActiveSupport::TestCase
     assert_equal ['Special', 'chars', 'in a phrase Öö'], f.tokens
   end
 
+  def test_fetcher_should_exclude_single_character_tokens_except_for_chinese_characters
+    f = Redmine::Search::Fetcher.new('ca f é 漢 あ 한', User.anonymous, %w(issues), Project.all)
+    assert_equal ['ca', '漢'], f.tokens
+  end
+
   private
 
   def remove_permission(role, permission)