Parent Child loading and facets
We have the parent concept of an Article, with zero or more child Attachments.
We have used the approach below, with the following field names in accordance to this help page:
- parentField: "@computedfoldingchildren", (Articles have this field, it is a multivalue field of the sitecore guids of each child Attachment. Attachments do not have this field at all).
- childField: "@computedfoldingprimaryid", (Both Articles and Attachments have this field, it is simply the sitecore guid)
- filterField: "@computedfoldingid", (Both Articles and Attachments have this, for an Article it is its own sitecore guid, for an Attachment it is its parent Articleâs sitecore guid)
It seems to be working in my poc, though my result object is shaped slightly different than how I was expecting. It seems like I get one result per âgroupâ. Unless the parent Article is the outer âhitâ, it is loaded as the .parentResult, with children loaded as .childResults. This is not ideal but should work for us.
The issue we now face is with facets. To oversimplify, Articles have metadata we facet on, letâs simplify it down to âGeographyâ. Attachments typically donât have geography explicitly, but would inherit the concept from the parent. So I went ahead and added geography as a computed field to the Attachments (derived from the parent during the crawl). (This also allows us to do field level filtering, i.e. @geography=Canadaâ¦which unless Iâm mistaken we need to have on the Attachments otherwise it will fail?)
But the problem I have is if I groupBy facet on @geography, Iâd like to have each âgroupâ (a âgroupâ being Article and its Attachments) count only once. Say for example q: is âDogâ. I have an Article that does not contain âDogâ at all, but it has 3 Attachments, only two of which contains âDogâ. Letâs say the Articleâs @geography is Canada. Iâd like the facet for Canada to be 1, despite the article itself not having âdogâ, and 2 of the attachments hitting (and having their parent Articleâs inherited Geography as Canada). Right now I seem to be getting 2 as the count in the groupby. Similarly if say the Article and and 1 of the 3 attachments has âdogâ, I get 2.
I tried for example playing with queryOverride on the groupBy clause, but a) it doesnât seem to have an effect (maybe not on our version of Coveo?) and b) not sure it is the right approach for this.
Just to clarify above, as I know folding is commonly used for email threads, my analogy would be that we have a thread weâve constructed consisting of any emails in the thread that satisfy the query filters, plus the original email in the thread whether it satisfies the filters or not. We know that every email in the thread has the same field @geography=Canada as metada, but when we facet we want the entire thread to only count once for the count of Canada.
This is currently a limitation of the folding components. The facets will not be adjusted to the number of result shown. It will instead show the total amount of documents, including the folded items.
An Idea has been opened: https://coveo.ideas.aha.io/ideas/CID-I-365