incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Smith <...@proven-corporation.com>
Subject Re: group_level and sorting
Date Sun, 19 Apr 2009 06:37:11 GMT
Nicolas Clairon wrote:
> Hi all !
> 
> I have a question (wich is a big concerne to me and my project) about
> the group_level option.
> 
> I want to display all doc by tag and then sorting them by date.
> 
> The map function :
> -----------------------------------
> function(doc){
>   for(var t in doc.tags){
>     emit([doc.tags[t], doc.creation_date], doc.title);
>   }
> }
> ------------------------------------
> 
> * creation_date is a float since the epoch (ie something like this 12423344.003)
> * docs can have the same title

[snip]

> $ curl http://localhost:5984/db/_design/foo/_view/by_tag_sort_by_date?reduce=false
> 
> returns :
> 
> {"id":"8075ba2ef7418f4d6c9a3e89be83acd8","key":["tag1",1239361935.000004],"value":"title2"},
> {"id":"8d9132318a6c34c646e9e2cd43823ffa","key":["tag1",1239794744.000002],"value":"title1"},
> {"id":"f49a28ffd2118298c1be7440ec4556fa","key":["tag2",1239794744.000002],"value":"title1"},

Hi, Nicolas.  I'm curious, can you perhaps just use the map, with no 
reduce?  To get a date-sorted list of docs for tag "tag1", you can query 
with startkey=["tag1", null]&endkey=["tag1", {}].

(null always sorts before floats, and {} always sorts after.)

Also, do you think that your reduce function breaks the guidelines from 
the Wiki?  http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views 
(Check toward the bottom under "Reduce Value Sizes.")  The rule of thumb 
is that reduce is for summarizing information and map alone is good for 
extracting sets of data.

-- 
Jason Smith
Proven Corporation
Bangkok, Thailand
http://www.proven-corporation.com

Mime
View raw message