Faceting can also be done on range basis. So for example, we can create facet counts of books for every two dollars. Using range faceting, we can give counts of books with prices between 0-2 dollars and from 2-4 dollars and so on.
$facetqry = $facetset->createFacetRange('pricerange'); $facetqry->setField('price'); $facetqry->setStart(0); $facetqry->setGap(2); $facetqry->setEnd(16);
In the preceding code, we start faceting from price 0
dollars and up to 16
dollars. The following code will be used to display the range facets along with their counts after executing the query:
$facetCnts = $resultSet->getFacetSet()->getFacet('pricerange'); foreach($facetCnts as $range => $cnt){ echo $range.' to '.($range+2).': ['.$cnt.']'."<br/>".PHP_EOL; }
5481523 [http-bio-8080-exec-4] INFO org.apache.solr.core.SolrCore – [collection1] webapp=/solr path=/select params={facet=true&f.price.facet.range.gap=2&facet.range={!key%3Dpricerange...