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 698F6CE7D for ; Wed, 16 May 2012 10:11:54 +0000 (UTC) Received: (qmail 78052 invoked by uid 500); 16 May 2012 10:11:53 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 77471 invoked by uid 500); 16 May 2012 10:11:47 -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 77431 invoked by uid 99); 16 May 2012 10:11:46 -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 10:11:46 +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 209.85.215.180 as permitted sender) Received: from [209.85.215.180] (HELO mail-ey0-f180.google.com) (209.85.215.180) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 May 2012 10:11:38 +0000 Received: by eaai12 with SMTP id i12so142197eaa.11 for ; Wed, 16 May 2012 03:11:18 -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=TV0gKNdl3iIuF8yT3wt41ccakX64Gta6JOrxaADEbPU=; b=qviq5ouQy/WvPOHXRQG06NsGG2/I7gjzDLNSpTKNcyIf6g+0+t0X6T+HBa9KVZnnsU 1oDbiRJ+30+QsXqKxDjw2bMSI/h21yWNKe0h7bcn+O6MSJF7fgghRv9/JH7GEztSuG7B OJT2Ae4jlz7VdAmQQmFfpri56w7BVcM9nhwqPdhGyJQGa2JSVQuVy/cXLMPZaz8nvq4K ghcxK+vNoe5ok1n2EYCbJXL6qX3WztkyfvYdOdNlbOG6W+kG4Bpak7zOYCbhm37sYZgr TSsQu9uwihpbGgYhWb/a1UAeDdvy0Rh683/dECXRSiFdEskKGmCLdU1+PJTQBTdFSTpH Iv+Q== MIME-Version: 1.0 Received: by 10.213.26.65 with SMTP id d1mr1263268ebc.49.1337163077967; Wed, 16 May 2012 03:11:17 -0700 (PDT) Received: by 10.14.188.8 with HTTP; Wed, 16 May 2012 03:11:17 -0700 (PDT) Date: Wed, 16 May 2012 12:11:17 +0200 Message-ID: Subject: Hierarchical comments Hacker News style From: Luca Matteis To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Sorry for the repost. I was told user@ is more appropriate for this kind of question: 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