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 2C8C5E536 for ; Tue, 5 Feb 2013 20:07:10 +0000 (UTC) Received: (qmail 29598 invoked by uid 500); 5 Feb 2013 20:07:08 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 29472 invoked by uid 500); 5 Feb 2013 20:07:08 -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 29464 invoked by uid 99); 5 Feb 2013 20:07:08 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Feb 2013 20:07:08 +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 koeglstefan@gmail.com designates 209.85.219.46 as permitted sender) Received: from [209.85.219.46] (HELO mail-oa0-f46.google.com) (209.85.219.46) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Feb 2013 20:07:00 +0000 Received: by mail-oa0-f46.google.com with SMTP id k1so667874oag.33 for ; Tue, 05 Feb 2013 12:06:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=3iXoP7nCi9o09J35QexA1k87jVBB4sxn4Co+DCLh8lg=; b=Op6k1qqbOMJkLD/GxQiGr7MasZFV9c1mvBLSiS6iBkD/C1rTsfkd2/m7io+38H+2XV ZBt78WNMbyz4kDcOdWlx543IGlTPQLGdC4XD6fnIFmXzeRNxJZnvcgDp451/9vYJouJJ zCMLLLEujg5KP+Wy0AmcejrvoUWZtMaBHdl+l7fhhCNdYjXiJvyxUSJjRrx2KukKxL25 THKvmoXkRNsiBu73B4mUhbrDKrGETAsqIqkfYDNtYD1qeAdmMTZnxiL1tObdq/4fhw6n N1wJfVuVRg/ww3b/OdALPdIlJZoAucvIRU0cKpBIKHuO8POsU0xEZEteTlY5cRDrybHU Ni6w== MIME-Version: 1.0 X-Received: by 10.60.4.165 with SMTP id l5mr20883342oel.84.1360094799527; Tue, 05 Feb 2013 12:06:39 -0800 (PST) Received: by 10.76.4.229 with HTTP; Tue, 5 Feb 2013 12:06:39 -0800 (PST) In-Reply-To: References: <097C0DAA-FF04-4EC7-905C-22310DA33EC1@gmail.com> Date: Tue, 5 Feb 2013 21:06:39 +0100 Message-ID: Subject: Re: tinkering with limits while replicating From: =?ISO-8859-1?Q?Stefan_K=F6gl?= To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=e89a8ff1c2e862fe0304d4ffbfc4 X-Virus-Checked: Checked by ClamAV on apache.org --e89a8ff1c2e862fe0304d4ffbfc4 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Feb 5, 2013 at 8:06 PM, Tibor Gemes wrote: > A simle example which filters by type: > > fun({Doc}, {Req}) -> > DocType = couch_util:get_value(<<"type">>, Doc), > case DocType of > undefined -> false; > <<"mytype">> -> true; > _ -> false > end > end. > > > This is another example. A bit more complicated. This receives a values > query parameter (comma separated). The filter lets through any design docs, > any _deleted docs, and the mytype doc only if its value propery is > contained in the query parameter: > > fun({Doc}, {Req}) -> > DocId = couch_util:get_value(<<"_id">>, Doc), > DocType = couch_util:get_value(<<"type">>, Doc), > DocValue = couch_util:get_value(<<"value">>, Doc), > DocDeleted = couch_util:get_value(<<"_deleted">>, Doc), > > {Query} = couch_util:get_value(<<"query">>,Req, {[]}), > ValuesParam = couch_util:get_value(<<"values">>,Query), > Values = binary:split(ValuesParam, <<",">>, [global]), > case {DocId, DocDeleted} of > {<<"_design/", _/binary>>, _} -> true; > {_, true} -> true; > _ -> > case DocType of > undefined -> false; > <<"mytype">> -> lists:any(fun(E) -> E =:= DocValue > end, Values); > _ -> false > end > end > end. > > Those might be suboptimal but works perfectly for me. > Thanks for sharing. I've added them as examples to the wiki with links to your mail http://wiki.apache.org/couchdb/EnableErlangViews -- Stefan --e89a8ff1c2e862fe0304d4ffbfc4--