Reputation: 77
Suppose we are searching with iphone and in Brand facet we are getting the below facets 1)Amzer 2)Apple 3)Araree 4)Casemate 5)DailyObjects
It is based on alphabetic order. But we want to sort the facet values based on some customized score of each brand. Is there any feature available in solr faceting which will fulfil the above requirement?
If we have the score against each brand facet values then is there any way to perform facet in the solr end ?
Currently, solr is having only two facet.sort options i.e. index and count. We want to incorporate other sorting option apart from index and count. Please suggest.
Upvotes: 0
Views: 377
Reputation: 52792
Since you're talking about aggregation of a field, you can do this by using the Facet JSON API:
The example given does what you're asking about:
{
categories:{
type : terms // terms facet creates a bucket for each indexed term in the field
field : cat,
sort : "x desc", // can also use sort:{x:desc}
facet : {
x : "avg(price)", // x = average price for each facet bucket
y : "max(popularity)" // y = max popularity value in each facet bucket
}
}
}
This sums up the average price of all the elements in the facet, while also sorting by it - giving you the categories with the highest average price first.
The supported list of functions you can use for aggregation under facets is available in the reference guide:
Upvotes: 1