OrchardCMS / Orchard

Orchard is a free, open source, community-focused Content Management System built on the ASP.NET MVC platform.
https://orchardproject.net
BSD 3-Clause "New" or "Revised" License
2.37k stars 1.12k forks source link

Duplicated results when multiple terms are selected in a content item #8732

Open AndreaPiovanelli opened 11 months ago

AndreaPiovanelli commented 11 months ago

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.