AI OnAI Off
Hi Johnny,
With these below extensions, the indexed field names are not the same as extension/property names:
I do not understand deeply why Episerver did like that. But if you want to reuse these available indexed fields for your purpose then you should change code like this:
var searchQuery = SearchClient.Instance.Search<BaseProduct>()
.Filter(x =>
x.Ancestors().Match(currentContent.ContentLink.ToReferenceWithoutVersion().ToString()))
.Take(0).TermsFacetFor(x => x.CommonType(), request => request.Field = "_Type").GetContentResult();
// extract the content type id's form the result
var terms = searchQuery.TermsFacetFor(x => x.CommonType()).Terms;
One more note, the CommonType is full content type name within namespace name. If you just want to query facet for content type name without namespace name, you can use query as following as:
var searchQuery = SearchClient.Instance.Search<BaseProduct>()
.Filter(x =>
x.Ancestors().Match(currentContent.ContentLink.ToReferenceWithoutVersion().ToString()))
.Take(0).TermsFacetFor(x => x.CommonTypeShortName(), request => request.Field = "_TypeShortNamme").GetContentResult();
// extract the content type id's form the result
var terms = searchQuery.TermsFacetFor(x => x.CommonTypeShortName()).Terms;
That is excellent Binh. Done the trick perfectly. Once again thank you for your help. Much appreciated!
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:
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:
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