mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
FIX: strip quote from search term when searching within topic
This commit is contained in:
parent
c1f62d8657
commit
e01802a13b
2 changed files with 15 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue