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 9E22296FA for ; Wed, 7 Mar 2012 08:58:56 +0000 (UTC) Received: (qmail 46032 invoked by uid 500); 7 Mar 2012 08:58:55 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 45661 invoked by uid 500); 7 Mar 2012 08:58:49 -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 45628 invoked by uid 99); 7 Mar 2012 08:58:48 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Mar 2012 08:58:48 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of simonmetson@googlemail.com designates 74.125.82.180 as permitted sender) Received: from [74.125.82.180] (HELO mail-we0-f180.google.com) (74.125.82.180) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Mar 2012 08:58:41 +0000 Received: by werf3 with SMTP id f3so4670380wer.11 for ; Wed, 07 Mar 2012 00:58:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=references:in-reply-to:mime-version:content-transfer-encoding :content-type:message-id:cc:x-mailer:from:subject:date:to; bh=uWbK5N19VvtAQT+6gM5oExzhH3uEoYBWGvht2OVZOE0=; b=CgBaez9/CTAFyB0RgSYgLTCx862Jp6zFDHRUHK93KCz3T2/ncdCsV6ROBEylkSCxoD rwbmJaZdPucb4lfVjx5Bc3wXjkqpRLnEwHHuYdVh03fiMGp08tvUGeKmxehfe7MVmpel dw3dUlvVmDl4zLRCv+yuChipbnUZaMoJ2Fk/P/1thBOK0qPG4rooqS/rzMzhlu0dOvBn x2FRxa9edR82m+8b5R97pnZjpy+nr/kU2sKzYznjePp0NE0PJA/avYO4VluA+M105Oic 0e9eI0DarBCsO5u0NvncBZSAmFJXTqZMnxdn2GXK6WlC/1N1n+9AG2Iq2/MqlcDODREN eXZQ== Received: by 10.180.95.1 with SMTP id dg1mr2180201wib.21.1331110699478; Wed, 07 Mar 2012 00:58:19 -0800 (PST) Received: from [192.168.1.69] (93-97-111-13.zone5.bethere.co.uk. [93.97.111.13]) by mx.google.com with ESMTPS id cc3sm92147831wib.7.2012.03.07.00.58.17 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 07 Mar 2012 00:58:18 -0800 (PST) References: <3D8B736F-2D61-4CCC-86EB-78F7DFB20DBD@sri.com> In-Reply-To: <3D8B736F-2D61-4CCC-86EB-78F7DFB20DBD@sri.com> Mime-Version: 1.0 (1.0) Content-Transfer-Encoding: 7bit Content-Type: multipart/alternative; boundary=Apple-Mail-86B02D77-42DD-4E15-9DAF-4E22555D0DA4 Message-Id: <4009686D-D3C2-4AD2-B047-9B0EBC44C0DD@googlemail.com> Cc: "" X-Mailer: iPad Mail (9A405) From: Simon Metson Subject: Re: starkey with multiple values not working as expected Date: Wed, 7 Mar 2012 09:01:10 +0000 To: "user@couchdb.apache.org" X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail-86B02D77-42DD-4E15-9DAF-4E22555D0DA4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii I wrote a bloglet to illustrate this a while back, it's incomplete (I'd like= to inline some code examples and use a lucene search to get a 2d query) but= might help illustrate how view slicing works: http://drsm79.cloudant.com/vi= ew-slicing/_design/view-slicing/index.html On 1 Mar 2012, at 00:25, Jim Klo wrote: > actually, it's responding exactly as expected. >=20 > you can't think of complex keys as a boolean "AND", but as a single value.= >=20 > so...=20 >=20 >> ["2012-01-01T02:07:50.387+0000","97ee813bfe4dbbf80a48b018b20a08bb"] >=20 > is actually less than ALL your values because of CouchDB's collation rules= . >=20 > To explain this to others, I use the idea of turning the key into a senten= ce.... typically i think of it as you have the last element grouped by the t= he other elements from left to right. >=20 > So you have "restaurantids grouped by timestamp" as your key, which means f= or any given timestamp as a startkey/endkey, the last item in the key will b= e a restuarantid... if you try rounding your timestamp to the nearest hour i= n your example you'll see what I mean using your data...=20 >=20 > if you want to look up by restaurantid, order your keys from left to right= ... [restaurantid, timestamp]... which will then order your view first by re= staurantid, then by timestamp... which gives you "timestamps grouped by rest= aurantid" >=20 > you'd then use >=20 >> restaurant_orders_after_date?startkey=3D["97ee813bfe4dbbf80a48b018b20a08b= b","2012-01-01T02:07:50.387+0000"]&endkey=3D["97ee813bfe4dbbf80a48b018b20a08= bb",{}] >=20 >=20 > - Jim >=20 > Jim Klo > Senior Software Engineer > Center for Software Engineering > SRI International >=20 > On Feb 29, 2012, at 3:45 PM, Mathieu Castonguay wrote: >=20 >> Here is the view: >>=20 >> "restaurant_orders_after_date": { >> "map": "function(doc) { if(doc.restaurantId && >> doc.timeOfLatestStatusChange && doc.status && (doc.status =3D=3D 'ACCEPTE= D' || >> doc.status =3D=3D 'REJECTED')) { >> emit([doc.timeOfLatestStatusChange,doc.restaurantId], doc._id)}}" >>=20 >> Execution of the view: >>=20 >> restaurant_orders_after_date?startkey=3D["2012-01-01T02:07:50.387+0000","= 97ee813bfe4dbbf80a48b018b20a08bb"]&endkey=3D[{},"97ee813bfe4dbbf80a48b018b20= a08bb"] >>=20 >> {"id":"6bb4423653c6d9138524c110cf0047fb","key":["2012-01-03T14:00:52.542+= 0000","f98ba9a518650a6c15c566fc6f03dc8d"],"value":"6bb4423653c6d9138524c110c= f0047fb"}, >> {"id":"6bb4423653c6d9138524c110cf007276","key":["2012-01-03T17:34:49.565+= 0000","97ee813bfe4dbbf80a48b018b20a08bb"],"value":"6bb4423653c6d9138524c110c= f007276"}, >> {"id":"6bb4423653c6d9138524c110cf006d26","key":["2012-01-03T17:36:31.222+= 0000","97ee813bfe4dbbf80a48b018b20a08bb"],"value":"6bb4423653c6d9138524c110c= f006d26"}, >> {"id":"6bb4423653c6d9138524c110cf007c76","key":["2012-01-03T17:38:45.485+= 0000","97ee813bfe4dbbf80a48b018b20a08bb"],"value":"6bb4423653c6d9138524c110c= f007c76"}, >> {"id":"6bb4423653c6d9138524c110cf006119","key":["2012-01-03T17:47:51.637+= 0000","29b384e85adcdf5b2085dadba5018d03"],"value":"6bb4423653c6d9138524c110c= f006119"}, >> {"id":"6bb4423653c6d9138524c110cf005e51","key":["2012-01-03T18:00:35.185+= 0000","29b384e85adcdf5b2085dadba5018d03"],"value":"6bb4423653c6d9138524c110c= f005e51"} >>=20 >> It seems to completly ignore the second value which is the id of the >> restaurant. I want all orders who's timeOfLatestStatusChange is greater >> than the current time (in this case "2012-01-01T02:07:50.387+0000") and >> who's restaurant id is a certain value(in this case >> "97ee813bfe4dbbf80a48b018b20a08bb"). >>=20 >> Can anyone explain to me why the second parameter seems ignored, I can me= an >> I can put "donkey" and it still does the same thing. >>=20 >> Thank you, >>=20 >> Matt >=20 --Apple-Mail-86B02D77-42DD-4E15-9DAF-4E22555D0DA4--