diff --git a/lib/search.rb b/lib/search.rb index 236ba6c96eb..adab7e3a7e4 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -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 diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index 148f28be8b9..273be47c31a 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -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) }