Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to order groups by count in solr

Tags:

solr

I'm wondering how to order groups in a Solr result. I want to order the groups by numFound. I saw how to order the groups by score here, but that didn't seem to actually make a difference in the examples I looked at, and isn't exactly what I wanted.

In the xml you can see the number per group as numFound and that is what I want to sort the groups by, so for example I could see the largest group at the top.

<arr name="groups">
<lst>
<str name="groupValue">top secret</str>
<result name="doclist" numFound="12" start="0">
...

Any tips appreciated! Thanks!

like image 977
mc-Corkell Avatar asked Jul 03 '13 20:07

mc-Corkell


3 Answers

This is an old question, but it is possible with two queries.

First query: bring back the field you're grouping by as a set of facets for your navigation state. You can limit the number of records returned to 0 here: you just need the facets. The number of facets you return should be the size of your page.

group_id:
     23 (6)
    143:(3)
      5:(2)

Second query: Should be for the records, so no facets are required. The query should be an OR query for the facet field values returned from the first query. (group_id:23 OR group_id:143 OR group_id:5 and so on) and be grouped by the id you are used for grouping.

Sorting: reorder the records from query 2 to match the order from query 1.

That'll do it, with the proviso that I'm not sure how scalable that OR query will be. If you're looking to paginate, remember that you can offset facets: use that as the mechanism instead of offseting the records.

like image 156
jayb0b Avatar answered Oct 21 '22 03:10

jayb0b


Sorting on the numFound is not possible as numFound is not an field in Solr.
Check the discussion mentioning it not being supported and I did not find a JIRA open for the issue as well.

like image 39
Jayendra Avatar answered Oct 21 '22 05:10

Jayendra


Not possible since the last time I looked into this.

like image 44
Flips Avatar answered Oct 21 '22 04:10

Flips