incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Borja Martín <>
Subject counting tags within a date range
Date Mon, 01 Mar 2010 13:33:46 GMT
I have these documents :

{ "created_at": "20100301", "tag": "foo" },
{ "created_at": "20100301", "tag": "bar" },
{ "created_at": "20100301", "tag": "foo-bar" },
{ "created_at": "20100302", "tag": "foo" }

and what I want is to retrieve the documents within a date range and count
how many times does each tag appear globally, not just by its date. I should
get something like this:
{ "foo" : 2, "bar" : 1, "foo-bar" : 1}

So, in the first attempt, I wrote the following map/reduce functions:
// map
function(doc) {
// reduce
function (key, values, rereduce) {
  return sum(values);

Obviously this didn't work as the documents are grouped by the whole key and
if I set the group_level to 1, the documents are grouped only by the date:



Then I changed the emit function by setting the tag as the first position
for the key:

Now I can group the results and get how many times each tag appears:



The problem with this, is that I can't restrict the query to certain date
ranges as I get always all the documents in spite of the second part of the



when I should get something like

I was wondering if this is the normal collation behaviour or I'm missing
anything and if there is any way to achieve this. I also tried to add the
collation option to 'raw' in the view definition just in case, but I got the
same results.

Thanks in advance.


def dagi3d(me)
 case me
   when :web then  ""
   when :twitter then ""

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message