Range faceting can be done on date fields and numeric fields.
Range faceting parameters:
Parameter |
Behavior |
Default value |
facet.range |
Specifies the field for which Solr should create range facets. For example: facet.range=salary&facet.range=rank facet.range=createdDate |
|
facet.range.start |
Specifies from where (lower bound) the range starts. For example: f.salary.facet.range.start=10000.0&f.rank.facet.range.start=1 f.createdDate.facet.range.start=NOW/DAY-30DAYS |
|
facet.range.end |
Specifies where (upper bound) the range ends. For example: f.salary.facet.range.end=100000.0&f.rank.facet.range.end=50 f.createdDate.facet.range.end=NOW/DAY+30DAYS |
|
facet.range.gap | The size of each range will be added to the lower bound successively until the upper bound is reached. | |
facet.range.hardend |
A Boolean parameter that specifies how Solr should handle cases where facet.range.gap does not divide evenly between lower bound and upper bound. If it is true, the last range constraint will have the facet.range.end value as an upper bound. If false, the last range will have the smallest possible upper bound greater than facet.range.end such that the range is the exact width of the specified range gap. |
false |
facet.range.include |
Determines how to compute range faceting between the lower bound and upper bound. Possible values are:
|
|
facet.range.other |
Specifies that, in addition to the counts for each range between lower bound and upper bound, counts should be computed for these options as well:
|
|
facet.range.method |
Specifies a faceting method:
|
filter |
Example: Search query for iPod with faceting enabled and range for the field price from 1000 to 100000
URL: http://localhost:8983/solr/techproducts/select?defType=edismax&q=ipod&fl=id,name,price&facet=true&facet.range=price&facet.range.start=10&facet.range.end=20&facet.range.gap=5
Response:
{
"responseHeader":{
"status":0,
"QTime":1,
"params":{
"facet.range":"price",
"q":"ipod",
"defType":"edismax",
"facet.range.gap":"5",
"fl":"id,name,price",
"facet":"true",
"facet.range.start":"10",
"facet.range.end":"20"}},
"response":{"numFound":3,"start":0,"docs":[
{
"id":"IW-02",
"name":"iPod & iPod Mini USB 2.0 Cable",
"price":11.5},
{
"id":"F8V7067-APL-KIT",
"name":"Belkin Mobile Power Cord for iPod w/ Dock",
"price":19.95},
{
"id":"MA147LL/A",
"name":"Apple 60 GB iPod with Video Playback Black",
"price":399.0}]
},
"facet_counts":{
"facet_queries":{},
"facet_fields":{},
"facet_ranges":{
"price":{
"counts":[
"10.0",1,
"15.0",1],
"gap":5.0,
"start":10.0,
"end":20.0}},
"facet_intervals":{},
"facet_heatmaps":{}}}