FIX: AI Helper category / tag suggestion when user does not categories muted (#1042)

This commit is contained in:
Rafael dos Santos Silva 2024-12-23 15:58:26 -03:00 committed by GitHub
parent ceac6e5efb
commit 792df58fbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -109,10 +109,12 @@ module DiscourseAi
schema
.asymmetric_similarity_search(raw_vector, limit: limit, offset: 0) do |builder|
builder.join("topics t on t.id = topic_id")
builder.where(<<~SQL, exclude_category_ids: muted_category_ids.map(&:to_i))
t.category_id NOT IN (:exclude_category_ids) AND
t.category_id NOT IN (SELECT categories.id FROM categories WHERE categories.parent_category_id IN (:exclude_category_ids))
SQL
unless muted_category_ids.empty?
builder.where(<<~SQL, exclude_category_ids: muted_category_ids.map(&:to_i))
t.category_id NOT IN (:exclude_category_ids) AND
t.category_id NOT IN (SELECT categories.id FROM categories WHERE categories.parent_category_id IN (:exclude_category_ids))
SQL
end
end
.map { |r| [r.topic_id, r.distance] }
end