How are Reddit and Hacker News ranking algorithms used?

后端 未结 2 727
后悔当初
后悔当初 2021-01-30 02:42

I\'ve been looking at ranking algorithms recently, specifically those used by Reddit and Hacker News. The algorithms themselves are simple enough, but I don\'t quite understand

2条回答
  •  心在旅途
    2021-01-30 03:21

    I implemented an SQL version of Reddit's ranking algorithm for a video aggregator like so:

    SELECT id, title
    FROM videos
    ORDER BY 
        LOG10(ABS(cached_votes_total) + 1) * SIGN(cached_votes_total)   
        + (UNIX_TIMESTAMP(created_at) / 300000) DESC
    LIMIT 50
    

    cached_votes_total is updated by a trigger whenever a new vote is cast. It runs fast enough on our current site, but I am planning on adding a ranking value column and updating it with the same trigger as the cached_votes_total column. After that optimization, it should be fast enough for most any size site.

    edit: More information at Reddit Hotness Algorithm in SQL

提交回复
热议问题