Try our conversational search powered by Generative AI!

Unique Product Content Types under an instance of Node Content



My catalog contains a collection of node content pages and under any node could be a number of different implementations of a product content type.

When loading my category node, I'd like to run a query to return the unique product content types which are children of that node. For example when loading a page, if there are 100 of one product and only 2 of another type, i'd like my query to return the 2 unique types.

My site is using Find so maybe there's a clever option using that.

Has anyone had to do this before?

Thanks in advance!

Jan 29, 2019 18:23

Hi Johnny,

I think you can use Episerver Find facet to do this.

Example query:

 var query = SearchClient.Instance.Search<ProductContent>().Filter(x => x.ParentLink.Match(currentNodeContentLink.ToReferenceWithoutVersion().ToString())).Take(0).TermsFacetFor(x => x.ContentTypeName());

Hope this help

Jan 30, 2019 4:07

Thank you Binh. This looks like just what i was looking for. I will give it a try!

Jan 30, 2019 12:41

Hi Binh,

This query does the trick and works for multi level category hierarchies

            // use Find to execute search with the content type id set as a facet
            var result = SearchClient.Instance.Search<BaseProduct>()
                .Filter(x =>
                        .Take(0).TermsFacetFor(x => x.ContentTypeID.ToString()).GetContentResult();

            // extract the content type id's form the result
            var types = result.TermsFacetFor(x => x.ContentTypeID.ToString()).Terms;

Jan 30, 2019 19:15

Yeah, your query works for multi level category hierarchies. Great job!

Edited, Jan 31, 2019 3:08
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.