The method SearchLibrary.GetFacetsFor() takes a single category and a list of facets as input.
I can think of many examples where it would make sense to ask for facets across several categories. For instance in a search UI that works across all products in the shop.
As far as I can see I will need to make a call to GetFacetsFor for each category and manually summarise the data.
This will however give me problems because a product can exist in more than one category.
SearchLibrary.GetFacetsFor() across categories
The method SearchLibrary.GetFacetsFor() takes a single category and a list of facets as input.
I can think of many examples where it would make sense to ask for facets across several categories. For instance in a search UI that works across all products in the shop.
As far as I can see I will need to make a call to GetFacetsFor for each category and manually summarise the data.
This will however give me problems because a product can exist in more than one category.
Am I missing something here?
Facets across categories can be done using this code. query.ToFacets()
//Normal way of using queryable.
var
query = SearchLibrary.FacetedQuery().Where(x => x.Variants.Any());
//adding facets to the query.
IList<Facet> facetsForQuery = GetSelectedFacets();
query.WithFacets(facetsForQuery);
//Getting facets for the query.
IList<Facet> facets = query.ToFacets().ToList();
//Getting products for the query.
IList<Product> products = query.ToList();
Hi Nikolaj, thanks for posting that. The one you have actually just queries the entire product set which is somehow what you needs.
You can also (if you want a fixed set of categories query on the ids something like this (not tested though):
var list = new List<int> {1, 2, 3, 4};
SearchLibrary.FacetedQuery().Where(x => x.CategoryIds.Any(y => list.Contains(y)))
Regards
Morten
is working on a reply...