Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Nikolaj Hjelm Kaplan 5 posts 25 karma points
    Sep 05, 2014 @ 11:30
    Nikolaj Hjelm Kaplan
    0

    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?

  • Nikolaj Hjelm Kaplan 5 posts 25 karma points
    Sep 08, 2014 @ 12:16
    Nikolaj Hjelm Kaplan
    0

    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();
  • Morten Skjoldager 440 posts 1499 karma points
    Sep 15, 2014 @ 10:45
    Morten Skjoldager
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft