Rajdeep Sahoo
Rajdeep Sahoo

Reputation: 77

Is there any way to implement customized (except index/count ) facet values sorting in solr?

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

Answers (1)

MatsLindh
MatsLindh

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:

  • sum, sum(sales), summation of numeric values
  • avg, avg(popularity), average of numeric values
  • min, min(salary), minimum value
  • max, max(mul(price,popularity)), maximum value
  • unique, unique(author), number of unique values
  • hll, hll(author), distributed cardinality estimate via hyper-log-log algorithm
  • percentile, percentile(salary,50,75,99,99.9), Percentile estimates via t-digest algorithm. When sorting by this metric, the first percentile listed is used as the sort value.
  • sumsq, sumsq(rent), sum of squares of field or function
  • variance, wvariance(rent), variance of numeric field or function
  • stddev, stddev(rent), standard deviation of field or function

Upvotes: 1

Related Questions