couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Keen ...@visiture.com>
Subject Re: selecting a random subset of a view
Date Mon, 28 Jun 2010 13:36:01 GMT
In the application requesting the view, generate a random skip parameter, and set the limit
parameter to 3. This will allow you to grab a random set of results from Couch. More info
on these parameters is here:

http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options

Just make sure skip is never greater than the number of total results - 3.

Mike

On Jun 28, 2010, at 9:29 AM, <mickael.bailly@free.fr> <mickael.bailly@free.fr>
wrote:

> Hello couchers,
> 
> how would you do to select a random subset of a view result (a simple view with map only).
> 
> Example (I don't write the full view response array for clarity)
> 
> When called normally, my view returns :
> 
> {
> ...
> rows: [
> {id: aa1},
> {id: aa2},
> {id: aa3},
> {id: aa4},
> {id: aa5},
> {id: aa6},
> {id: aa7},
> {id: aa8},
> {id: aa9}
> ]
> }
> 
> And I want only three of those rows, randomly chosen. So I launch the magic "get three
random rows" feature, and it gives me :
> 
> {
> ...
> rows: [
> {id: aa5},
> {id: aa3},
> {id: aa6}
> ]
> }
> 
> The second time I launch the same magic "get three random rows" I got:
> {
> ...
> rows: [
> {id: aa7},
> {id: aa1},
> {id: aa5}
> ]
> }
> 
> Thanks for your advices
> 
> Mickael


Mime
View raw message