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 2C10C9142 for ; Wed, 16 May 2012 10:27:13 +0000 (UTC) Received: (qmail 19622 invoked by uid 500); 16 May 2012 10:27:12 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 19456 invoked by uid 500); 16 May 2012 10:27:12 -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 19437 invoked by uid 99); 16 May 2012 10:27:11 -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:27:11 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [209.85.214.180] (HELO mail-ob0-f180.google.com) (209.85.214.180) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 May 2012 10:27:04 +0000 Received: by obbun3 with SMTP id un3so1065162obb.11 for ; Wed, 16 May 2012 03:26:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=nFL6e2FoAKVlXzF5LFcQgz1pl9cAPkRg/04KjcX9vaw=; b=SfZENhCSTQSI+3qGmSaw4pqBFUJRr0wRHir3u1n2hfCkJ3eu8bTofF7+DVipbqTzVF sej3OmplB8M1EnROTyS6IO41s2hVBiwh/IAmFkAkn7KsmQdPZ4lCa5OLYHLngiriSMzK ZRe4tAVkz2ngesK0+9T6A0EZEi75R5+qj+7ndiDvft9M3LDBMilhFR3IsVWlpJtryzBr nXMV9kMNUIZ5tQGxu4VuAHPNqd/ulSHoTE3OiBZNMQ8YwXM+hVSqMvk8ASJlr/fHbB4/ nWezhWCu3CENuac4ZHl3zHnhD10GK0KaOQqupl6XezhgyAjflw66Ud5CW6puvTNeW82x BZZw== MIME-Version: 1.0 Received: by 10.60.14.193 with SMTP id r1mr2310455oec.16.1337164002897; Wed, 16 May 2012 03:26:42 -0700 (PDT) Received: by 10.182.55.72 with HTTP; Wed, 16 May 2012 03:26:42 -0700 (PDT) Received: by 10.182.55.72 with HTTP; Wed, 16 May 2012 03:26:42 -0700 (PDT) In-Reply-To: References: Date: Wed, 16 May 2012 22:26:42 +1200 Message-ID: Subject: Re: Hierarchical comments Hacker News style From: Tim McNamara To: dev@couchdb.apache.org Content-Type: multipart/alternative; boundary=e89a8ff252ee662f2004c024c123 X-Gm-Message-State: ALoCoQl7QNaynzsyeRZq9b4nv4LHCmKrS2hmHIa/3o/wgdxqKV+kElJe2j8/3CwKHx7n9pNzAXlt --e89a8ff252ee662f2004c024c123 Content-Type: text/plain; charset=UTF-8 It may be worth looking at the reddit source code (github.com/reddit/reddit) to get some tips. Then you could adapt this into Couch. On May 16, 2012 9:41 PM, "Luca Matteis" wrote: > 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 > --e89a8ff252ee662f2004c024c123--