A platform for community discussion. Free, open, simple.
FIX: filter out hidden/whisper/deleted posts from keyword filter. (#35648)
Samf27c631ac32d
diff --git a/lib/topics_filter.rb b/lib/topics_filter.rbindex 8a01f8ed2c4..2df327c1f15 100644--- a/lib/topics_filter.rb+++ b/lib/topics_filter.rb@@ -110,7 +110,7 @@ class TopicsFilterSELECT topic_idFROM post_search_dataJOIN posts ON posts.id = post_search_data.post_id- WHERE search_data @@ #{ts_query}+ WHERE search_data @@ #{ts_query} AND NOT posts.hidden AND posts.deleted_at IS NULL #{whisper_condition("posts")})SQLenddiff --git a/spec/lib/topics_filter_spec.rb b/spec/lib/topics_filter_spec.rbindex 120983f6de7..21d4412beb2 100644--- a/spec/lib/topics_filter_spec.rb+++ b/spec/lib/topics_filter_spec.rb@@ -2237,6 +2237,19 @@ RSpec.describe TopicsFilter doexpect(scope.pluck(:id)).to eq([post1.topic_id])end+ it "excludes topics with only deleted or hidden posts from keyword search" do+ SearchIndexer.enable+ visible_post = Fabricate(:post, raw: "searchterm")+ _deleted_post = Fabricate(:post, raw: "searchterm", deleted_at: Time.zone.now)+ _hidden_post = Fabricate(:post, raw: "searchterm", hidden: true)+ _whisper_post = Fabricate(:post, raw: "searchterm", post_type: Post.types[:whisper])++ filter = TopicsFilter.new(guardian: Guardian.new)+ scope = filter.filter_from_query_string("searchterm")++ expect(scope.pluck(:id)).to contain_exactly(visible_post.topic_id)+ end+describe "with a custom filter" dofab!(:topic)