Search code examples
solrlucenesolr4

Solr Sorting Not working properly


I'm using this sample query to group the result set by category:

q=test&group=true&group.field=category 

This works as expected and I get this sample response:

"response": 
{"numFound":1,"start":0,"docs":[ 
 { 
  ... 
} 
{"numFound":6,"start":0,"docs":[ 
 { 
  ... 
} 
{"numFound":3,"start":0,"docs":[ 
 { 
  ... 
} 

However, I can't find a way to specify the sort order of the groups by number of docs each group has ("numFound field). I think the "sort" param has something to do with it, but I don't know how to use it.


Solution

  • Seems silly, but there may not be an easy way. One solr-user maillist thread says no. There's another thread I found that it may be doable with a local params and nested query. Basically, seems like there is no easy way to do this.

    One possible approach if you have a lot of groups, is to do one query where the group.limit=0, do the sorting in the app, then use the fq parameter to filter on just those values.

    This page seems like a pretty good general reference on all the grouping functions.