When applying a filter on the terms of a taxonomy, results are sometimes duplicated; this happens when a terms filter (HasTerms) is applied (in combination to other filters, e.g. a filter on content types) and a content item matches the filter for more than one term: in this situation, the resulting contentItems list contains multiple occurences of the same content item (specifically, one occurence for each term matching the filter).
Patch has to be applied here in ProjectionManager instead of Orchard.Taxonomies.Projections.TermsFilter.ApplyFilter function because, in the latter, query is not executed yet and, for this reason, duplicate content items cannot be removed.
Edit: after more digging, the issue is caused by the "random sorting", which disables the "select distinct" clause inside the "DefaultHqlQuery.ToHql" function called by the "HqlQuery.Slice" function.
https://github.com/OrchardCMS/Orchard/blob/03884cbd6431721ffe69b03c69ba672a1cb44dc1/src/Orchard.Web/Modules/Orchard.Projections/Services/ProjectionManager.cs#L155C2-L155C2
When applying a filter on the terms of a taxonomy, results are sometimes duplicated; this happens when a terms filter (HasTerms) is applied (in combination to other filters, e.g. a filter on content types) and a content item matches the filter for more than one term: in this situation, the resulting contentItems list contains multiple occurences of the same content item (specifically, one occurence for each term matching the filter).
Patch has to be applied here in ProjectionManager instead of Orchard.Taxonomies.Projections.TermsFilter.ApplyFilter function because, in the latter, query is not executed yet and, for this reason, duplicate content items cannot be removed.
Edit: after more digging, the issue is caused by the "random sorting", which disables the "select distinct" clause inside the "DefaultHqlQuery.ToHql" function called by the "HqlQuery.Slice" function.