lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <>
Subject Re: Facet Sorting
Date Wed, 18 Jul 2018 22:45:29 GMT

: If I want to plug in my own sorting for facets, what would be the best 
: approach. I know, out of the box, solr supports sort by facet count and 
: sort by alpha. I want to plug in my own sorting (say by relevancy). Is 
: there a way to do that? Where should I start with if I need to write a 
: Custom Facet Component?

it sounds like you're talking about the "classic" facets (using 
"facet.field") where facet.sort only supports "count" (desc) and "index" 

Adding a custom sort option there would be close to impossible.

The newer "json.facets" API supports a much more robust set of options, 
that includes the ability to sort on an "aggregate" function across all 
documents in the bucket...

some of the existing sort options there might solve your need, but it's 
also possible using that API to write your own ValueSourceParser plugin 
that can be used to sort facets as long as it returns ValueSources that 
extend "AggValueSource"

: Basically I want to plug the scores calculated in earlier steps for the 
: documents matched, do some kind of aggregation of the scores of the 
: documents that fall under a facet and use this aggregate score to rank 

IIUC what you want is possibly something like...

curl http://localhost:8983/solr/techproducts/query -d 'q=features:lcd&rows=0&
     type : terms,
     field : cat,
     sort : { x : desc },
       x : "sum(query($q))",

...which will sort the buckets by the sum of the scores of every document 
in that bucket (using the original query .. but you could alternatively 
sort by any aggregation of the scores from any arbitrary query / document 
based function)


View raw message