

How would you implement the Hacker News Ranking Algorithm with Mongodb - abhishivsaxena

I have implemented Hacker News Ranking Algorithm with SQL in the past, but am totally lost on how to do it with MongoDB. Any ideas?<p>preferably not using map reduce.
======
travisglines
I actually did this for exipe.com in node.js/mongodb let me look it up.

~~~
travisglines
Store a "score" to rank by in the database and then use some sort of time
dependent function. AKA when you search the mongo for posts sort by "score."

Our score was calculated by something like this:

    
    
        var gravity = 1.5;
        var score = num_votes / Math.pow(t+2,gravity);
    

Gravity being how quickly a post would fall. Notice the t+2 ... it added 2
hours to all posts in order to eliminate things that were recently posted with
like one vote sitting at the top.

Then we'd just run this function through the whole database periodically
(every 5 minutes or something).

~~~
antimora
Recently I was looking into how to implement trees in MongoDB. Apparently
there are several ways achieving this depending on querying needs.

Could you share your experience building trees for comments in your project
Exipe?

~~~
travisglines
We just had a comments model (in mongoose) that had an array of subcomments
(MongoDB arrays are awesome). Therefore the "trees" (not really trees as we
implemented it) could only have one level of indentation ... but that's all we
wanted anyways.

