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 2CC30B499 for ; Wed, 18 Jan 2012 11:57:07 +0000 (UTC) Received: (qmail 81832 invoked by uid 500); 18 Jan 2012 11:57:05 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 81778 invoked by uid 500); 18 Jan 2012 11:57:04 -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 81770 invoked by uid 99); 18 Jan 2012 11:57:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jan 2012 11:57:04 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=NORMAL_HTTP_TO_IP,RCVD_IN_DNSWL_LOW,SPF_PASS,WEIRD_PORT,WEIRD_QUOTING X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of marcello.nuccio@gmail.com designates 209.85.216.180 as permitted sender) Received: from [209.85.216.180] (HELO mail-qy0-f180.google.com) (209.85.216.180) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jan 2012 11:56:59 +0000 Received: by qcsp15 with SMTP id p15so2851754qcs.11 for ; Wed, 18 Jan 2012 03:56:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=la/8x1ynIfuSuViL70LYVC5ZTtyHP2xOKMqjaOwFF6g=; b=XM113i1IcfvFYXsru87XbDTSADEILrDTNqNFe+Kvc0bv495YA78bk8Dh6QVbuvFUJq 4/pxYMLWOjUwMuZScgj4ladFvygx5W+ZB8Golo6lz81EBlz72S8DLGTYTgmr3YQ6QYwx uPPkLML8q4V3O7Ls/lV11aRS6DX00KbKscPT4= MIME-Version: 1.0 Received: by 10.229.78.217 with SMTP id m25mr6611500qck.98.1326887799011; Wed, 18 Jan 2012 03:56:39 -0800 (PST) Received: by 10.229.166.14 with HTTP; Wed, 18 Jan 2012 03:56:38 -0800 (PST) In-Reply-To: References: Date: Wed, 18 Jan 2012 12:56:38 +0100 Message-ID: Subject: Re: get view with a list of keys From: Marcello Nuccio To: user@couchdb.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable CGS, I think we are talking of different things. The original question was: is it possible to make a view request with a list of keys? My response was: yes, but you need to use POST, as documented at http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options Your response was: you can use a GET, simply use as many `key[]=3Dkey` query parameters as needed to send the list of keys. Then I've asked how do you do that, since: 1. it does not work for me. 2. it's not documented. Your sample code does a different thing and does not respond to the original question: is it possible to make a view request with a list of keys? Your sample code uses an array as start/end keys, but this is not the same as asking for a list of keys. Marcello 2012/1/18 CGS : > ...and, yes, it is cache-able because if I repeat the request (with the > exact same parameters), the browser reports "304 Not Modified". > > CGS > > > > On Wed, Jan 18, 2012 at 12:34 PM, CGS wrote: > >> >> Here is an example (I used list function, but it works with pure map >> function nevertheless): >> >> 1. jQuery plugin: >> >> $.test =3D $.test || {}; >> $.extend($.test, { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 fetch_data_startendkey: function(options) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 options =3D options || {}; >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 $.ajax({ >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 type =C2=A0 =C2= =A0 : "GET", >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 url =C2=A0 =C2= =A0 =C2=A0: " >> http://my_domain.domain_type:5984/mydatabase/_design/design_name/_list/l= ist_function_name/view_function_name?startkey=3D >> "+options.startkey+"&endkey=3D"+options.endkey+"&limit=3D"+options.limit= +"&skip=3D"+options.skip+"&descending=3D"+options.descending, >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dataType : "json= ", >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 async =C2=A0 =C2= =A0: false, >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 global =C2=A0 : = false, >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 data =C2=A0 =C2= =A0 : {}, >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error =C2=A0 =C2= =A0: options.error, >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 success =C2=A0: = options.success >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }); >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 } >> }); >> >> 2. jQuery callback: >> >> $.test.fetch_data_startendkey({ >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 startkey: "my_string", >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 endkey: "my_other_string", >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 limit: mylimit, >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 skip: myoffset, >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 descending: my_descending_bool= ean, >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 success : function(data, textS= tatus, headers) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* do something = with the predefined errors and the >> returned data if no predefined error returned */ >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }, >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error : function(code, error, = reason) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* do something = with the error */ >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 }); >> >> where "my_*string" is the list transformed in string (e.g., >> "[\""+key1+"\",\""+key2+...+"\"]", whatever method used to get that >> string), mylimit and myoffset are integers and so on. No manual encoding >> needed (handled by the browser). >> >> 3. The request in log shows no difference from the direct request from t= he >> address bar. >> >> This works for me without any problem for my CouchDB 1.1.0. I know the >> method can be improved to be more robust, but I have no time now for tha= t. >> Nevertheless, GET method works and it doesn't require manual encoding. >> >> CGS >> >> PS: I hope I don't have typos and neither I omitted something as I am >> quite tired now. If I did, please, let me know. >> >> >> >> >> >> On Wed, Jan 18, 2012 at 12:01 PM, Marcello Nuccio < >> marcello.nuccio@gmail.com> wrote: >> >>> I'm not sure to follow... >>> >>> 1. are you sure the GET does work? When I try, the key[] parameters are >>> ignored. >>> >>> 2. IMHO the advantage of GET is cache-ability. Building a JSON is quite >>> easy: >>> =C2=A0 =C2=A0JSON.stringify({ keys: [ "key1", "key2" ] }); >>> >>> Can you give some more information? >>> >>> Thanks, >>> =C2=A0Marcello >>> >>> 2012/1/18 CGS : >>> > The problem with POST method is that you need to do the encoding >>> manually, >>> > while with GET method instead of &key=3D["key1",...], you get >>> > &key[]=3D["key1"]&key[]=3D... To solve the problem, for example, I tr= ansform >>> > the full query in a string and I attach it manually to the web addres= s. >>> In >>> > that way, the browser takes care of encoding for me and I avoid the >>> mess. I >>> > use this method under jQuery AJAX (don't forget to add \" for the dou= ble >>> > quota required in the query). >>> > >>> > Hope it will help. >>> > >>> > CGS >>> > >>> > >>> > >>> > >>> > >>> > On Wed, Jan 18, 2012 at 11:29 AM, Marcello Nuccio < >>> marcello.nuccio@gmail.com >>> >> wrote: >>> > >>> >> Yes, but you need to do a POST, not a GET: >>> >> >>> >> http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options >>> >> >>> >> put the following JSON in the body: >>> >> {"keys": ["key1", "key2", ...]} >>> >> >>> >> Marcello >>> >> >>> >> 2012/1/18 Alexandre Masselot : >>> >> > Hello, >>> >> > >>> >> > I'm using view with a simple map that extract a couple of values (= we >>> >> store >>> >> > millions of web page info in couchdb and I need to access rapidly = a >>> md5 >>> >> > field to know whether we should treat a crawled page or if we alre= ady >>> >> know >>> >> > it). >>> >> > >>> >> > It's fine to get the view output for one page >>> >> > http://127.0.0.1:5984/honbot/_design/projections/_view/md5?key=3D >>> >> > "http%253A%252F%252Fwww.gesunde-maenner.ch%252Fhtml%252F" >>> >> > >>> >> > >>> >> > For saving, we use bulk_docs to save doc per 1000 slices and that >>> goes >>> >> much >>> >> > faster. >>> >> > >>> >> > My question is: is it possible to make a view request list above, = but >>> >> with >>> >> > a list of key? >>> >> > Let's say >>> >> > "http%253A%252F%252Fwww.gesunde-maenner.ch%252Fhtml%252F" >>> >> > =C2=A0and "http%253A%252F%252Fwww.pipo.com" >>> >> > >>> >> > >>> >> > thanks for the help >>> >> > alex >>> >> > -- >>> >> > Alexandre Masselot >>> >> > >>> >> > http://alexandre-masselot.blogspot.com/ >>> >> >>> >> >>