Return-Path: Delivered-To: apmail-incubator-couchdb-user-archive@locus.apache.org Received: (qmail 64996 invoked from network); 8 Nov 2008 01:18:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Nov 2008 01:18:08 -0000 Received: (qmail 97082 invoked by uid 500); 8 Nov 2008 01:18:13 -0000 Delivered-To: apmail-incubator-couchdb-user-archive@incubator.apache.org Received: (qmail 97047 invoked by uid 500); 8 Nov 2008 01:18:13 -0000 Mailing-List: contact couchdb-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-user@incubator.apache.org Delivered-To: mailing list couchdb-user@incubator.apache.org Received: (qmail 97036 invoked by uid 99); 8 Nov 2008 01:18:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Nov 2008 17:18:13 -0800 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 paul.joseph.davis@gmail.com designates 74.125.92.145 as permitted sender) Received: from [74.125.92.145] (HELO qw-out-1920.google.com) (74.125.92.145) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 08 Nov 2008 01:16:56 +0000 Received: by qw-out-1920.google.com with SMTP id 4so1057710qwk.54 for ; Fri, 07 Nov 2008 17:17:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=wKCCs8AvNBi1J5yIbpp6KlUrhdp1NoOT7/gmsG78hY8=; b=w6UnHvobww6lCpfLGZ/HBtizPtirhUt+HyQkNF3dKJwjl45VZFUYjPmHd7E3yslyOA 7+V0F2Jo2iZppw/gGQwLDnmoxAhAImpGZIoPVcbBtuwxdQPU66eEjSNIPjCKARWdMblD iXcxQWNj7lEeujcyKIe9E0voV/IWgNJKYFV5w= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=DfsbaGMJPk1W+/Q/Ez0wXIftAn96Tr/KgLGMKYHHKO79/b+VVdsmlV9Ar1iTmgG9mW FjPTs3VN7odV8vTjUgy9jyN6/h24P42rUL29PTOLwhws1MzGeUdMOyIlxpi0e9cyLRvx lmuF9pMFx+xNZMcTvdl3Zmib4+UX7mXi2/+lM= Received: by 10.214.148.1 with SMTP id v1mr4977270qad.194.1226107058277; Fri, 07 Nov 2008 17:17:38 -0800 (PST) Received: by 10.214.215.21 with HTTP; Fri, 7 Nov 2008 17:17:38 -0800 (PST) Message-ID: Date: Fri, 7 Nov 2008 20:17:38 -0500 From: "Paul Davis" To: couchdb-user@incubator.apache.org Subject: Re: Reduce function error "keys has no properties" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Virus-Checked: Checked by ClamAV on apache.org John, You're not accounting for a rereduce. There's a third parameter `rereduce` for reduce functions that is a boolean. Fairly certain when it's true keys is null. This is the commutative and associative thing rearing. Your reduce function needs to operate on its own output. Paul On Fri, Nov 7, 2008 at 8:05 PM, John Bartak wrote: > I get the error "Query Server Log Message: function raised exception (TypeError: keys has no properties)" when I run my reduce function and try to use the keys parameter. I thought keys was supposed to have the documentId's for each document passed in through the values parameter? > > My View looks like: > > function(doc) > { > function emitParts(parts,doc) > { > for (var i = 0; i < parts.length; ++i) > { > emit(parts[i].substr(0,3).toLowerCase(),doc); > } > } > > if (doc.type == "Person") > { > var parts; > if (doc.Name && typeof(doc.Name) == "string") > { > parts = doc.Name.split(new RegExp("[ ]")); > emitParts(parts,doc); > } > if (doc.Email && typeof(doc.Email) == "string") > { > parts = doc.Email.split(new RegExp("[.@ ]")); > emitParts(parts,doc); > } > > } > } > function( keys, values ) > { > var usedKeys = ''; > var reduced = []; > for ( var i = 0; i < keys.length; ++i ) > { > if (usedKeys.indexOf('%!' + keys[i] + '%!') == -1) > { > usedKeys = usedKeys + '%!' + keys[i] + '%!'; > reduced.push(values[i]); > } > } > return reduced; > } > > If I remove any reference to keys from the reduce function, the error goes away. > > This View creates keys where that are the first 3 characters found in every word of the Person's eMail and Name fields. > > The intent of the usedKeys code in the reduce function is deal with the case where a document has an Email field and a Name field that have words that start with the same 3 characters. It prevents the same document from being inserted in the results twice. > > >