Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Unique Product Content Types under an instance of Node Content

Vote:
 

Hi,

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!

#200870
Jan 29, 2019 18:23
Vote:
 

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

#200875
Jan 30, 2019 4:07
Vote:
 

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

#200901
Jan 30, 2019 12:41
Vote:
 

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 =>
                    x.Ancestors().Match(currentContent.ContentLink.ToReferenceWithoutVersion().ToString()))
                        .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;

#200925
Jan 30, 2019 19:15
Vote:
 

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

#200928
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.