读书人

Hacker News网站的稿子排名算法工作原

发布时间: 2013-09-05 16:02:06 作者: rapoo

Hacker News网站的文章排名算法工作原理

In this post I'll try to explain how Hacker News ranking algorithm works and how you can reuse it in your own applications. It's a very simple ranking algorithm and works surprising well when you want to highlight hot or new stuff.

这篇文章我要向大家介绍Hacker News网站的文章排名算法工作原理,以及如何在自己的应用里使用这种算法。这个算法非常的简单,但却在突出热门文章和遴选新文章上表现的异常优秀。

Digging into news.arc code

Hacker News is implemented in Arc, a Lisp dialect coded by Paul Graham. Hacker News is opensource and the code can be found at arclanguage.org. Digging through the news.arc code you can find the ranking algorithm which looks like this:

深入 news.arc 程序代码
Hacker News是用Arc语言开发的,这是一种Lisp方言,由Y Combinator投资公司创始人Paul Graham创造。Hacker News的开源的,你可以在arclanguage.org找到它的源代码。深入发掘 news.arc 程序,你会找到这段排名算法代码,就是下面这段:

; Votes divided by the age in hours to the gravityth power.; Would be interesting to scale gravity in a slider.(= gravity* 1.8 timebase* 120 front-threshold* 1    nourl-factor* .4 lightweight-factor* .3 )(def frontpage-rank (s (o scorefn realscore) (o gravity gravity*))  (* (/ (let base (- (scorefn s) 1)          (if (> base 0) (expt base .8) base))        (expt (/ (+ (item-age s) timebase*) 60) gravity))     (if (no (in s!type 'story 'poll))  1         (blank s!url)                  nourl-factor*         (lightweight s)                (min lightweight-factor*                                              (contro-factor s))                                        (contro-factor s))))

In essence the ranking performed by Hacker News looks like this:

本质上,这段 Hacker News采用的排名算法的工作原理看起来大概是这个样子:

Score = (P-1) / (T+2)^Gwhere,P = points of an item (and -1 is to negate submitters vote)T = time since submission (in hours)G = Gravity, defaults to 1.8 in news.arc

As you see the algorithm is rather trivial to implement. In the upcoming section we'll see how the algorithm behaves.

Score = (P-1) / (T+2)^G
其中,
P = 文章获得的票数( -1 是去掉文章提交人的票)
T = 从文章提交至今的时间(小时)
G = 比重,news.arc里缺省值是1.8
正如你看到的,这个算法很容易实现。在下面的内容里,我们将会看到这个算法是如何工作的。

Effects of gravity (G) and time (T)

Gravity and time have a significant impact on the score of an item. Generally these things hold true:

读书人网 >软件架构设计

热点推荐