Search code examples
solrlucenefacetsolandra

Counting in facet results


By counting in facet results I mean resolve the problem:

I have 7 documents:

A1   B1   C1
A2   B1   C1
A3   B2   C1
A4   B2   C2
A5   B3   C2
A6   B3   C2
A7   B3   C2

If I make the facet query by field B, get the result: B1=2, B2=2, B3=3.

A1   B1   C1
A2   B1   C1     2 - facing by B
--------------====
A3   B2   C1
A4   B2   C2     2 - facing by B
--------------====
A5   B3   C2
A6   B3   C2
A7   B3   C2     3 - facing by B
--------------====

I want to get additional information, something like count in results, by field C. So, how can I query to get a result similar to the following:

A1   B1   C1
A2   B1   C1     2, 1 - facing by B, count C in facet results
--------------=======
A3   B2   C1
A4   B2   C2     2, 2 - facing by B, count C in facet results
--------------=======
A5   B3   C2
A6   B3   C2
A7   B3   C2     2, 1 - facing by B, count C in facet results
--------------=======

Thanks


Solution

  • What you need is Facet Pivots
    This will help you get the results and counts of hierarchies.

    This is available in Solr 4.0 trunk build. So you may need to apply the patch.

    References -
    http://wiki.apache.org/solr/HierarchicalFaceting
    http://wiki.apache.org/solr/SimpleFacetParameters#Pivot_.28ie_Decision_Tree.29_Faceting