Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOLR: ordering results alphabetically by field

Tags:

solr

SOLR results are normally ordered by "best match" of your search criteria. Is it possible to order the results alphabetically by a given SOLR field?

I realize that this is not a typical use case, but here's my motivation. We have quite a lot of code written around SOLR that performs queries based on user searches against the various fields of our data. Most of the time, we want a relevancy ordering (i.e. best matches first).

But one anomalous use-case requires that we return data ordered alphabetically by field. I could perform this query using our SQL database (avoiding SOLR altogether), but I'd have to replicate an awful lot of code that's tailored around consuming SOLR results (facets in particular). I'm hoping to use the same code path, if it's possible to get such an ordering from SOLR.

like image 505
George Armhold Avatar asked Aug 26 '11 16:08

George Armhold


1 Answers

Yes, you just have to set the sort parameter to field-name

like image 102
Arnaud Le Blanc Avatar answered Sep 28 '22 09:09

Arnaud Le Blanc