couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Borja Martín <>
Subject Ordering results from reduce function
Date Fri, 08 Jan 2010 14:10:09 GMT
suppose I have the typical view used to index the tags of a document:

// map
function(doc) {
  for (var idx in doc.tags) {
   emit(doc.tags[idx], 1);

// and then I have this reduce function to count how many documents I have
for each given tag:
function(key,values) {
 return sum(values);

and with the following sample documents:
{ "tags" : ["foo", "foo bar"] },
{ "tags" : ["foo", "bar", "foo bar"]}

I get these results:
 {"key":"foo bar","value":2}

What I want to do is to get the results ordered by its value so I can know
which are the most used tags for example. I know that the results are
ordered by the key so I guess this could be done if I could use the value
returned by the reduce on it while calling the emit function with something
like emit([reduce_value, tag], null); Is there any way to accomplish that?

Has it sense or am I misunderstanding something?

Thanks in advance


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

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