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 6002A4CBE for ; Tue, 21 Jun 2011 14:30:18 +0000 (UTC) Received: (qmail 13678 invoked by uid 500); 21 Jun 2011 14:30:15 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 13640 invoked by uid 500); 21 Jun 2011 14:30:15 -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 13629 invoked by uid 99); 21 Jun 2011 14:30:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Jun 2011 14:30:15 +0000 X-ASF-Spam-Status: No, hits=1.9 required=5.0 tests=SPF_HELO_SOFTFAIL,SPF_SOFTFAIL X-Spam-Check-By: apache.org Received-SPF: softfail (athena.apache.org: transitioning domain of clement@challet.eu does not designate 88.191.97.33 as permitted sender) Received: from [88.191.97.33] (HELO challet.eu) (88.191.97.33) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Jun 2011 14:30:08 +0000 Received: from new-host-3.home (men75-1-87-90-29-239.dsl.sta.abo.bbox.fr [87.90.29.239]) by challet.eu (Postfix) with ESMTPA id A9D878581D6 for ; Tue, 21 Jun 2011 16:29:47 +0200 (CEST) Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Apple Message framework v1084) Subject: Re: rewrite rules for alphabetic browse From: Clement Hallet In-Reply-To: Date: Tue, 21 Jun 2011 16:29:45 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <9437EA4B-96D6-499E-81F5-C5A422D54066@challet.eu> References: To: user@couchdb.apache.org X-Mailer: Apple Mail (2.1084) Hello Gabriel, Why not making a key using only the first letter ?=20 function(doc) { if (doc.type && doc.name) { emit([doc.type, doc.name[0]); } } and querying it with that key =3D ["artist","a"] --=20 Cl=E9ment Le 21 juin 2011 =E0 16:18, Gabriel Farrell a =E9crit : > 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: >=20 > function(doc) { > if (doc.type && doc.name) { > emit([doc.type, doc.name]); > } > } >=20 > 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: >=20 > { > "from": "artists/a", > "to": "_list/artists/type_name", > "query": { > "startkey": ["artist", "a"], > "endkey": ["artist", "aZZZZZ"] > } > }, >=20 > 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: >=20 > { > "from": "artists/:startkey", > "to": "_list/artists/type_name", > "query": { > "startkey": ["artist", ":startkey"], > "endkey": ["artist", ":startkeyZZZZZ"] > } > }, >=20 > I can achieve something close by extending the URL to > http://example.com/artists/a/aZZZZZ and using the following rewrite: >=20 > { > "from": "artists/:startkey/:endkey", > "to": "_list/artists/type_name", > "query": { > "startkey": ["artist", ":startkey"], > "endkey": ["artist", ":endkey"] > } > }, >=20 > 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.