I'm doing a product search for Episerver Commerce site using Find. Most of the examples and the documentation use the products properties for faceting and filtering the search, but in our case we would like to filter by the all parent catalog nodes/categories the product has. What is the suggested way to accomplish this? Should I create a complex object and index those to Find, or is there another more straightforward way?
By default products in Find will have a hierarchy of all their categories stored against the document. This is available through the Ancestors property. The example below uses a node as the currentContent and retrieves all products within that. Is that what you're looking for?
Thanks Janaka, that can help me to filter the results.
I'm looking for solution to create facets based on nodes the product has. Something like the documentation instructs here (below "Grouping authors"):
var searchResults = client.Search<Book>()
.TermsFacetFor(x => x.Author.Name)
var authorCounts = searchResults
.TermsFacetFor(x => x.[THIS SHOULD BE THE LIST OF PARENT NODES?]).Terms;
foreach(var authorCount in authorCounts)
string authorName = authorCount.Term;
int count = authorCount.Count;
Console.WriteLine(authorName + ": " + count);
I'm now thinking that maybe I should create a property for model that gets the list of parent nodes?
Terms facets would be the right option here.
It depends on the requirements but normally what I would do is probably have two string properties on the product which put it into a top-level category and subcategory. The properties are not visible to editors. These would be the names of the categories obtained through a helper class when indexing.
Then I can simply do terms faceting on these fields in my search.