Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 55044 invoked from network); 24 Dec 2009 10:17:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Dec 2009 10:17:11 -0000 Received: (qmail 79194 invoked by uid 500); 24 Dec 2009 10:17:09 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 79085 invoked by uid 500); 24 Dec 2009 10:17: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 79075 invoked by uid 99); 24 Dec 2009 10:17:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Dec 2009 10:17:08 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,HTML_MESSAGE,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.218.218] (HELO mail-bw0-f218.google.com) (209.85.218.218) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Dec 2009 10:16:58 +0000 Received: by bwz10 with SMTP id 10so5300405bwz.35 for ; Thu, 24 Dec 2009 02:16:36 -0800 (PST) MIME-Version: 1.0 Received: by 10.204.11.3 with SMTP id r3mr6824295bkr.107.1261649796207; Thu, 24 Dec 2009 02:16:36 -0800 (PST) In-Reply-To: <41139fcb0912231843n7094ab63p7819cde900b954c3@mail.gmail.com> References: <8d8b110e0912231647i5e556e75i42ff62d1fb162310@mail.gmail.com> <41139fcb0912231843n7094ab63p7819cde900b954c3@mail.gmail.com> From: =?UTF-8?Q?Borja_Mart=C3=ADn?= Date: Thu, 24 Dec 2009 11:13:06 +0100 Message-ID: <8d8b110e0912240213h4b78a5f9j5c26041a25a85f9a@mail.gmail.com> Subject: Re: sorting documents using multiple keys To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=000325557832ef16b0047b76bbc1 --000325557832ef16b0047b76bbc1 Content-Type: text/plain; charset=UTF-8 Hi, thanks for your answer. The thing is that this solution only works for single keys and I can't use the startkey/endkey params in the POST request with the 'keys' param in order to query for multi keys (Thanks for the include_docs tip :)) Regards On Thu, Dec 24, 2009 at 3:43 AM, Anand Chitipothu wrote: > > Then, I create a view to store the documents for each tag: > > > > function(doc) { > > for(var idx in doc.tags) { > > emit(doc.tags[idx], doc); > > } > > } > > > > and eventually I can make a POST request using the keys parameter in > order > > the retrieve all the documents that have one or more of the given tags. > > The problem is that I don't know how to sort the result by the field > > created_at and I can't use it in the emit function within the key as I > will > > not know the value for it (and the documents can different values for it) > > > > Any idea how to achieve this? > > Change your view function to emit both tag and created_at. > > function (doc) { > for (var i in doc.tags) { > emit([doc.tags[i], doc.created_at], null); > } > } > > Also notice that you don't have to emit the doc. It can be included in > the result by adding "include_docs=true" to your query string. > > Use the following request to get all documents, matching a tag. > > http://localhost:5984/ > /_design//?start_key=["mytag"]&end_key=["mytag", > {}]&include_docs=true > > If you want the most recent doc first, try adding descending=true and > swap start_key and end_key. > > I'm not sure if there is any straight-forward way to query for more > than one tag. You can probably achieve that by making your view > function emit all possible combinations of tags in the document. > > Anand > -- def dagi3d(me) case me when :web then "http://dagi3d.net" when :twitter then "http://twitter.com/dagi3d" end end --000325557832ef16b0047b76bbc1--