Browse Source

cold start

丁云鹏 11 months ago
parent
commit
d3ece6ce93

+ 1 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/rank/RankItem.java

@@ -12,6 +12,7 @@ import java.util.Map;
 public class RankItem {
     private Content content;
     private Map<String, Double> scoreMap;
+    private double score;
 
     public double getScore(String strategy) {
         return scoreMap.get(strategy) == null

+ 5 - 14
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/rank/strategy/RankV3Strategy.java

@@ -11,7 +11,7 @@ import com.tzld.longarticle.recommend.server.service.score.ScoreParam;
 import com.tzld.longarticle.recommend.server.service.score.ScoreResult;
 import com.tzld.longarticle.recommend.server.service.score.ScoreService;
 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.service.score.strategy.ViewMultiplierStrategy;
 import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
 import com.tzld.longarticle.recommend.server.util.JSONUtils;
 import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
@@ -47,23 +47,14 @@ public class RankV3Strategy implements RankStrategy {
             RankItem item = new RankItem();
             item.setContent(c);
             item.setScoreMap(scoreMap.get(c.getId()));
+            double score = 2 * item.getScore(SimilarityStrategy.class.getSimpleName())
+                    + item.getScore(ViewMultiplierStrategy.class.getSimpleName())
+            item.setScore(score);
             return item;
-
         });
 
         // 1 排序
-        Collections.sort(items, (o1, o2) -> {
-            int result = -Double.compare(
-                    o1.getScore(SimilarityStrategy.class.getSimpleName()),
-                    o2.getScore(SimilarityStrategy.class.getSimpleName()));
-            if (result != 0) {
-                return result;
-            }
-
-            return -Double.compare(
-                    o1.getScore(ViewCountStrategy.class.getSimpleName()),
-                    o2.getScore(ViewCountStrategy.class.getSimpleName()));
-        });
+        Collections.sort(items, (o1, o2) -> -Double.compare(o1.getScore(), o2.getScore());
         // 2 相似去重
         List<Content> contents = CommonCollectionUtils.toList(items, RankItem::getContent);
         log.info("Sort result {}", JSONUtils.toJson(contents));

+ 8 - 8
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/strategy/SimilarityStrategy.java

@@ -5,7 +5,6 @@ import com.tzld.longarticle.recommend.server.service.score.Score;
 import com.tzld.longarticle.recommend.server.service.score.ScoreParam;
 import com.tzld.longarticle.recommend.server.service.score.ScoreStrategy;
 import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
-import com.tzld.longarticle.recommend.server.util.NormalizationUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
@@ -31,18 +30,19 @@ public class SimilarityStrategy implements ScoreStrategy {
         }
         Map<String, Double> scoreMap = nlpRemoteService.score(param.getAccountName(), param.getContents());
 
-        double min = scoreMap.values().stream()
-                .min(Double::compareTo)
-                .orElse(0.0);
-        double max = scoreMap.values().stream()
-                .max(Double::compareTo)
-                .orElse(0.0);
+//        double min = scoreMap.values().stream()
+//                .min(Double::compareTo)
+//                .orElse(0.0);
+//        double max = scoreMap.values().stream()
+//                .max(Double::compareTo)
+//                .orElse(0.0);
 
         List<Score> scores = CommonCollectionUtils.toList(param.getContents(), c -> {
             Score score = new Score();
             score.setContentId(c.getId());
             double val = scoreMap.get(c.getId()) == null ? 0.0 : scoreMap.get(c.getId());
-            score.setScore(NormalizationUtils.minMax(val, min, max));
+            // score.setScore(NormalizationUtils.minMax(val, min, max));
+            score.setScore(val);
             score.setStrategy(this);
             return score;
         });