Quantcast
Channel: Using Optimizely Platforms
Viewing all articles
Browse latest Browse all 8020

Using TermFacets to return a list of product namespaces under a node

$
0
0

Hi,

I need to run a Find Query to return a list of product namespaces which exist under a category node. So when the category loads, it will hit Find to ask what types of products exist as descendants in a multi level catalog. If there are 100 of product type A and 2 of product type B i should get two results with the namespace of each.

If i run this code, i get a list of localised content type names:

            // use Find to execute search with the content type id set as a facet
            var searchQuery = SearchClient.Instance.Search<BaseProduct>()
                .Filter(x =>
                    x.Ancestors().Match(currentContent.ContentLink.ToReferenceWithoutVersion().ToString()))
                        .Take(0).TermsFacetFor(x => x.ContentTypeName()).GetContentResult();
            // extract the content type id's form the result
            var terms = searchQuery.TermsFacetFor(x => x.ContentTypeName()).Terms;

However the localized content type name is not exactly what i need to i updated my code as follows which i hoped would include the Common Type namespaces:

            var searchQuery = SearchClient.Instance.Search<BaseProduct>()
                .Filter(x =>
                    x.Ancestors().Match(currentContent.ContentLink.ToReferenceWithoutVersion().ToString()))
                        .Take(0).TermsFacetFor(x => x.CommonType()).GetContentResult();
            // extract the content type id's form the result
            var terms = searchQuery.TermsFacetFor(x => x.CommonType()).Terms;

However on trying to facet the common type, i always get a null result.

The type is stored in the Find index so there must be a way of returning it as a facet? Any advice would be much appreciated?

Thanks,

Johnny


Viewing all articles
Browse latest Browse all 8020

Trending Articles