Random Ordering through Solr with Sunspot

246 views
Skip to first unread message

Tom Cocca

unread,
Jan 28, 2010, 6:36:07 PM1/28/10
to ruby-sunspot
Has anybody tried to do random ordering through sunspot / sunspot rails?

It would also be great if that random sort would work with pagination.

Let me know if anybody has any ideas.

Thanks,
~ Tom

Mat Brown

unread,
Jan 29, 2010, 12:27:03 AM1/29/10
to ruby-s...@googlegroups.com
Hi Tom,

Sunspot does do random(ish) ordering, using order_by(:random) -
however, because it's random(ish), pagination isn't meaningful.

That said, Solr does allow for a consistent "random" ordering across
searches by way of specifying the same random field name. I'd be open
to a way to express that in the Sunspot API.

Cheers!
Mat

> --
> You received this message because you are subscribed to the Google Groups
> "Sunspot" group.
> To post to this group, send email to ruby-s...@googlegroups.com.
> To unsubscribe from this group, send email to
> ruby-sunspot...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/ruby-sunspot?hl=en.
>

Tom Cocca

unread,
Feb 4, 2010, 7:07:58 PM2/4/10
to ruby-s...@googlegroups.com
Mat, sorry for the late response.

The order_by(:random) works fine for now.  I's not a huge issue that it doesn't work with pagination although that would be an awesome feature.  What would it take to implement that?  Generating a random number say 423 and do an order_by(:random_423) ?

Does that random_# field have to be an existing field in your index or can it just be made up on the fly?

Thanks again,
~ Tom
Reply all
Reply to author
Forward
0 new messages