0

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!

Barka
  • 8,764
  • 15
  • 64
  • 91

2 Answers2

0

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.

Jayendra
  • 52,349
  • 4
  • 80
  • 90
  • I wasn't able to find a Lucene equivalent, if anyone knows of one, please do share. Thanks! – Barka Oct 27 '11 at 00:18
0

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

Community
  • 1
  • 1
L.B
  • 114,136
  • 19
  • 178
  • 224
  • Thanks! Unfortunately. this will randomize all docs. I want to only randomize among all docs that have the top score. – Barka Oct 26 '11 at 15:26
  • @user277498 You may try randomize by about 10%, that way you can obtain a similar effect(altough not the same) – L.B Oct 26 '11 at 17:09
  • I don't understand. What do you mean by randomize by 10%? – Barka Oct 27 '11 at 00:19
  • @user277498 Suppose original score is 0.5 then you can randomly add or subtract a number which is smaller than 0.025 tho get a new score between 0.475 & 0.525 – L.B Oct 27 '11 at 06:04