solrfacetfaceted-searchsolar

Determine terms for facet fields in solr


I base on facet.field and I have one situation. In my store i have base products and variants, when I use facet.field I get count with base products and variants:

Category:
   Chairs(30) <- this is count of base products and variants
   Tables(20) <- this is count of base products and variants

I want to add some terms for facet.field in order to that facet return count only of variants, every product has field like "productType":"baseProduct" or "productType":"variantProduct" I want to use those fields.

Any ideas? how can I use this in some query , please help


Solution

  • You can use facet.pivot to get distinct counts for each type:

    &facet.pivot=productType,category
    

    You can also use the JSON Facet API to do two separate facets:

    {
      base: {
         type: terms,
         field: category,
         domain: { filter: "productType:baseProduct" }
      },
      variant: {
         type: terms,
         field: category,
         domain: { filter : "productType:variantProduct" }
       }
    }