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 735E647F7 for ; Tue, 21 Jun 2011 15:29:23 +0000 (UTC) Received: (qmail 65727 invoked by uid 500); 21 Jun 2011 15:29:21 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 65639 invoked by uid 500); 21 Jun 2011 15:29:21 -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 65631 invoked by uid 99); 21 Jun 2011 15:29:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Jun 2011 15:29:21 +0000 X-ASF-Spam-Status: No, hits=4.1 required=5.0 tests=HTML_MESSAGE,SPF_HELO_SOFTFAIL,SPF_SOFTFAIL X-Spam-Check-By: apache.org Received-SPF: softfail (nike.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 15:29:13 +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 71A0C8581D6 for ; Tue, 21 Jun 2011 17:28:51 +0200 (CEST) From: Clement Hallet Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: multipart/alternative; boundary=Apple-Mail-1--349550888 Subject: Re: rewrite rules for alphabetic browse Date: Tue, 21 Jun 2011 17:28:50 +0200 In-Reply-To: To: user@couchdb.apache.org References: <9437EA4B-96D6-499E-81F5-C5A422D54066@challet.eu> Message-Id: X-Mailer: Apple Mail (2.1084) X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail-1--349550888 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=iso-8859-1 Glad to hear it helped. I can't tell why it's still sorted, but to be sure it remains like that = i would do : View function(doc) { if (doc.type && doc.name) { var lowerCased =3D doc.name.toLowerCase(); var firstLetter =3D lowerCased.toLowerCase()[0]; emit([doc.type, firstLetter, lowerCased], doc.name); } } Rewrite { "from": "artists/:key", "to": "_list/artists/type_name", "query": { "startkey": ["artist", ":key"], "endkey": ["artist", ":key", {}] } } So the 3rd element of the key is not used as a filter but more as a = sorting field. --=20 Cl=E9ment Le 21 juin 2011 =E0 17:17, Gabriel Farrell a =E9crit : > On Tue, Jun 21, 2011 at 10:29 AM, Clement Hallet = wrote: >> Hello Gabriel, >>=20 >> Why not making a key using only the first letter ? >>=20 >> function(doc) { >> if (doc.type && doc.name) { >> emit([doc.type, doc.name[0]); >> } >> } >>=20 >>=20 >> and querying it with that key =3D ["artist","a"] >=20 > Interesting idea. If I only use the first letter (and lowercase it as > well to catch names starting with "A"), then I can get the URLs I > want. I thought I would lose the sorting within each letter, but > they're still sorted! I don't understand why that is, but it's a nice > surprise. >=20 > My view now looks like this: >=20 > function(doc) { > if (doc.type && doc.name) { > var firstLetter =3D doc.name.toLowerCase()[0]; > emit([doc.type, firstLetter], doc.name); > } > } >=20 > And the rewrite is simplified to this: >=20 > { > "from": "artists/:key", > "to": "_list/artists/type_name", > "query": { > "key": ["artist", ":key"] > } > }, >=20 > Thanks! >=20 >> -- >> Cl=E9ment >>=20 >> Le 21 juin 2011 =E0 16:18, Gabriel Farrell a =E9crit : >>=20 >>> 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. >>=20 >>=20 --Apple-Mail-1--349550888--