问题
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.
回答1:
OK. I have done it using different apps: First, you need to install either "dokterbob/django-popularity" on github or "thornomad/django-hitcount" to track how often a link is visited.
Second, you need to count how many votes (likes or favorites) an object receives. For that purpose, you can try "brosner/django-voting", "apgwoz/django-favorites".
Now you have to use this piece of code --django-populars to put them all together. I would recommend looking into this code first of all to see how it works to understand how to put together the needed components.
回答2:
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.
来源:https://stackoverflow.com/questions/3885167/how-to-update-content-popularity-scoring-such-as-hacker-news-algorithm