Project

General

Profile

Actions

Patch #30037

closed

Allow single Chinese character as a search keyword

Added by Go MAEDA over 5 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Search engine
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

Currently, Redmine requires at least 2 characters length for search keywords. It is not a problem for languages such as English and French.

But for languages such as Japanese and Chinese, the limitation imposes inconvenience for users because there are some words which consist of only a single character. Some examples as follows:

  • 金 = money in Japanese and Chinese
  • 水 = water in Japanese and Chinese
  • 猪 = a wild boar in Japanese, a pig in Chinese
  • 陈 = a common family name for Chinese people

To allow such single character search keywords, I suggest the following patch. It accepts single multibyte-character keywords while keeping the current limitation for keywords with ASCII characters.

diff --git a/lib/redmine/search.rb b/lib/redmine/search.rb
index 674022151..d4c0b9b20 100644
--- a/lib/redmine/search.rb
+++ b/lib/redmine/search.rb
@@ -59,8 +59,8 @@ module Redmine
         # 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 in ASCII
+        @tokens = @tokens.uniq.select {|w| w.bytesize > 1 }
         # no more than 5 tokens to search for
         @tokens.slice! 5..-1
       end

Files

Actions

Also available in: Atom PDF