A platform for community discussion. Free, open, simple.
FIX: exact matching should also match on title
Sam858a26603111
diff --git a/lib/search.rb b/lib/search.rbindex 236ba6c96eb..adab7e3a7e4 100644--- a/lib/search.rb+++ b/lib/search.rb@@ -698,7 +698,7 @@ class Searchposts = posts.where("post_search_data.search_data @@ #{ts_query(weight_filter: weights)}")exact_terms = @term.scan(/"([^"]+)"/).flattenexact_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}%")endendenddiff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rbindex 148f28be8b9..273be47c31a 100644--- a/spec/components/search_spec.rb+++ b/spec/components/search_spec.rb@@ -282,7 +282,7 @@ describe Search doit "works for unlisted topics" dotopic.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 doendend+ 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" dolet(:result) { Search.execute(topic.id, type_filter: 'topic', search_for_id: true, min_search_term_length: 1) }