From 5d28cb709acff03dfab4675fa86032fcc96ed5f2 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 3 Feb 2023 13:23:27 +1100 Subject: [PATCH] FIX: de-prioritize archived topics (#20161) Previously due to an error archived topics were more prominent in search than closed topics. This amends our internal logic to ensure archived topics are bumped down the list. --- lib/search.rb | 4 +++- spec/lib/search_spec.rb | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/search.rb b/lib/search.rb index ae9ec947e37..af244565081 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -1161,7 +1161,9 @@ class Search WHEN #{Searchable::PRIORITIES[:high]} THEN #{SiteSetting.category_search_priority_high_weight} ELSE - CASE WHEN topics.closed + CASE WHEN topics.archived + THEN 0.85 + WHEN topics.closed THEN 0.9 ELSE 1 END diff --git a/spec/lib/search_spec.rb b/spec/lib/search_spec.rb index 515684c7670..feca2de42eb 100644 --- a/spec/lib/search_spec.rb +++ b/spec/lib/search_spec.rb @@ -948,15 +948,23 @@ RSpec.describe Search do expect(result.blurb(result.posts.first)).to eq(expected_blurb) end - it "applies a small penalty to closed topic when ranking" do - post = + it "applies a small penalty to closed topics and archived topics when ranking" do + archived_post = + Fabricate( + :post, + raw: "My weekly update", + topic: + Fabricate(:topic, title: "A topic that will be archived", archived: true, closed: true), + ) + + closed_post = Fabricate( :post, raw: "My weekly update", topic: Fabricate(:topic, title: "A topic that will be closed", closed: true), ) - post2 = + open_post = Fabricate( :post, raw: "My weekly update", @@ -964,7 +972,7 @@ RSpec.describe Search do ) result = Search.execute("weekly update") - expect(result.posts.pluck(:id)).to eq([post2.id, post.id]) + expect(result.posts.pluck(:id)).to eq([open_post.id, closed_post.id, archived_post.id]) end it "can find posts by searching for a url prefix" do