Gravatar for slangevin@coveo.com

Question by Simon, Jul 27, 2016 9:29 AM

Parent Child loading and facets

The bellow scenario is using the REST Search API directly, not using the JavaScript UI

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.

1 Reply
Gravatar for slangevin@coveo.com

Answer by Simon, Jul 27, 2016 1:40 PM

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

Ask a question