couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clement Hallet <clem...@challet.eu>
Subject Re: rewrite rules for alphabetic browse
Date Tue, 21 Jun 2011 14:29:45 GMT
Hello Gabriel,

Why not making a key using only the first letter ? 

 function(doc) {
   if (doc.type && doc.name) {
     emit([doc.type, doc.name[0]);
   }
 }


and querying it with that key = ["artist","a"]


-- 
Clément

Le 21 juin 2011 à 16:18, Gabriel Farrell a écrit :

> I'm putting together a site where I have artists and works of art. I
> would like to browse those artists and works alphabetically, with URLs
> like http://example.com/artists/a and http://example.com/works/b. I
> have a view called type_name:
> 
>  function(doc) {
>    if (doc.type && doc.name) {
>      emit([doc.type, doc.name]);
>    }
>  }
> 
> My "artists" list renders the results from that view in a template. I
> can get the first page of artists with a rewrite like this:
> 
>  {
>    "from": "artists/a",
>    "to": "_list/artists/type_name",
>    "query": {
>      "startkey": ["artist", "a"],
>      "endkey": ["artist", "aZZZZZ"]
>    }
>  },
> 
> How would I generalize this for all letters of the alphabet? I want to
> do something like the following, but the last ":startkey" isn't
> substituted:
> 
>  {
>    "from": "artists/:startkey",
>    "to": "_list/artists/type_name",
>    "query": {
>      "startkey": ["artist", ":startkey"],
>      "endkey": ["artist", ":startkeyZZZZZ"]
>    }
>  },
> 
> I can achieve something close by extending the URL to
> http://example.com/artists/a/aZZZZZ and using the following rewrite:
> 
>  {
>    "from": "artists/:startkey/:endkey",
>    "to": "_list/artists/type_name",
>    "query": {
>      "startkey": ["artist", ":startkey"],
>      "endkey": ["artist", ":endkey"]
>    }
>  },
> 
> The URL is uglier but it works. Is there any way to make the shorter
> URL work? Frankly, I think some of my trouble is that, coming from
> other web frameworks, I'm not used to my URLs being constrained in
> this way. I want to be able to grab the request path, munge it all
> over with JavaScript, then send it on to my lists, shows, views, etc.


Mime
View raw message