Deduplicate filter results

when both a card and that card's comments match the search term, we
don't want to show it multiple times.

ref: https://app.fizzy.do/5986089/cards/3030
This commit is contained in:
Mike Dalessio
2025-11-19 17:51:38 -05:00
parent a5f5b592c2
commit 378705a30d
2 changed files with 20 additions and 1 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ class Filter < ApplicationRecord
result.mentioning(term, user: creator)
end
result
result.distinct
end
end
+19
View File
@@ -0,0 +1,19 @@
require "test_helper"
class Filter::SearchTest < ActiveSupport::TestCase
include SearchTestHelper
test "deduplicate multiple results" do
user = users(:david)
board = boards(:writebook)
card = board.cards.create!(title: "Duplicate results test", description: "Have you had any haggis today?", creator: user)
card.published!
card.comments.create(body: "I hate haggis.", creator: user)
card.comments.create(body: "I love haggis.", creator: user)
filter = user.filters.new(terms: [ "haggis" ], indexed_by: "all", sorted_by: "latest")
assert_equal [ card ], filter.cards.to_a
end
end