Hacker News
Score = (P-1)/(T+2)^G
StackOverflow
(log(Qviews)4) + ((QanswersQscore)/5) + sum(Ascores)
…
(QageInHours+1) - ((AageInHours-Qupdated)/2))^1.5
Nowcoder
log(精华分+评论数 ×10 + 点赞数× 2 + 收藏数× 2) + (发布时间-牛客纪元)
在RedisKeyUtil类里,添加
//帖子分数
public static String getPostScoreKey(){
return PREFIX_POST + SPLIT + "score";
}
在DiscussPostController类addDiscussPost方法里return CommunityUtil.getJSONString(0,“发送成功!”);之前,添加
//计算帖子分数(发帖时给一个基础分),若存到队列里会导致重复计算,而存到set比较好
String redisKey = RedisKeyUtil.getPostScoreKey();
redisTemplate.opsForSet().add(redisKey,post.getId());
置顶不算分,加精要算分,所以在setWonderful方法里return CommunityUtil.getJSONString(0);之前添加
//计算帖子分数
String redisKey = RedisKeyUtil.getPostScoreKey();
redisTemplate.opsForSet().add(redisKey,id);
在CommentController类addComment方法里return “redirect:/discuss/detail/”+discussPostId;之前,添加
//计算帖子分数
String redisKey = RedisKeyUtil.getPostScoreKey();
redisTemplate.opsForSet().add(redisKey,discussPostId);
在LikeController类like方法里return CommunityUtil.getJSONString(0,null, map);之前,添加
if(entityType==ENTITY_TYPE_POST){
//计算帖子分数(只是先收集帖子id)
String redisKey = RedisKeyUtil.getPostScoreKey();
redisTemplate.opsForSet().add(redisKey,postId);
}
在quartz包下新建PostScoreRefreshJob类,
//牛客纪元
private static final Date epoch; //在静态块里初始化一下epoch
static{
try {
epoch = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2014-08-01 00:00:00");
} catch (ParseException e) {
throw new RuntimeException("初始化牛客纪元失败!",e);
}
}
@Override
public void execute(JobExecutionContext context) throws JobExecutionExce