skip is going to be a performance penalty, since couch need to seek over all 
skipped rows, IIRC. but for smaller skip-values this approach should work

On 28.06.2010, at 15:36, Mike Keen wrote:

> 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, <[email protected]> 
> <[email protected]> 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
> 

Reply via email to