views:

36

answers:

1

I'm using a customized version of Hacker News popularity algorithm for my social site (items with a number of likes and comments). The algorithm works perfectly but I don't know how to update item scorings correctly (I'm storing the score in item model as meta data).

Now I'm just updating scores on every new like and comment for items listed during past 9 days. This is really slow and resource heavy so I'm looking for a better way to keep scores up to date. Problem is that every item needs a new score when one changes to keep the time decay. What would be the better way to do this? I'm using Django for the project.

A: 

There's a number of ways to do this. One simple way is to number items sequentially, and start each item with a 'rank id' of its ID number. Whenever a post is rated up, increment its rank number (and vice-versa for down votes). Then, sort by rank number to order items correctly.

Another option is an exponential decay model, which requires periodic updates, but these can be piggy backed on votes, reducing the amount of batch-update work you have to do. I wrote an article about implementing that here. It's targeted at App Engine, but generally useful.

Nick Johnson