From 12ecf8624a97c3d33aaa3cd56851b5f1ca347c90 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 25 Jul 2016 16:26:33 +1000 Subject: [PATCH] FIX: tokenize words with dots correctly hello.world is now tokenized as "hello.world" and "world" that way the word "world" will find the post with "hello.world" --- app/models/search_observer.rb | 9 ++++++++- spec/components/search_spec.rb | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/search_observer.rb b/app/models/search_observer.rb index c04166c55ac..88b8e05b6e2 100644 --- a/app/models/search_observer.rb +++ b/app/models/search_observer.rb @@ -125,7 +125,14 @@ class SearchObserver < ActiveRecord::Observer def characters(string) scrubbed << " " - scrubbed << string + scrubbed << string.gsub(/\p{L}*\.\p{L}*/) do |with_dot| + split = with_dot.split(".") + if split.length > 1 + with_dot + (" " << split[1..-1].join(" ")) + else + with_dot + end + end scrubbed << " " end end diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index 698fb568c74..91a88719f56 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -540,6 +540,11 @@ describe Search do end + it 'can tokenize dots' do + post = Fabricate(:post, raw: 'Will.2000 Will.Bob.Bill...') + expect(Search.execute('bill').posts.map(&:id)).to eq([post.id]) + end + it 'supports category slug and tags' do # main category category = Fabricate(:category, name: 'category 24', slug: 'category-24')