Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 38083 invoked from network); 8 Apr 2011 16:28:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Apr 2011 16:28:07 -0000 Received: (qmail 89111 invoked by uid 500); 8 Apr 2011 16:28:05 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 89085 invoked by uid 500); 8 Apr 2011 16:28:05 -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 89077 invoked by uid 99); 8 Apr 2011 16:28:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Apr 2011 16:28:05 +0000 X-ASF-Spam-Status: No, hits=0.0 required=5.0 tests=SPF_HELO_PASS,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: unknown ~alla (nike.apache.org: encountered unrecognized mechanism during SPF processing of domain of david@cloudant.com) Received: from [216.86.168.183] (HELO mxout-08.mxes.net) (216.86.168.183) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Apr 2011 16:27:58 +0000 Received: from [192.168.1.100] (unknown [67.180.255.146]) by smtp.mxes.net (Postfix) with ESMTPA id 361D6509ED for ; Fri, 8 Apr 2011 12:27:37 -0400 (EDT) Message-ID: <4D9F377E.4000803@cloudant.com> Date: Fri, 08 Apr 2011 09:27:42 -0700 From: David Hardtke User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 MIME-Version: 1.0 To: user@couchdb.apache.org Subject: Re: View advice References: <0A3CF017-6578-4AC4-9149-21A4340F536D@gmail.com> <4D9EDB10.3000704@matulla.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked by ClamAV on apache.org You can send multiple keys to the view if you use POST: POST /db/_design/ddoc/_view/name?reduce=true/false -d '{"queries":[{"key":"NY"},{"key","CA"}]}' You'll still need to remove duplicates and merge the two views for the two keys. On 04/08/11 04:39, Daniel Itabora� wrote: > I would love to be able to do union operations like Keith described and I > would love even more to be able to send a javascript function to a view. > That function would then filter out the documents based on whatever criteria > I want, something like > > function(doc) { > // returns true to those documents I want to retrieve > return doc.type == "Article"&& (doc.location == "NY" || doc.location == > "CA" ); > } > > You probably don�t even need the whole doc, filtering solely based on the > emitted keys through the function could do the trick. You�d still have to > specify an appropriate key range to speed up things though. > > This would screw up the reduce results stored on the Btree, but I feel that > "view limited ad hoc querying" is such an important thing, that I would > forgo the speed of reduce in these cases. > > Simple things should be possible, even if they conflict with design goals. > > Daniel > > On Fri, Apr 8, 2011 at 6:53 AM, Peter Matulla > wrote: > >> another approach: >> >> http://www.vertigrated.com/blog/2010/04/generic-ad-hoc-queries-in-couchdb/ >> >> Peter >> >> ------------------------------------------------------------------------ >> >> -------- Original Message -------- >> Subject: Re: View advice >> From: Olafur Arason >> To: user@couchdb.apache.org >> Date: Freitag, 8. April 2011 07:57:25 >> >>> You can fake it if you want: >>> >>> function(doc) { >>> if(doc.type == "Article"&& (doc.location == "NY" || doc.location == >> "CA" )){ >>> emit(["NYCA", doc.release_date], doc) >>> } >>> } >>> >>> Or join the discussion about why views should have search fields so this >> could >>> be resolved once and for all. >>> >>> They it would be: >>> >>> function(doc) { >>> if(doc.type == "Article" )){ >>> emit(doc.release_date, doc, doc.location) >>> } >>> } >>> >>> then query it with: >>> >>> _view/articles?limit=5&decending=true&search="NY OR CA" >>> >>> Btw you only need this to call it from couchapp. It's better not to have >> the >>> whole url so you can easily change hosts and even database names >>> like application-test. >>> >>> There is some work going on in this direction and it's important to let >> people >>> know that this is important. >>> >>> Regards, >>> Olafur Arason >>> >>> On Fri, Apr 8, 2011 at 03:13, Pierre-Alexandre Lacerte >>> wrote: >>>> I am currently trying to create a view to reproduce this SQL query: >>>> >>>> SELECT * FROM articles WHERE articles.location="NY" OR >> articles.location="CA" ORDER BY articles.release_date DESC >>>> I tried to create a view with a complex key: function(doc) { if(doc.type >> == "Article") { emit([doc.location, doc.release_date], doc) } } >>>> And then using startkey and endkey to retrieve one location and ordering >> the result on the release date. >>>> >> http://myhost.com:8000/mydb/_design/application/_view/articles?startkey=["NY", >> {}]&endkey=["NY"]&limit=5&descending=true >>>> This works fine. >>>> >>>> However, I learned that I cannot send multiple startkeys and endkeys to >> my view. (To mimic WHERE articles.location="NY" OR articles.location="CA") >>>> How should I design this? (It could happen that I would need to query >> for 15 different locations) >>>> So far, I have 3 suggestions: >>>> 1- Store the view output in its own database, and make a new view to >> sort by release date. I'm not sure if this option will be fast and scale >> well... >>>> 2- Use couchdb-lucene. >>>> 3- Hack my version to support multiple startkeys or endkeys. >> https://issues.apache.org/jira/browse/COUCHDB-523 >>>> Thanks for your help, >>>> >>>> Pierre >>