In addition to the different ways of creating facets, there is a concept of facet by pivots that is provided by Solr and is exposed via Solarium. Pivot faceting allows us to create facets within the results of the parent facet. The input to pivot faceting is a set of fields to pivot on. Multiple fields create multiple sections in the response.
Here is the code to create a facet pivot on genre
and availability
(in stock):
$facetqry = $facetset->createFacetPivot('genre-instock'); $facetqry->addFields('genre_s,inStock');
To display the pivots, we have to get all facets from the resultset.
$facetResult = $resultSet->getFacetSet()->getFacet('genre-instock');
And for each facet, get the field, value, and count for the facet and more facet pivots within the facet.
echo 'Field: '.$pivot->getField().PHP_EOL; echo 'Value: '.$pivot->getValue().PHP_EOL; echo 'Count: '.$pivot->getCount().PHP_EOL;
Also get all pivots inside this facet and process them in the same fashion...