A platform for community discussion. Free, open, simple.
FIX: Improve regexp for matching version lexeme.
Guo Xiang Tan0f53ad58c28c
diff --git a/app/services/search_indexer.rb b/app/services/search_indexer.rbindex 2ee91b71766..acd343a00bc 100644--- a/app/services/search_indexer.rb+++ b/app/services/search_indexer.rb@@ -59,7 +59,7 @@ class SearchIndexertsvector.scan(/'(([a-zA-Z0-9]+\.)+[a-zA-Z0-9]+)'\:([\w+,]+)/).reduce(additional_lexemes) do |array, (lexeme, _, positions)|count = 0- if lexeme !~ /^(\d+\.)?(\d+\.)?(\*|\d+)$/+ if lexeme !~ /^(\d+\.)?(\d+\.)*(\*|\d+)$/loop docount += 1break if count >= 10 # Safeguard here to prevent infinite loop when a term has many dotsdiff --git a/spec/services/search_indexer_spec.rb b/spec/services/search_indexer_spec.rbindex fc8624eccdc..e1af96d0f65 100644--- a/spec/services/search_indexer_spec.rb+++ b/spec/services/search_indexer_spec.rb@@ -143,10 +143,17 @@ describe SearchIndexer doit 'should not tokenize versions' dopost.topic.update!(title: "this is a title that I am testing")- post.update!(raw: '1.2.2')+ post.update!(raw: '123.223')expect(post.post_search_data.search_data).to eq(- "'1.2.2':10 'test':8A 'titl':4A 'uncategor':9B"+ "'123.223':10 'test':8A 'titl':4A 'uncategor':9B"+ )++ post.update!(raw: '15.2.231.423')+ post.reload++ expect(post.post_search_data.search_data).to eq(+ "'15.2.231.423':10 'test':8A 'titl':4A 'uncategor':9B")end