丁云鹏 11 月之前
父节点
当前提交
aefda1bd48

+ 12 - 5
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/rank/RankService.java

@@ -14,7 +14,6 @@ import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.RandomUtils;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -55,20 +54,26 @@ public class RankService {
             List<RankItem> data = itemMap.computeIfAbsent(c.getContent().getContentPoolType(), k -> new ArrayList<>());
             data.add(c);
         }
-        for (Map.Entry<String, List<RankItem>> e : itemMap.entrySet()) {
-            if (StringUtils.equals(contentPools[1], e.getKey())) {
+        List<RankItem> sortedItems = new ArrayList<>();
+        for (int i = 0; i < contentPools.length; i++) {
+            if (i == 1) {
                 // 播放量排序
-                Collections.sort(e.getValue(), (o1, o2) -> -Double.compare(
+                List<RankItem> data = itemMap.get(contentPools[i]);
+                Collections.sort(data, (o1, o2) -> -Double.compare(
                         o1.getScore(ViewCountStrategy.class.getSimpleName()),
                         o2.getScore(ViewCountStrategy.class.getSimpleName())));
+                sortedItems.addAll(data);
             } else {
                 // 相似排序
-                Collections.sort(e.getValue(), (o1, o2) -> -Double.compare(
+                List<RankItem> data = itemMap.get(contentPools[i]);
+                Collections.sort(data, (o1, o2) -> -Double.compare(
                         o1.getScore(SimilarityStrategy.class.getSimpleName()),
                         o2.getScore(SimilarityStrategy.class.getSimpleName())));
+                sortedItems.addAll(data);
             }
         }
 
+<<<<<<< HEAD
 
         List<RankItem> sortedItems = new ArrayList<>();
         for (String pool : contentPools) {
@@ -76,6 +81,8 @@ public class RankService {
                 sortedItems.addAll(itemMap.get(pool));
             }
         }
+=======
+>>>>>>> 031bdba (init)
         List<Content> contents = CommonCollectionUtils.toList(sortedItems, RankItem::getContent);
         log.info("Sort result {}", JSONUtils.toJson(contents));
 

+ 2 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/ScoreService.java

@@ -2,8 +2,8 @@ package com.tzld.longarticle.recommend.server.service.score;
 
 
 import com.tzld.longarticle.recommend.server.common.ThreadPoolFactory;
-import com.tzld.longarticle.recommend.server.service.score.strategy.ContentPoolStrategy;
 import com.tzld.longarticle.recommend.server.service.score.strategy.SimilarityStrategy;
+import com.tzld.longarticle.recommend.server.service.score.strategy.ViewCountStrategy;
 import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
 import com.tzld.longarticle.recommend.server.util.JSONUtils;
 import lombok.extern.slf4j.Slf4j;
@@ -84,7 +84,7 @@ public class ScoreService implements ApplicationContextAware {
     private List<ScoreStrategy> getScoreStrategy(ScoreParam param) {
         List<ScoreStrategy> strategies = new ArrayList<>();
         strategies.add(strategyMap.get(SimilarityStrategy.class.getSimpleName()));
-        strategies.add(strategyMap.get(ContentPoolStrategy.class.getSimpleName()));
+        strategies.add(strategyMap.get(ViewCountStrategy.class.getSimpleName()));
 
         return strategies;
     }