瀏覽代碼

cold start

丁云鹏 11 月之前
父節點
當前提交
de8f811290

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

@@ -48,13 +48,13 @@ public class RankV3Strategy implements RankStrategy {
             item.setContent(c);
             item.setScoreMap(scoreMap.get(c.getId()));
             double score = 2 * item.getScore(SimilarityStrategy.class.getSimpleName())
-                    + item.getScore(ViewMultiplierStrategy.class.getSimpleName())
+                    + item.getScore(ViewMultiplierStrategy.class.getSimpleName());
             item.setScore(score);
             return item;
         });
 
         // 1 排序
-        Collections.sort(items, (o1, o2) -> -Double.compare(o1.getScore(), o2.getScore());
+        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));

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

@@ -4,9 +4,11 @@ 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.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 lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeansException;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
@@ -85,6 +87,9 @@ public class ScoreService implements ApplicationContextAware {
         List<ScoreStrategy> strategies = new ArrayList<>();
         strategies.add(strategyMap.get(SimilarityStrategy.class.getSimpleName()));
         strategies.add(strategyMap.get(ViewCountStrategy.class.getSimpleName()));
+        if (StringUtils.equals(param.getStrategy(), "ArticleRankV3")) {
+            strategies.add(strategyMap.get(ViewMultiplierStrategy.class.getSimpleName()));
+        }
 
         return strategies;
     }

+ 4 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/util/NormalizationUtils.java

@@ -10,4 +10,8 @@ public final class NormalizationUtils {
         }
         return (value - min) / (max - min);
     }
+
+    public static double min(double value) {
+        return Math.min(value - 1, 1);
+    }
 }