mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-24 23:44:09 -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 @term.present?
|
||||||
if is_topic_search
|
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.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
|
else
|
||||||
posts = posts.where("post_search_data.search_data @@ #{ts_query}")
|
posts = posts.where("post_search_data.search_data @@ #{ts_query}")
|
||||||
exact_terms = @term.scan(/"([^"]+)"/).flatten
|
exact_terms = @term.scan(/"([^"]+)"/).flatten
|
||||||
|
|
|
@ -213,6 +213,10 @@ describe Search do
|
||||||
# stop words should work
|
# stop words should work
|
||||||
results = Search.execute('this', search_context: post1.topic)
|
results = Search.execute('this', search_context: post1.topic)
|
||||||
expect(results.posts.length).to eq(4)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue