Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 46432 invoked from network); 8 Jan 2010 17:52:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Jan 2010 17:52:24 -0000 Received: (qmail 65131 invoked by uid 500); 8 Jan 2010 17:52:23 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 65054 invoked by uid 500); 8 Jan 2010 17:52:23 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 65044 invoked by uid 99); 8 Jan 2010 17:52:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jan 2010 17:52:23 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of jchris@gmail.com designates 209.85.222.182 as permitted sender) Received: from [209.85.222.182] (HELO mail-pz0-f182.google.com) (209.85.222.182) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jan 2010 17:52:13 +0000 Received: by pzk12 with SMTP id 12so4951022pzk.13 for ; Fri, 08 Jan 2010 09:51:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to :content-type:content-transfer-encoding; bh=PsBgzFmnM3kacYyVV4bIBeyEnR/jt82q9nujvtf08v8=; b=IlebyXg7Jhx4r23yNnbkpT/ijxa6XSIQAFIUtq4mYOnlN2Nkk9yROmT/uSb8x6YBdy iFf6mv7102LYY8ZtgVCHVHWE4n44gGwj44pBQa+XwokpAOxyaLv3+vW2GJa8DYw2mrq8 Tkv3r533nv8n0BKIpuq3e9Suw60AbnWDJpon0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; b=OxLq4Kppj7PbMBeWI4VIhlPHZQsXS142iLl+0cgzOv8IUuocIsPXqiZSiPt5f2W5Ke AwFLFPilLgs5Unq6cQAzW47OnnBSISqn8WH/IeXG00BD+t/7QHyQ+idTn62uAu8l9kf/ UrbcX00y2slVfkDFF2aMRB/6yFOhm4mag5Gi4= MIME-Version: 1.0 Sender: jchris@gmail.com Received: by 10.142.209.20 with SMTP id h20mr3887148wfg.167.1262973111946; Fri, 08 Jan 2010 09:51:51 -0800 (PST) In-Reply-To: <8d8b110e1001080610m7d3cd3dn1b1e2a5538820adc@mail.gmail.com> References: <8d8b110e1001080610m7d3cd3dn1b1e2a5538820adc@mail.gmail.com> Date: Fri, 8 Jan 2010 09:51:51 -0800 X-Google-Sender-Auth: 31bdcdf534105f9b Message-ID: Subject: Re: Ordering results from reduce function From: Chris Anderson To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On Fri, Jan 8, 2010 at 6:10 AM, Borja Mart=EDn wrote: > Hi, > suppose I have the typical view used to index the tags of a document: > > // map > function(doc) { > =A0for (var idx in doc.tags) { > =A0 emit(doc.tags[idx], 1); > =A0} > } > > // and then I have this reduce function to count how many documents I hav= e > for each given tag: > function(key,values) { > =A0return sum(values); > } > > and with the following sample documents: > { "tags" : ["foo", "foo bar"] }, > { "tags" : ["foo", "bar", "foo bar"]} > > I get these results: > {"rows":[ > =A0{"key":"bar","value":1}, > =A0{"key":"foo","value":3}, > =A0{"key":"foo bar","value":2} > ]} > > What I want to do is to get the results ordered by its value so I can kno= w > 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 somethi= ng > like emit([reduce_value, tag], null); Is there any way to accomplish that= ? > This is a common request, but not supported directly by CouchDB's views -- to do this you'll need to copy the group-reduce query to another database, and build a view to sort by value. This is a tradeoff we make in favor of dynamic range queries and incremental indexes. Chris > Has it sense or am I misunderstanding something? > > Thanks in advance > > Regards > > -- > def dagi3d(me) > =A0case me > =A0 when :web then =A0"http://dagi3d.net" > =A0 when :twitter then "http://twitter.com/dagi3d" > =A0end > end > --=20 Chris Anderson http://jchrisa.net http://couch.io