Skip to content

A platform for community discussion. Free, open, simple.

FIX: correct issue with search omitting words with multiple dots

Sam57a1190b07b2
diff --git a/app/services/search_indexer.rb b/app/services/search_indexer.rb
index 2fe7255c76a..fdf6b506690 100644
--- a/app/services/search_indexer.rb
+++ b/app/services/search_indexer.rb
@@ -22,9 +22,7 @@ class SearchIndexer
# insert some extra words for I.am.a.word so "word" is tokenized
# I.am.a.word becomes I.am.a.word am a word
- # uses \p{L} which matchs a single code point in category letter
- # uses \p{N} which matchs a single code point in category number
- search_data = raw_data.gsub(/(\p{L}|\p{N}|_|-|\.)*\.(\p{L}|\p{N}|_|-|\.)*/) do |with_dot|
+ search_data = raw_data.gsub(/[^[:space:]]*[\.]+[^[:space:]]*/) do |with_dot|
split = with_dot.split(".")
if split.length > 1
with_dot + (" " << split[1..-1].join(" "))
diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb
index 3898b38fd6e..16cdae30a24 100644
--- a/spec/components/search_spec.rb
+++ b/spec/components/search_spec.rb
@@ -760,8 +760,9 @@ describe Search do
end
it 'can tokanize website names correctly' do
- post = Fabricate(:post, raw: 'i like wb.camra.org.uk so yay')
- expect(Search.execute('wb.camra.org.uk').posts.map(&:id)).to eq([post.id])
+ post = Fabricate(:post, raw: 'i like http://wb.camra.org.uk/latest#test so yay')
+ expect(Search.execute('http://wb.camra.org.uk/latest#test').posts.map(&:id)).to eq([post.id])
+ expect(Search.execute('camra').posts.map(&:id)).to eq([post.id])
end
it 'supports category slug and tags' do