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"
This commit is contained in:
Sam 2016-07-25 16:26:33 +10:00
parent e01802a13b
commit 12ecf8624a
2 changed files with 13 additions and 1 deletions

View File

@ -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

View File

@ -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')