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 C9FF69221 for ; Wed, 11 Apr 2012 20:46:59 +0000 (UTC) Received: (qmail 76905 invoked by uid 500); 11 Apr 2012 20:46:58 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 76864 invoked by uid 500); 11 Apr 2012 20:46:58 -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 76856 invoked by uid 99); 11 Apr 2012 20:46:58 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Apr 2012 20:46:58 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW X-Spam-Check-By: apache.org Received-SPF: unknown ~alla (athena.apache.org: encountered unrecognized mechanism during SPF processing of domain of jdreux@justlexit.com) Received: from [209.85.210.180] (HELO mail-iy0-f180.google.com) (209.85.210.180) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Apr 2012 20:46:51 +0000 Received: by iage36 with SMTP id e36so2425782iag.11 for ; Wed, 11 Apr 2012 13:46:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:content-type:x-gm-message-state; bh=ugxAQqvDhdesEAByQJ3rWMcdW+ycL9WkdyqTCVudssQ=; b=Q4W8l1R1Jz/w2aF0eficEbVTQuhj1pt3H1kw0NuOwEQTyiQCr8eVBNkDJDE2g30lV7 72xtlnXKOU8PEpdVFj07YcWVfiqZ8npUbhiRLmOdapq3fAR5f6bLxhHS2Q/S+YMXsgBn OHiULjpD3YuLpvljavGk0RbBiFDWgz9800XzbN198eSS95oK7miyQb4PKcpvJUXk0f8Z vINyLipXg4LlJoGgtGr2++IhurvKWtOal0ukFXQWXHx4wdA5r+sQtk3Ntvj8MjXQMwfI GhZke7WZuin/gGTwkhePt5Ot8oRSNK0rjFC4HAgg/CKTPCo5gkFVSHnXXP6vrGV2n9Ri JNWQ== MIME-Version: 1.0 Received: by 10.43.68.132 with SMTP id xy4mr10575974icb.54.1334177190833; Wed, 11 Apr 2012 13:46:30 -0700 (PDT) Received: by 10.42.176.71 with HTTP; Wed, 11 Apr 2012 13:46:30 -0700 (PDT) X-Originating-IP: [173.248.249.66] In-Reply-To: References: <4A256A62-EC51-4FBB-98B3-1638BBEA674D@utt.fr> Date: Wed, 11 Apr 2012 16:46:30 -0400 Message-ID: Subject: Re: View cache invalidation From: Julien Dreux To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=bcaec51b1b6786ede804bd6d5573 X-Gm-Message-State: ALoCoQlJ/TYNLbcvOsVkxDwlJujqkmfIAEBqzk8JbP77MghuSkMp3nCMLMRWpGVKJKolDrp0G91C X-Virus-Checked: Checked by ClamAV on apache.org --bcaec51b1b6786ede804bd6d5573 Content-Type: text/plain; charset=ISO-8859-1 Matthieu, Robert, These answers already help a lot, however what we are trying to do is not to retrieve the list of opening hours for a given business for today, but rather retrieve the list of businesses that are open at a given time (e.g. Wednesday at 2:05 PM). Even though I have an idea on how this could be done I would like to know your take on it to make sure we are on the right track. Thanks, * * *JULIEN DREUX* jdreux@justlexit.com 514 812-8084 www.justlexit.com On Wed, Apr 11, 2012 at 4:11 PM, Matthieu Rakotojaona < matthieu.rakotojaona@gmail.com> wrote: > On Wed, Apr 11, 2012 at 9:24 PM, Julien Dreux > wrote: > > function(doc) { > > if(doc.businessHours) { > > var daysArr = new Array('s','m','t','w','h','f','a'); > > var day = daysArr[new Date().getDay()]; > > emit(parseInt(doc.businessHours[day][0].indexOf('0') == 0 ? > > doc.businessHours[day][0].substring(1) : doc.businessHours[day][0]), > doc)}; > > } > > > > Thank you for your help. > > * > > * > > *JULIEN DREUX* > > jdreux@justlexit.com > > 514 812-8084 > > www.justlexit.com > > > > As said before, views (both map and reduce) MUST be absolutely > context-independent. There is only ONE thing a map function can depend > on : the document being processed. It cannot even rely on other > documents, or the version of your couchdb, or whatever. If you need > this information, include it in your doc. > > I get from your view definition that you would like to ask your > database for the opening hours of your businesses for today, right ? I > will suppose you do so. A correct way to implement way would be like > that : > > - for each day in the 'businessHours' array of the doc, emit a pair. > The key should be the day from the array, the value would be the > opening hour as processed in your emit (removing the leading 0 if it > exists) > - You would then have multiple key/value pairs by document. > - At query time, use 'key=' as an > argument, like 'key="s"'. > - Bonus : do not emit the doc in a map. If you need it, you can add > 'include_docs=true' to the arguments at querying time, and you will be > able to access it along the data you emitted when defining the view. > This will prevent you from storing the doc twice. > > Proposed (untested) implementation : > > function(doc){ > var daysArr = new Array('s','m','t','w','h','f','a'); > var i=0; > for (i = 0; i < daysArr.length; i++){ > var day = daysArr[i]; > var openingHour = doc.businessHours[day][0].indexOf('0') == 0 ? > doc.businessHours[day][0].substring(1) : doc.businessHours[day][0]); > emit(day, openingHour); > } > } > > Query would look like this for today (wednesday) : > > GET /path/to/view?key="w"&include_docs=true > > > > -- > Matthieu RAKOTOJAONA > --bcaec51b1b6786ede804bd6d5573--