Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 53206 invoked from network); 28 Mar 2009 11:54:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 28 Mar 2009 11:54:31 -0000 Received: (qmail 45696 invoked by uid 500); 28 Mar 2009 11:54:30 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 45601 invoked by uid 500); 28 Mar 2009 11:54:30 -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 45591 invoked by uid 99); 28 Mar 2009 11:54:30 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Mar 2009 11:54:30 +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 clairon@gmail.com designates 209.85.218.170 as permitted sender) Received: from [209.85.218.170] (HELO mail-bw0-f170.google.com) (209.85.218.170) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Mar 2009 11:54:24 +0000 Received: by bwz18 with SMTP id 18so1574990bwz.11 for ; Sat, 28 Mar 2009 04:54:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=Cbzz2DZ9E0FRRCzaH5wkyZ3qFIonwzRlSdD7iiemBbw=; b=dt1OQd2ACA9O3IIDVt3gGTpMLF2FXH8vk9mMDjoHQpdhG191cuOtTEGT7f+Om/XWUr FT5Wci3CBS0Anf4EZe9kQXUUgG7NVW+4SSwEHuSpoPC1WxFERPToptklh3/pt4rZKUip vqQqyF7XIK6NZli5iDfzN0hbhkU9V+xEZWLGk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=ajhbM3/UlU2Q+7aCKkcwDJRESVe+Bqtmcw1VZG8pzlg/e96FjPgQ1ivKyzKL1YiKUm JytwcwOIMMIr0WGuuMmPW7I7Gq5+XRJL5/lu3AxP4o3JeVHYeiCxjsmXaP0fdTUp9VM+ Eq2yEyOzZTOQN9yMahnr6vTIuE0YOfdvvk6Qw= MIME-Version: 1.0 Received: by 10.103.193.12 with SMTP id v12mr810425mup.23.1238241242097; Sat, 28 Mar 2009 04:54:02 -0700 (PDT) In-Reply-To: <4b307fd10903280425m20ed2972k473c7a9dfce4e231@mail.gmail.com> References: <4b307fd10903280348r3ad074d9jaa284183b72be6e6@mail.gmail.com> <49CE025E.2070005@gmx.de> <4b307fd10903280408x6cb6f820rfef671824867a493@mail.gmail.com> <49CE058A.3060706@gmx.de> <4b307fd10903280425m20ed2972k473c7a9dfce4e231@mail.gmail.com> Date: Sat, 28 Mar 2009 12:54:02 +0100 Message-ID: <4b307fd10903280454g3d8688e8t9f8b87ec3f33e43@mail.gmail.com> Subject: Re: Random issue with reduce From: Nicolas Clairon 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 I find a work around by using rereduce like this : function( key, values, rereduce){ var results =3D []; if (!rereduce) { for (var i in values){ if (results.indexOf(values[i]) =3D=3D -1){results.push( values[i] );} } return results; } else { var results =3D []; for( var i in values){ for(var e in values[i]){ results.push(values[i][e]); } } return results; } } But I don't understand why sometime I need to rereduce and sometime (for the same expected result) it is not necessary This is the first version of the reduce function wich produce a result with nested lists... function( key, values, rereduce){ var results =3D []; for (var i in values){ if (results.indexOf(values[i]) =3D=3D -1){results.push( values= [i] );} } return results; } If someone has an anwser... On Sat, Mar 28, 2009 at 12:25 PM, Nicolas Clairon wrote= : > I use this form of reduce to group by key the results. > In the real life, I use this reduce to get all tag group by document id. > > Something like that : > > function(doc){ > =A0 if(doc.doc_type =3D=3D "MyDoc"){ > =A0 =A0 for( var t in doc.tags){ > =A0 =A0 =A0 emit(doc.name, doc.tags[t]); > =A0 =A0 } > =A0 } > } > > and the reduce : > > function(key, values){ > =A0return values; > } > > I get the following result: > > name1 =3D > ["tag1", "tag2", "tag3"] > name2 =3D> ["tag2", "tag3"] > > but sometime I get this result > > name1 =3D [["tag1","tag2","tag3"],["tag4","tag5","tag6","tag7"],["tag8","= tag9"]] > > Note that if the view work well the first time, it will always work fine. > > It is the correct way to go ? > > On Sat, Mar 28, 2009 at 12:10 PM, Sven Helmberger > wrote: >> Nicolas Clairon schrieb: >>> >>> Nop ! >>> >>> Here is the test =A0map function : >>> >>> function(doc){ >>> =A0emit("key", 1); >>> } >>> >>> and the reduce function: >>> >>> function(key, values){ >>> =A0return values; >>> } >>> >>> That work well for a large usecase but sometime, I get this strange >>> behavior... >>> >> >> What purpose does the reduce function have? it doesn't really reduce or >> combine anything so it seems like it could just as well be left out. >> >> Regards, >> Sven Helmberger >> >