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 4FFA8B845 for ; Wed, 18 Jan 2012 12:45:42 +0000 (UTC) Received: (qmail 60720 invoked by uid 500); 18 Jan 2012 12:45:40 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 60634 invoked by uid 500); 18 Jan 2012 12:45:39 -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 60626 invoked by uid 99); 18 Jan 2012 12:45:39 -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 12:45:39 +0000 X-ASF-Spam-Status: No, hits=0.3 required=5.0 tests=FREEMAIL_REPLY,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 rogutes@googlemail.com designates 74.125.83.52 as permitted sender) Received: from [74.125.83.52] (HELO mail-ee0-f52.google.com) (74.125.83.52) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jan 2012 12:45:34 +0000 Received: by eekc50 with SMTP id c50so1105294eek.11 for ; Wed, 18 Jan 2012 04:45:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-type:content-disposition :content-transfer-encoding:in-reply-to; bh=h/ca0RD/ZaXu9t6m3wSo0qIxbb3D9VmMFQ4wJY/o41w=; b=Z2MibzaRalQ39B0ADjj9zUPoGcYJ7k/7PCYWGz37wxHzcHHNw+p+qQl55k+kfJE4dL hELNi+rmt6++SMVx3c07d62I+xknxwO45lE7aEAYV2n0qbsHOt5p5Vj2pOH9MrsJADEn kdxuBCv6TEAytc4p6Od+lPjPT6Vx3lm9guwkE= Received: by 10.14.16.129 with SMTP id h1mr132979eeh.46.1326890713011; Wed, 18 Jan 2012 04:45:13 -0800 (PST) Received: from urvas (78-62-122-124.static.zebra.lt. [78.62.122.124]) by mx.google.com with ESMTPS id x4sm4473717eeb.4.2012.01.18.04.45.10 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 18 Jan 2012 04:45:11 -0800 (PST) Date: Wed, 18 Jan 2012 14:45:08 +0200 From: =?utf-8?Q?Rogut=C4=97s?= Sparnuotos To: user@couchdb.apache.org Subject: Re: get view with a list of keys Message-ID: <20120118124508.GB7244@urvas> Mail-Followup-To: user@couchdb.apache.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: This parameter works fine with integer keys in Firefox: ?keys=[4739, 4823] But you would really have to encode it to this: ?keys=%5B4739%2C+4823%5D All using GET. Marcello Nuccio (2012-01-18 12:56): > 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[]=key` > 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 = $.test || {}; > >> $.extend($.test, { > >>         fetch_data_startendkey: function(options) { > >>             options = options || {}; > >>             $.ajax({ > >>                 type     : "GET", > >>                 url      : " > >> http://my_domain.domain_type:5984/mydatabase/_design/design_name/_list/list_function_name/view_function_name?startkey= > >> "+options.startkey+"&endkey="+options.endkey+"&limit="+options.limit+"&skip="+options.skip+"&descending="+options.descending, > >>                 dataType : "json", > >>                 async    : false, > >>                 global   : false, > >>                 data     : {}, > >>                 error    : options.error, > >>                 success  : options.success > >>             }); > >>         } > >> }); > >> > >> 2. jQuery callback: > >> > >> $.test.fetch_data_startendkey({ > >>             startkey: "my_string", > >>             endkey: "my_other_string", > >>             limit: mylimit, > >>             skip: myoffset, > >>             descending: my_descending_boolean, > >>             success : function(data, textStatus, headers) { > >>                 /* do something with the predefined errors and the > >> returned data if no predefined error returned */ > >>             }, > >>             error : function(code, error, reason) { > >>                 /* do something with the error */ > >>             } > >>         }); > >> > >> 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 the > >> 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 that. > >> 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: > >>>    JSON.stringify({ keys: [ "key1", "key2" ] }); > >>> > >>> Can you give some more information? > >>> > >>> Thanks, > >>>  Marcello > >>> > >>> 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=["key1",...], you get > >>> > &key[]=["key1"]&key[]=... To solve the problem, for example, I transform > >>> > the full query in a string and I attach it manually to the web address. > >>> 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 double > >>> > 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 already > >>> >> 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= > >>> >> > "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" > >>> >> >  and "http%253A%252F%252Fwww.pipo.com" > >>> >> > > >>> >> > > >>> >> > thanks for the help > >>> >> > alex > >>> >> > -- > >>> >> > Alexandre Masselot > >>> >> > > >>> >> > http://alexandre-masselot.blogspot.com/ > >>> >> > >>> > >> > >> -- -- Rogutės Sparnuotos