我有兴趣使用这个排名类,它基于Evan Miller的一篇文章,用于对我的表格进行排名,该表格具有赞和踩。我正在为一个活动网站开发与Stack Overflow的点赞/踩系统非常相似的系统,通过使用这个排名类,我感觉结果会更加准确。我的问题是如何按照“热度”函数进行排序?
private function _hotness($upvotes = 0, $downvotes = 0, $posted = 0) {
$s = $this->_score($upvotes, $downvotes);
$order = log(max(abs($s), 1), 10);
if($s > 0) {
$sign = 1;
} elseif($s < 0) {
$sign = -1;
} else {
$sign = 0;
}
$seconds = $posted - 1134028003;
return round($order + (($sign * $seconds)/45000), 7);
}
我想每次用户投票时,我都可以在我的表中添加一列,重新计算新投票的热度数据,并在主页面上按该列排序。但我更有兴趣将此功能与上述函数结合起来实时处理,但我不确定是否可能。
来自Evan Miller的方法:
SELECT widget_id, ((positive + 1.9208) / (positive + negative) -
1.96 * SQRT((positive * negative) / (positive + negative) + 0.9604) /
(positive + negative)) / (1 + 3.8416 / (positive + negative))
AS ci_lower_bound FROM widgets WHERE positive + negative > 0
ORDER BY ci_lower_bound DESC;
但我不想在SQL中进行这个计算,因为我觉得这样会很混乱,并且如果我在多个页面使用此代码,则难以更改。