random order

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

random order

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

(obviously paging would not work)

thanks
ryan
Reply | Threaded
Open this post in threaded view
|

RE: random order

pbinkley
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:[hidden email]]
Sent: Friday, February 09, 2007 12:28 AM
To: [hidden email]
Subject: random order

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

(obviously paging would not work)

thanks
ryan
Reply | Threaded
Open this post in threaded view
|

RE: random order

Chris Hostetter-3

: 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