Following up on questions
- How to get facet ranges in solr results?
- SolR Query - Price ranges
if I understand correctly, to get the number of matches per price intervals in Solr, here are the different ways one can use:
- per static price intervals:
- facet.range
- facet.query
- per dynamic price intervals
- there is Solr JIRA to get dynamic facet intervals:Solr JIRA 1581: Facet by function
To get only price min and price max:
- for the field "price" on the whole index: StatsComponent
Now my question is: I can get result grouping work OK, but how to get price min and max 开发者_如何转开发on each group (&group=true). Is there a Solr JIRA associated with it ?
Lucene JIRA 3097: Post group faceting does presents results in global facets and not in "per group" results.
Solr version: 5.4 and above.
I have a solution for this and I have implemented in my project.
You have to use json facet to achive the max and min value based on the facet result.
json.facet={
tags_group:{
type:terms,
field:tags,
limit:-1,
facet:{
pricemin:{
type:terms,
field:price,
limit:1,
sort:{
x:asc
},
facet:{
x:"min(price)"
}
},
pricemax:{
type:terms,
field:price,
limit:1,
sort:{
y:desc
},
facet:{
y:"max(price)"
}
}
}
}
}
In the above Json facet I have used tags as filed(multivalued) and this will create a bucket like this
<str name="val">Letter Holder</str>
<int name="count">2</int>
<lst name="pricemin">
<arr name="buckets">
<lst>
<double name="val">899.0</double>
<int name="count">1</int>
<double name="x">899.0</double>
</lst>
</arr>
</lst>
<lst name="pricemax">
<arr name="buckets">
<lst>
<double name="val">1299.0</double>
<int name="count">1</int>
<double name="y">1299.0</double>
</lst>
</arr>
</lst>
精彩评论