Project

General

Profile

Feature #38446 » 38446-v2.patch

Go MAEDA, 2024-04-30 10:14

View differences:

lib/redmine/search.rb
135 135
      def tokens
136 136
        # extract tokens from the question
137 137
        # eg. hello "bye bye" => ["hello", "bye bye"]
138
        tokens = @question.scan(%r{(([[:space:]]|^)"[^"]+"([[:space:]]|$)|[[:^space:]]+)}).collect {|m| m.first.gsub(%r{(^[[:space:]]*"[[:space:]]*|[[:space:]]*"[[:space:]]*$)}, '')}
138
        tokens = @question.scan(/"[^"]+"|[^\p{Zs}]+/).map do |token|
139
          # Remove quotes from quoted tokens, strip surrounding whitespace
140
          # e.g. "\" foo bar \"" => "foo bar"
141
          token.gsub(/\A"\p{Zs}*|\p{Zs}*"\Z/, '')
142
        end
139 143
        # tokens must be at least 2 characters long
140 144
        # but for Chinese characters (Chinese HANZI/Japanese KANJI), tokens can be one character
141 145
        # no more than 5 tokens to search for
test/unit/lib/redmine/search_test.rb
30 30
    value = "全角\u3000スペース"
31 31
    assert_equal %w[全角 スペース], Redmine::Search::Tokenizer.new(value).tokens
32 32
  end
33

  
34
  def test_tokenize_should_support_multiple_phrases
35
    value = '"phrase one" "phrase two"'
36
    assert_equal ["phrase one", "phrase two"], Redmine::Search::Tokenizer.new(value).tokens
37
  end
33 38
end
(2-2/2)