|
@@ -41,18 +41,34 @@ public class RankService {
|
|
|
Map<String, Map<String, Double>> scoreMap = scoreResult.getScoreMap();
|
|
|
|
|
|
List<RankItem> items = CommonCollectionUtils.toList(param.getContents(), c -> {
|
|
|
- Map<String, Double> map = scoreMap.get(c.getId());
|
|
|
- double score = 1 * map.getOrDefault(SimilarityStrategy.class.getSimpleName(), 0.0)
|
|
|
- + 10 * map.getOrDefault(ViewCountStrategy.class.getSimpleName(), 0.0)
|
|
|
- + 100 * map.getOrDefault(ContentPoolStrategy.class.getSimpleName(), 0.0);
|
|
|
-
|
|
|
RankItem item = new RankItem();
|
|
|
item.setContent(c);
|
|
|
- item.setScore(score);
|
|
|
+ item.setScoreMap(scoreMap.get(c.getId()));
|
|
|
return item;
|
|
|
|
|
|
});
|
|
|
- Collections.sort(items, Comparator.comparingDouble(o -> -o.getScore()));
|
|
|
+ Collections.sort(items, (o1, o2) -> {
|
|
|
+ int contentPoolComparison = Double.compare(
|
|
|
+ o1.getScore(ContentPoolStrategy.class.getSimpleName()),
|
|
|
+ o2.getScore(ContentPoolStrategy.class.getSimpleName())
|
|
|
+ );
|
|
|
+ if (contentPoolComparison != 0) {
|
|
|
+ return -contentPoolComparison; // 降序
|
|
|
+ }
|
|
|
+
|
|
|
+ int similarityComparison = Double.compare(
|
|
|
+ o1.getScore(SimilarityStrategy.class.getSimpleName()),
|
|
|
+ o2.getScore(SimilarityStrategy.class.getSimpleName())
|
|
|
+ );
|
|
|
+ if (similarityComparison != 0) {
|
|
|
+ return -similarityComparison; // 降序
|
|
|
+ }
|
|
|
+
|
|
|
+ return Double.compare(
|
|
|
+ o1.getScore(ViewCountStrategy.class.getSimpleName()),
|
|
|
+ o2.getScore(ViewCountStrategy.class.getSimpleName())
|
|
|
+ );
|
|
|
+ });
|
|
|
|
|
|
log.info("RankItem sort {}", JSONUtils.toJson(items));
|
|
|
|