Commit 38d2c969 authored by 刘基明's avatar 刘基明

排序优化

parent 0eb0dfd2
...@@ -131,11 +131,10 @@ public class RankService { ...@@ -131,11 +131,10 @@ public class RankService {
this.calculateThemeScore(theme); this.calculateThemeScore(theme);
} }
//排序 //排序
Map<ThemeAnalysDO, Double> map = themeAnalysDOS.stream().collect(Collectors.toMap(o -> o, ThemeAnalysDO::getScore));
hotestThemes = map.entrySet().stream() hotestThemes = themeAnalysDOS.stream()
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) .sorted(Comparator.comparing(ThemeAnalysDO::getScore).reversed())
.map(Map.Entry::getKey).collect(Collectors.toList()); .collect(Collectors.toList());
//落库 //落库
rankLogService.logThemeRank(hotestThemes, start, TimeUtils.calMillisTillNow(start)); rankLogService.logThemeRank(hotestThemes, start, TimeUtils.calMillisTillNow(start));
} }
...@@ -185,10 +184,8 @@ public class RankService { ...@@ -185,10 +184,8 @@ public class RankService {
} }
// 排序 // 排序
Map<TopicRankQo, Double> map = topicRankQos.stream().collect(Collectors.toMap(o -> o, TopicRankQo::getScore)); List<TopicRankQo> rankList = topicRankQos.stream()
List<TopicRankQo> rankList = map.entrySet().stream() .sorted(Comparator.comparing(TopicRankQo::getScore).reversed())
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.map(Map.Entry::getKey)
.collect(Collectors.toList()); .collect(Collectors.toList());
// 非“新”话题才能添加“热”标签 // 非“新”话题才能添加“热”标签
if (!TopicStatusEnum.NEWEST.getCode().equals(rankList.get(0).getType())) { if (!TopicStatusEnum.NEWEST.getCode().equals(rankList.get(0).getType())) {
...@@ -201,10 +198,12 @@ public class RankService { ...@@ -201,10 +198,12 @@ public class RankService {
List<TopicRankQo> top4Topic = rankList.stream() List<TopicRankQo> top4Topic = rankList.stream()
.limit(6) .limit(6)
.filter(o -> !newest2Topic.contains(o)) .filter(o -> !newest2Topic.contains(o))
.limit(4-newest2Topic.size()) .limit(4 - newest2Topic.size())
.collect(Collectors.toList()); .collect(Collectors.toList());
top4Topic.addAll(newest2Topic); top4Topic.addAll(newest2Topic);
this.rankTopicListTop4 = top4Topic; this.rankTopicListTop4 = top4Topic.stream()
.sorted(Comparator.comparing(TopicRankQo::getScore).reversed())
.collect(Collectors.toList());
//落库 //落库
rankLogService.logTopicRank(rankList, start, TimeUtils.calMillisTillNow(start)); rankLogService.logTopicRank(rankList, start, TimeUtils.calMillisTillNow(start));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment