Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EE9AF60FA for ; Sun, 22 May 2011 09:13:12 +0000 (UTC) Received: (qmail 82464 invoked by uid 500); 22 May 2011 09:13:11 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 82435 invoked by uid 500); 22 May 2011 09:13:11 -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 82427 invoked by uid 99); 22 May 2011 09:13:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 22 May 2011 09:13:11 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of mrtrick@gmail.com designates 74.125.83.180 as permitted sender) Received: from [74.125.83.180] (HELO mail-pv0-f180.google.com) (74.125.83.180) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 22 May 2011 09:13:03 +0000 Received: by pvc21 with SMTP id 21so3252609pvc.11 for ; Sun, 22 May 2011 02:12:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=wnotb3Ap3FHoW0iZ+NEUA+9FN2PNfk4rDI6k2X6gI6s=; b=H3RcZwMoDlPg4yx/KaH/PBJN2vb09c7qCHdDm8vZpHn8NLJXdj4BWGU0STLCeMA4jH zbeP/1xay2pTVaiWbG+utN+OO8ouueeW3orQfYtIlpOVz2TM69CanrN/zASrcYKQpqZs IrR9PyPmXSEGQC7RHsHOGjR+QvOjLvt7Bmlpg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=xbwMIdKuCAUtAySTNhvQV1nvRtTNi5hCRQR0wJdP1WvHunw8oVUVcsHhQ99t4jPk1D 232FzNFwpFIB11wovCRJqULYQYtRUFcl3L+ROXHh3l8P/S7LpI0n957fDES8mAZvyIdY iXyh65dZR6Pj/7Srm9ziZo+Ut4pnhaxF6pklc= Received: by 10.68.55.131 with SMTP id s3mr1506395pbp.479.1306055563136; Sun, 22 May 2011 02:12:43 -0700 (PDT) Received: from [192.168.1.101] ([115.187.236.96]) by mx.google.com with ESMTPS id h7sm3617166pbg.74.2011.05.22.02.12.40 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 22 May 2011 02:12:42 -0700 (PDT) Message-ID: <4DD8D383.2060005@gmail.com> Date: Sun, 22 May 2011 19:12:35 +1000 From: Patrick Barnes User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: user@couchdb.apache.org Subject: Re: Mapping multiple entries in an array field? (like tags) References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi He, The view query api supports a 'keys' parameter. http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options So your view can emit a parameter for every tag. function(doc) { for (var i in doc.tags) emit(doc.tags[i],null); } (so the view results would look like: {key:"python",id:"doc1",value:null}, {key:"couchdb",id:"doc1",value:null}, {key:"web",id:"doc1,value:null}, ... And to fetch results for a given set of tags (say 'couchdb' and 'python') you can call: curl -X POST http://localhost:5984/db/ \ -H "Content-Type: application/json" -d '{"keys":["couchdb","python"]}' Hope that helps, -Patrick Barnes On 22/05/2011 4:59 PM, He Shiming wrote: > Dear Community, > > I'm working with documents like this: > { > "tags": ["python", "couchdb", "web"] > } > > I'd like to be able to query this document, by all of the following keys: > "python" > ["python", "web"] > ["couchdb", "python"] > ["web", "python", "couchdb"] > > but not by keys such as: > "redis" > ["python", "redis"] > > It's a tag-like situation. I can have the parameter and the field > sorted in alphabetical order if necessary. But it should support any > number of "tags" as the key. > > The only solution I figured, is to compose a list of possible key > combinations in the map function, then emit all of them. And this way, > one view will only be able to handle a fixed number of keys. For that > matter, the function gets really complicated for the 3-key (or above) > query. So I'm wondering if there are better ways to do this. > > Thanks! > He Shiming >