From user-return-4309-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Sat Apr 04 20:45:10 2009 Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 85390 invoked from network); 4 Apr 2009 20:45:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Apr 2009 20:45:09 -0000 Received: (qmail 17077 invoked by uid 500); 4 Apr 2009 20:45:08 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 16980 invoked by uid 500); 4 Apr 2009 20:45:08 -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 16970 invoked by uid 99); 4 Apr 2009 20:45:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 04 Apr 2009 20:45:08 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jchris@gmail.com designates 74.125.78.24 as permitted sender) Received: from [74.125.78.24] (HELO ey-out-2122.google.com) (74.125.78.24) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 04 Apr 2009 20:45:00 +0000 Received: by ey-out-2122.google.com with SMTP id 25so309482eya.29 for ; Sat, 04 Apr 2009 13:44:38 -0700 (PDT) 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=35qpLRfGHAGI81lyODEP3CzlOo7o6FLePqXhcmPSkdg=; b=XhoI5lQbQrf4pxcONcx79wu0OtFZ/JfHr6AoRA1KSpVPXsMf/QrLae6WtW5eFd49fh EZcYKn11+QDAZ3ygU9iFp3aDk0Ian55oQB1UWGMaurnw1/tAtp+bl/LDAwxkzorGl7rC zwUy5oJzcc9toSCxuMNqg3oHwG5scDGvA2bKU= 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=ks8xwgEAIEpMMZ7WGm7GZxU280YOxcoazXHUHqewX0i1hQNNBVTof8FjoyWfgcPR1j n34OHDYLPYWnwWC8zEEB/jHuQT52oOeQI1EYtBc2mstW5kin4DATIeVtiCOYndwVcylF +M7V9ue2GUtgBNGFfc7zvFj3JTWNrNWrH7LkU= MIME-Version: 1.0 Sender: jchris@gmail.com Received: by 10.210.57.12 with SMTP id f12mr2013127eba.9.1238877878119; Sat, 04 Apr 2009 13:44:38 -0700 (PDT) In-Reply-To: <4b307fd10904040215m77bdb077wc475fb696a7fdf9f@mail.gmail.com> References: <4b307fd10904031357s683fa560oe8fc96e43febca68@mail.gmail.com> <4b307fd10904040215m77bdb077wc475fb696a7fdf9f@mail.gmail.com> Date: Sat, 4 Apr 2009 13:44:38 -0700 X-Google-Sender-Auth: 233bb88632e2e78e Message-ID: Subject: Re: sorting by reduce value 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 Sat, Apr 4, 2009 at 2:15 AM, Nicolas Clairon wrote: > To bad :-( This is a really standard feature. I hope it will be > integrate very soon in couchdb... > > For now, an easier solution would be to create a "doctype_count" document= : > > { > =A0id: "type1", > =A0rev: "1-638393", > =A0number: 1, > } > > And each time a document is created, we increment the "number" field. > A lot of conflict > will appear but I think it will be easy to deal with conflict than > keeping incremental in a > secondary database. Right ? > No. That's a recipe for update conflicts. I think keeping a secondary database up to date will probably be easier, it's just a matter of doing the bookkeeping, like with any external indexer. You might end up having to run the "reduce" externally as well (on groups of map rows). This way you can keep track of which docs/revs contribute to each grouped key, and use that information to rerun the reduce incrementally. If you have few distinct types, you are probably better just using standard CouchDB reduce with group=3Dtrue and sorting the full output by value. > On Fri, Apr 3, 2009 at 11:21 PM, Chris Anderson wrote= : >> On Fri, Apr 3, 2009 at 2:01 PM, Paul Davis = wrote: >>> Nope. There's nothing in CouchDB that allows for this yet. Different >>> methods have been discussed for adding it via things like a value >>> index to allow for users to selectively choose how things are sorted >>> in the output but noone's stepped up with an implementation yet. >>> >> >> I think the simplest path would be to "print" the results of a >> group=3Dtrue or group_level query to a secondary database. Keeping it >> incremental is the challenge. >> >>> HTH, >>> Paul Davis >>> >>> On Fri, Apr 3, 2009 at 4:57 PM, Nicolas Clairon wro= te: >>>> Hi ! >>>> >>>> I'm getting through a sorting issue with couchdb. >>>> >>>> Let's say we have a classic map/reduce for counting the number of >>>> documents by type : >>>> >>>> function(doc){ >>>> =A0emit(doc.doc_type, 1); >>>> } >>>> >>>> function(key, values){ >>>> =A0 return sum(values); >>>> } >>>> >>>> the results would be : >>>> >>>> type1 =3D> 3 >>>> type2 =3D> 1 >>>> type3 =3D> 2 >>>> ... >>>> >>>> My question is simple : How can we sort the result by the compute redu= ce value ? >>>> We can sort by key, but can we sort by value ? >>>> >>>> Regards, >>>> >>>> Nicolas >>>> >>> >> >> >> >> -- >> Chris Anderson >> http://jchrisa.net >> http://couch.io >> > --=20 Chris Anderson http://jchrisa.net http://couch.io