Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 6330 invoked from network); 15 Apr 2010 12:32:35 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 15 Apr 2010 12:32:35 -0000 Received: (qmail 83428 invoked by uid 500); 15 Apr 2010 12:32:33 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 83370 invoked by uid 500); 15 Apr 2010 12:32:33 -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 83360 invoked by uid 99); 15 Apr 2010 12:32:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Apr 2010 12:32:32 +0000 X-ASF-Spam-Status: No, hits=-0.2 required=10.0 tests=AWL,RCVD_IN_DNSWL_NONE X-Spam-Check-By: apache.org Received-SPF: unknown (athena.apache.org: error in processing during lookup of magnus@magnusottosson.se) Received: from [72.14.220.153] (HELO fg-out-1718.google.com) (72.14.220.153) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Apr 2010 12:32:27 +0000 Received: by fg-out-1718.google.com with SMTP id 22so606114fge.5 for ; Thu, 15 Apr 2010 05:32:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.112.148 with HTTP; Thu, 15 Apr 2010 05:32:04 -0700 (PDT) In-Reply-To: References: <227A0267-AA3C-4E4A-B7BF-6E3DDBD19AED@googlemail.com> Date: Thu, 15 Apr 2010 14:32:04 +0200 Received: by 10.223.92.144 with SMTP id r16mr3970790fam.62.1271334724547; Thu, 15 Apr 2010 05:32:04 -0700 (PDT) Message-ID: Subject: Re: Search for city by name, order by population From: Magnus Ottosson To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 The problem with sorting on the client side is that I have a lot of entities! Say that I want to fetch all cities starting with the name "new" it could potentially be thousands and the performance would not be that great. I know it's a hack and that it might not be suitable but I found that if I create the key like I previous mentioned but add the population to the and of the key I can search for entities like this: ?startkey="new\u9999"&endkey="new0"&descending=true&limit=10 This will sort the cities correctly and I do not need to use the reduce function. I will also look at the lucene version but I'm in a hosted environment where I have no control over the existing software... Magnus On Wed, Apr 14, 2010 at 12:11 AM, Jon Gretar Borgthorsson wrote: > To be honest then in this exact case as you describe it I would skip sorting > it in CouchDB and sort it on the client side. It's a very simple solution > that can probably be done in a single line of code. I might even check and > see if the autocomplete plugin you use simply offers to do that for you. > > When in doubt always do what has the least amount of code my great > grandfather used to tell me. ;) > > On Mon, Apr 12, 2010 at 8:38 AM, Magnus Ottosson > wrote: > >> Oh, I should have made that more clear. I will use this to >> autocomplete a searchbox. So when the user start typing I will search >> for the cities that matches the string. The user might type "new". >> Then I want to fetch the 10 largest cities based on population where >> the name starts with "new". >> >> If I just wanted to search for the name I could have created an index >> with the name as the key and searched like this: >> startkey="new"&endkey="new\u9999" and this would have matched all the >> cities with the name string with new. Right? >> >> I want to sort this result by population in descending order so I can >> fetch the 10 largest cities matching the input. >> >> Magnus >> >> >> >> On Mon, Apr 12, 2010 at 10:31 AM, Sebastian Cohnen >> wrote: >> > hmm, I do not quite follow... isn't the name of the city unique? what do >> you mean by *searching* for a city? >> > >> > On 12.04.2010, at 10:25, Magnus Ottosson wrote: >> > >> >> Hi, >> >> >> >> I have a database with the names and population of cities (about 7 >> >> million entities). Is it possible, with couchdb, to create a key that >> >> includes both cityname and population where I can search for a name >> >> and get the matching results ordered by the population? >> >> >> >> I tried to create a key like [population, name] and search like this >> >> ?startkey=[0, "name"]&endkey=[10000000, "name]&limit=10 but it does >> >> not work like the way I hoped. >> >> >> >> Any ideas? >> >> >> >> Magnus >> > >> > >> >