You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Ryan McKinley <ry...@gmail.com> on 2007/02/09 08:28:14 UTC

random order

Is there a way to return documents in a random order?

(obviously paging would not work)

thanks
ryan

RE: random order

Posted by Chris Hostetter <ho...@fucit.org>.
: I think you could implement your own scoring algorithm to provide a
: random score to each document in the result set
: (http://lucene.apache.org/java/docs/api/org/apache/lucene/search/package
: -summary.html#changingSimilarity). The default sort would then operate
: on the random values.

I'd be really suprised if you could get a "fair" random distribution with
a custom similarity.  You could write a custom ValueSource thta builds a
"FieldCache" like structure where the values are random and then use that
in a FunctionQuery -- but using that in combination with another query to
restrict the result set would be ... anoying.

the cleanest approach to truely randomize the order of any search
at the "Lucene" level would be with a new
SortComparatorSource/ScoreDocComparator ... but if you were willing
to put custom logic in at the "Solr" level you could do this in the
a RequestHandler using a DocIterator ... there's an algorithm for
fairly picking N random elements from a stream of elements even when you
don't know the length of the stream, i don't remember what it's called but
i could probably remember the psuedo code if no one else knows what i'm
talking about (i believe it involves maintaining a queue of size N and
pushing item number I onto the queue if a random float F < 1/I)



-Hoss


RE: random order

Posted by "Binkley, Peter" <Pe...@ualberta.ca>.
I think you could implement your own scoring algorithm to provide a
random score to each document in the result set
(http://lucene.apache.org/java/docs/api/org/apache/lucene/search/package
-summary.html#changingSimilarity). The default sort would then operate
on the random values.

Peter 

-----Original Message-----
From: Ryan McKinley [mailto:ryantxu@gmail.com] 
Sent: Friday, February 09, 2007 12:28 AM
To: solr-user@lucene.apache.org
Subject: random order

Is there a way to return documents in a random order?

(obviously paging would not work)

thanks
ryan