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:
parent
e01802a13b
commit
12ecf8624a
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue