Hacker News new | comments | show | ask | jobs | submit login

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).




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?


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.


Can't you do it every time someone votes? The scores aren't dependent on any other items other than their own votes, so each time it gets a new vote, you rescore it and it will drop or go up on the front page accordingly.


the score is also dependant on time


Sure, but with a system that is active (like HN), there would be enough votes coming in frequently enough to handle the ranking updates and account for time increases without needing to hit the system every 5 minutes.


I think a hybrid system would actually best. Otherwise posts that don't get many votes wouldn't update their score.

The best would probably actively update on votes and do a catchall operation on ones that haven't been voted on or all on a certain periodic cycle.


Also, if only updated periodically, the front page would "skip" so to speak every X minutes (exaggerated changes in rank), whereas re-scoring on each vote would allow smoother changes in rank.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: