Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr - Return random results (Sort by Random)

Tags:

solr

In Solr, Whats the best approach to order results by random?, basically needs to pick some records at random.

like image 485
xelber Avatar asked Aug 10 '14 23:08

xelber


1 Answers

Use a RandomSortField. There's an example in the bundled schema.xml in example directory (under solr):

<dynamicField name="random_*" type="random" />

Sort your result list by the field random_<seed>, where you replace <seed> with a randomly generated value (but use the same value if you're paginating through the result, as it will give you a stable sort based on the field name).

like image 190
MatsLindh Avatar answered Jan 04 '23 05:01

MatsLindh