A platform for community discussion. Free, open, simple.
FIX: Don't inject extra terms for version lexeme.
Guo Xiang Tanb70f1084f7aa
diff --git a/app/services/search_indexer.rb b/app/services/search_indexer.rbindex a73585e5791..2ee91b71766 100644--- a/app/services/search_indexer.rb+++ b/app/services/search_indexer.rb@@ -59,13 +59,15 @@ class SearchIndexertsvector.scan(/'(([a-zA-Z0-9]+\.)+[a-zA-Z0-9]+)'\:([\w+,]+)/).reduce(additional_lexemes) do |array, (lexeme, _, positions)|count = 0- loop do- count += 1- break if count >= 10 # Safeguard here to prevent infinite loop when a term has many dots- term, _, remaining = lexeme.partition(".")- break if remaining.blank?- array << "'#{term}':#{positions} '#{remaining}':#{positions}"- lexeme = remaining+ if lexeme !~ /^(\d+\.)?(\d+\.)?(\*|\d+)$/+ loop do+ count += 1+ break if count >= 10 # Safeguard here to prevent infinite loop when a term has many dots+ term, _, remaining = lexeme.partition(".")+ break if remaining.blank?+ array << "'#{term}':#{positions} '#{remaining}':#{positions}"+ lexeme = remaining+ endendarraydiff --git a/spec/services/search_indexer_spec.rb b/spec/services/search_indexer_spec.rbindex b814949ce0f..fc8624eccdc 100644--- a/spec/services/search_indexer_spec.rb+++ b/spec/services/search_indexer_spec.rb@@ -141,6 +141,15 @@ describe SearchIndexer do)end+ it 'should not tokenize versions' do+ post.topic.update!(title: "this is a title that I am testing")+ post.update!(raw: '1.2.2')++ expect(post.post_search_data.search_data).to eq(+ "'1.2.2':10 'test':8A 'titl':4A 'uncategor':9B"+ )+ end+it 'should tokenize host of a URL and removes query string' docategory = Fabricate(:category, name: 'awesome category')topic = Fabricate(:topic, category: category, title: 'this is a test topic')