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 <[email protected]> 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 > <[email protected]>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 >> <[email protected]> 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 >> > >> > >> >
