Return-Path: X-Original-To: apmail-couchdb-dev-archive@www.apache.org Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 59ED3CD9D for ; Wed, 16 May 2012 09:41:23 +0000 (UTC) Received: (qmail 78098 invoked by uid 500); 16 May 2012 09:41:22 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 77777 invoked by uid 500); 16 May 2012 09:41:21 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 77766 invoked by uid 99); 16 May 2012 09:41:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 May 2012 09:41:21 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lmatteis@gmail.com designates 74.125.83.52 as permitted sender) Received: from [74.125.83.52] (HELO mail-ee0-f52.google.com) (74.125.83.52) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 May 2012 09:41:14 +0000 Received: by eeke53 with SMTP id e53so137892eek.11 for ; Wed, 16 May 2012 02:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=BNe8FOM6ayEcgeHIuWB2Kod32EnChBbzccFQQgR1uYI=; b=qULYJMPfafhE1X8sNJAC5L2zws/JZC9P2opHFkCSK4cj8z13fYcUDqOh+ncSqW2cEU Tke4msvNl/ZTz+hFdLSWXE9aQ/TL9DzB3RcuJzpXuFDZ4gxYO1GojVJfFqSdcaWENe1X WmcylRcXZAU42vYCKL82jr7e2h1hg2pxgY0p0GG90g3e7Z/D/JmgFYzhvruDyEDgDyBF alzrU836jeD3f0fRc3YRQpG09NqNXFKUR5GlRX/TnMqKODNdgSWu6Yvn4xEh1Vfsj6RD EcxJXwju3uf4rmioEfL9lNfTdB2rStW7koyi3fYZAofdc5verxww584XFfPVO4H/lOeh VSmA== MIME-Version: 1.0 Received: by 10.213.108.195 with SMTP id g3mr1250027ebp.11.1337161253866; Wed, 16 May 2012 02:40:53 -0700 (PDT) Received: by 10.14.188.8 with HTTP; Wed, 16 May 2012 02:40:53 -0700 (PDT) Date: Wed, 16 May 2012 11:40:53 +0200 Message-ID: Subject: Hierarchical comments Hacker News style From: Luca Matteis To: dev@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 I'm trying to implement a basic way of displaying comments in the way that Hacker News provides, using CouchDB. Not only ordered hierarchically, but also, each level of the tree should be ordered by a "points" variable. If you're familiar with sites such as Hacker News or Reddit you know that each level of the comment tree is ordered by the amount of points and also the date they were posted - however, for sake of simplicity I'll just talk about a "points" variable. The idea is that I want a view to return it in the order I except, and not make many Ajax calls for example, to retrieve them and make them look like they're ordered correctly. This is what I got so far: Each document is a "comment". Each comment has a property `path` which is an ordered list containing all its parents. So for example, imagine I have 4 comments (with _id `1`, `2`, `3` and `4`). Comment `2` is children of `1`, comment `3` is children of `2`, and comment `4` is also children of `1`. This is what the data would look like: { _id: 1, path: ["1"] }, { _id: 2, path: ["1", "2"] }, { _id: 3, path: ["1", "2", "3"] } { _id: 4, path: ["1", "4"] } This works quite well for the hierarchy. A simple `view` will already return things ordered with each comment underneath the correct one. The issue comes when I want to order each "level" of the tree independently. So for example documents `2` and `4` belong to the same branch, but are ordered, on that level, by their ID. Instead I want them ordered based on a "points" variable that I want to add to the path - but can't seem to understand where I could be adding this variable for it to work the way I want it. Is there a way to do this? Consider that the "points" variable will change in time. Thank you, Luca