0
votes

For a particular query type, I get many many documents with the same top score. I want to randomly pull 10 documents each time this query is called. So users that do the same search will get different results each time. This does sound like a really bad idea but it actually makes business sense.

My thinking right now is to get all documents from the index that have the top score, and then randomly pick 10 from those.

How do I do this? Is there another way?

Please note that I still want the top scores to remain on top, just shuffled. I do not want to include the lower scores in the shuffle nor exclude them from appearing at the bottom of the list.

Many thanks!

2

2 Answers

0
votes

Solr/Lucene provides an random sort field, with which you can randomly sort the documents.
As your scores for all the documents are the same, they will be randomly sorted.

<fieldType name="random" class="solr.RandomSortField" />

<dynamicField name="random*" type="random" indexed="true" stored="false"/>

you can sort them with e.g. sort=random_1234 desc
Generating the random number e.g. 1234 will always return new set of documents. However, same number will generate the same set.

Check for the lucene.net implementation.

0
votes

See this link ( “Shuffling” a Lucene Hits result set) about randomizing search results using CustomScoreQuery.