FIX: strip quote from search term when searching within topic

This commit is contained in:
Sam 2016-07-25 15:06:25 +10:00
parent c1f62d8657
commit e01802a13b
2 changed files with 15 additions and 1 deletions

View file

@ -516,8 +516,18 @@ class Search
if @term.present?
if is_topic_search
term_without_quote = @term
if @term =~ /"(.+)"/
term_without_quote = $1
end
if @term =~ /'(.+)'/
term_without_quote = $1
end
posts = posts.joins('JOIN users u ON u.id = posts.user_id')
posts = posts.where("posts.raw || ' ' || u.username || ' ' || COALESCE(u.name, '') ilike ?", "%#{@term}%")
posts = posts.where("posts.raw || ' ' || u.username || ' ' || COALESCE(u.name, '') ilike ?", "%#{term_without_quote}%")
else
posts = posts.where("post_search_data.search_data @@ #{ts_query}")
exact_terms = @term.scan(/"([^"]+)"/).flatten

View file

@ -213,6 +213,10 @@ describe Search do
# stop words should work
results = Search.execute('this', search_context: post1.topic)
expect(results.posts.length).to eq(4)
# phrase search works as expected
results = Search.execute('"fourth post I am posting"', search_context: post1.topic)
expect(results.posts.length).to eq(1)
end
end