From f51f37eddf008b35adbe4b683536b5a11adb1ac2 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Thu, 20 Jun 2019 22:03:45 -0400 Subject: [PATCH] FEATURE: apply a small penalty to closed topics when searching (#7782) --- lib/search.rb | 6 +++++- spec/components/search_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/search.rb b/lib/search.rb index 13a31492d2c..12af2135949 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -861,7 +861,11 @@ class Search THEN #{SiteSetting.category_search_priority_high_weight} WHEN #{Searchable::PRIORITIES[:very_high]} THEN #{SiteSetting.category_search_priority_very_high_weight} - ELSE 1 + ELSE + CASE WHEN topics.closed + THEN 0.9 + ELSE 1 + END END ) ) diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index 0eff908d6ac..3e8f6b1eea7 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -359,6 +359,26 @@ describe Search do post.id, category.topic.first_post.id, post2.id ]) end + + it 'applies a small penalty to closed topic when ranking' do + post = Fabricate(:post, + raw: "My weekly update", + topic: Fabricate(:topic, + title: "A topic that will be closed", + closed: true + ) + ) + + post2 = Fabricate(:post, + raw: "My weekly update", + topic: Fabricate(:topic, + title: "A topic that will be open" + ) + ) + + result = Search.execute('weekly update') + expect(result.posts.pluck(:id)).to eq([post2.id, post.id]) + end end context 'searching for quoted title' do