mirror of
https://github.com/discourse/discourse.git
synced 2025-04-02 06:11:22 +08:00
FIX: exact matching should also match on title
This commit is contained in:
parent
c6f45fcfdb
commit
858a266031
@ -698,7 +698,7 @@ class Search
|
|||||||
posts = posts.where("post_search_data.search_data @@ #{ts_query(weight_filter: weights)}")
|
posts = posts.where("post_search_data.search_data @@ #{ts_query(weight_filter: weights)}")
|
||||||
exact_terms = @term.scan(/"([^"]+)"/).flatten
|
exact_terms = @term.scan(/"([^"]+)"/).flatten
|
||||||
exact_terms.each do |exact|
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -282,7 +282,7 @@ describe Search do
|
|||||||
|
|
||||||
it "works for unlisted topics" do
|
it "works for unlisted topics" do
|
||||||
topic.update_attributes(visible: false)
|
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)
|
results = Search.execute('discourse', search_context: topic)
|
||||||
expect(results.posts.length).to eq(1)
|
expect(results.posts.length).to eq(1)
|
||||||
end
|
end
|
||||||
@ -312,6 +312,16 @@ describe Search do
|
|||||||
end
|
end
|
||||||
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
|
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) }
|
let(:result) { Search.execute(topic.id, type_filter: 'topic', search_for_id: true, min_search_term_length: 1) }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user