FIX: exact matching should also match on title

This commit is contained in:
Sam 2018-05-08 15:59:03 +10:00
parent c6f45fcfdb
commit 858a266031
2 changed files with 12 additions and 2 deletions

View File

@ -698,7 +698,7 @@ class Search
posts = posts.where("post_search_data.search_data @@ #{ts_query(weight_filter: weights)}")
exact_terms = @term.scan(/"([^"]+)"/).flatten
exact_terms.each do |exact|
posts = posts.where("posts.raw ilike ?", "%#{exact}%")
posts = posts.where("posts.raw ilike :exact OR topics.title ilike :exact", exact: "%#{exact}%")
end
end
end

View File

@ -282,7 +282,7 @@ describe Search do
it "works for unlisted topics" do
topic.update_attributes(visible: false)
post = new_post('discourse is awesome', topic)
_post = new_post('discourse is awesome', topic)
results = Search.execute('discourse', search_context: topic)
expect(results.posts.length).to eq(1)
end
@ -312,6 +312,16 @@ describe Search do
end
end
context 'searching for quoted title' do
it "can find quoted title" do
create_post(raw: "this is the raw body", title: "I am a title yeah")
result = Search.execute('"a title yeah"')
expect(result.posts.length).to eq(1)
end
end
context "search for a topic by id" do
let(:result) { Search.execute(topic.id, type_filter: 'topic', search_for_id: true, min_search_term_length: 1) }