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 A0C1E100F3 for ; Thu, 13 Feb 2014 02:27:32 +0000 (UTC) Received: (qmail 40529 invoked by uid 500); 13 Feb 2014 02:27:31 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 40418 invoked by uid 500); 13 Feb 2014 02:27:30 -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 40410 invoked by uid 99); 13 Feb 2014 02:27:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Feb 2014 02:27:30 +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 X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of kevin.r.coombes@gmail.com designates 209.85.214.182 as permitted sender) Received: from [209.85.214.182] (HELO mail-ob0-f182.google.com) (209.85.214.182) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Feb 2014 02:27:23 +0000 Received: by mail-ob0-f182.google.com with SMTP id wm4so11550243obc.13 for ; Wed, 12 Feb 2014 18:27:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=7Ub9Vje6L9y/xuyAmVyavgO99pWK2CF71DOCZmSv++A=; b=eGpLOhqelbmEJXWus/jxnUMGdzZLu5LPDYeZZUqi0QeqU8fzcfeYfPOah6QOjqLg03 WtyXDv+tO+1MaH5rMDgmHT0RlskrRhq0vK3aaa4VCINemH9Api1raEqXUwhyyjpVO5gV sCydxc9QCQoW80bTUjgT2jo0a7OpXt7Iwyco0/GjbPpQSox6MiMCdrbk1eWmnjVhAgZd AduJ8azyOWghLLB2O29AG5WbhLoP1FW+5jYrjC6bzUvuCkkiYbKWCzB0U5hN+nk2B0DR OlIPHVGE4+403h9pMhLJW4dElwgwaBQPEWPqutsLFjQHYUslSnfuovRTb6QcHiqDhHS+ pEuw== X-Received: by 10.60.54.138 with SMTP id j10mr42389oep.51.1392258423025; Wed, 12 Feb 2014 18:27:03 -0800 (PST) Received: from [192.168.5.127] (cpe-174-101-43-190.columbus.res.rr.com. [174.101.43.190]) by mx.google.com with ESMTPSA id su13sm2483136oeb.1.2014.02.12.18.27.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Feb 2014 18:27:02 -0800 (PST) Message-ID: <52FC2D73.10205@gmail.com> Date: Wed, 12 Feb 2014 21:26:59 -0500 From: Kevin Coombes User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: user@couchdb.apache.org Subject: Re: Matching docs which values ending with a specific string References: <131147B1-EAB4-4FFB-A6BF-950877CAC74B@mac.com> <86A8E193-C6CF-41F3-9570-1A87A2AE4A9D@mac.com> In-Reply-To: <86A8E193-C6CF-41F3-9570-1A87A2AE4A9D@mac.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Maybe you should completely describe the structure you want. { "_id": "12345", "location": { "state": "California", "city": "Florence" } } Because (1) you can define multiple views that emit any reasonable combination of city and state in any order you might want to query and (2) some day you might want to add an entry like { "_id": "98765", "location": { "country": "Italy", "province": "Tuscany", "city": "Florence" } } On 2/12/2014 6:10 PM, Tito Ciuro wrote: > Hello, > > Ah! I see. Well, what if I stored the path in an array instead?: > > { > "_id" : "12345", > "location" : [,] > } > > If I emit (doc.location,doc._id), would I be able to write a query that matches the second element of the doc.location array? > > Thanks again for all the help, > > -- Tito > > On Feb 12, 2014, at 2:48 PM, Jason Winshell wrote: > >> AFAIK, you're describing a CouchDB limitation. You may need to use CouchDB-Lucene to get your answers. CouchDB views match keys in an index. You can match a prefix, but not a tail. And you can't deal with case sensitivity. You might be able to generate a view in which you reverse the chars of your location and then match in reverse order (i.e. turning the problem into a prefix). I think trying to coerce Couch to do that is nutty. Just use CouchDB-Lucene. >> >> On Feb 12, 2014, at 2:35 PM, Tito Ciuro wrote: >> >>> Hello, >>> >>> I have a database with documents with the following format: >>> >>> { >>> "_id" : "12345", >>> "location" : . >>> } >>> >>> I have values like: >>> >>> California.San Francisco >>> California.Los Angeles >>> Florida.Miami >>> ... >>> ... >>> >>> What I'm trying to do is to match documents that "end with" a particular string. Say I want to match all states where the town 'Anytown' exists: >>> >>> California.Anytown >>> Florida.Anytown >>> Texas.Anytown >>> >>> If I use the following query: >>> >>> curl http://127.0.0.1:5984/example/_design/test/_view/ends-with-city?key=%22California.Anytown%22 >>> >>> It works and returns one document (as expected), but I cannot seem to make it work when I look for an "end with" string. I have seen examples where %007F is used to match "begins with". When I use it, I get a {"error":"bad_request","reason":"invalid_json"} message. So I'm not sure how to proceed. >>> >>> Any ideas? Thanks! >>> >>> -- Tito