Quellcode durchsuchen

召回内容增加视频内容库,排序策略可指定发送内容库来源

wangyunpeng vor 7 Monaten
Ursprung
Commit
1984f6637a
19 geänderte Dateien mit 184 neuen und 151 gelöschten Zeilen
  1. 2 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/enums/recommend/RankStrategyEnum.java
  2. 27 16
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/RankService.java
  3. 1 18
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/HisJumpRankStrategy.java
  4. 1 1
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/InfiniteRankStrategy.java
  5. 1 1
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/LateRankStrategy.java
  6. 0 16
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RandomRankStrategy.java
  7. 1 8
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV10Strategy.java
  8. 2 9
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV11Strategy.java
  9. 2 9
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV12Strategy.java
  10. 2 9
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV13Strategy.java
  11. 2 9
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV14Strategy.java
  12. 133 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV15Strategy.java
  13. 1 12
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV3Strategy.java
  14. 1 8
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV4Strategy.java
  15. 2 9
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV5Strategy.java
  16. 1 8
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV7Strategy.java
  17. 2 9
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV8Strategy.java
  18. 1 8
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV9Strategy.java
  19. 2 1
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/score/ScoreService.java

+ 2 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/enums/recommend/RankStrategyEnum.java

@@ -20,6 +20,8 @@ public enum RankStrategyEnum {
     ArticleRankV13("ArticleRankV13", "ArticleRankV13", "rankV13Strategy"),
     ArticleRankV14("ArticleRankV14", "ArticleRankV14", "rankV14Strategy"),
 
+    ArticleRankV15("ArticleRankV15", "ArticleRankV15", "rankV15Strategy"),
+
     HIS_JUMP_STRATEGY("ArticleRankHisJump", "历史表现跳过相似度策略", "hisJumpRankStrategy"),
     INFINITE_STRATEGY("ArticleRankInfinite", "无限发表", "infiniteRankStrategy"),
     LATE_STRATEGY("ArticleRankLate", "晚间策略", "lateRankStrategy"),

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

@@ -4,6 +4,8 @@ package com.tzld.longarticle.recommend.server.service.recommend.rank;
 import cn.hutool.core.collection.CollectionUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.ctrip.framework.apollo.model.ConfigChangeEvent;
+import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
@@ -31,27 +33,35 @@ import static com.tzld.longarticle.recommend.server.common.constant.SceneConstan
 @Slf4j
 public class RankService implements InitializingBean {
 
-    private static Map<String, Map<Integer, Integer>> staticAccountPoolSourceTypeMap;
+    private static Map<String, Map<String, Integer>> staticStrategyPoolSourceTypeMap;
 
-    @ApolloJsonValue("${accountPoolSourceTypeConfig:{}}")
-    private Map<String, Map<Integer, Integer>> accountPoolSourceTypeMap;
+    @ApolloJsonValue("${strategyPoolSourceTypeConfig:{}}")
+    private Map<String, Map<String, Integer>> strategyPoolSourceTypeMap;
 
     @Override
     public void afterPropertiesSet() throws Exception {
-        RankService.staticAccountPoolSourceTypeMap = accountPoolSourceTypeMap;
+        RankService.staticStrategyPoolSourceTypeMap = strategyPoolSourceTypeMap;
     }
 
-    public static Integer getAccountPoolSourceType(String ghId, Integer index) {
+    @ApolloConfigChangeListener(interestedKeys = {"strategyPoolSourceTypeConfig"})
+    public void configChange(ConfigChangeEvent changeEvent) {
+        RankService.staticStrategyPoolSourceTypeMap = JSONObject.parseObject(changeEvent.getChange(
+                "strategyPoolSourceTypeConfig").getNewValue(), Map.class);
+        log.info("strategyPoolSourceTypeConfig change updateStaticValue success newValue:{}",
+                JSONObject.toJSONString(staticStrategyPoolSourceTypeMap));
+    }
+
+    public static Integer getStrategyPoolSourceType(String strategy, Integer index) {
         Integer sourceType = 0;
-        Map<Integer, Integer> indexSourceTypeMap = staticAccountPoolSourceTypeMap.get(ghId);
+        Map<String, Integer> indexSourceTypeMap = staticStrategyPoolSourceTypeMap.get(strategy);
         if (Objects.nonNull(indexSourceTypeMap)) {
-            sourceType = indexSourceTypeMap.get(index);
+            sourceType = indexSourceTypeMap.get(String.valueOf(index));
         }
         return sourceType;
     }
 
-    public static Map<Integer, Integer> getAccountPoolSourceType(String ghId) {
-        return staticAccountPoolSourceTypeMap.get(ghId);
+    public static Map<String, Integer> getStrategyPoolSourceType(String strategy) {
+        return staticStrategyPoolSourceTypeMap.get(strategy);
     }
 
     public RankResult rank(RankParam param) {
@@ -93,9 +103,7 @@ public class RankService implements InitializingBean {
                                               Map<Integer, AccountIndexReplacePoolConfig> indexReplacePoolConfigMap) {
         List<Content> pool = contentMap.get(contentPools[1]);
         if (CollectionUtils.isNotEmpty(pool)) {
-            Integer sourceType = getAccountPoolSourceType(param.getGhId(), 2);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool = contentSourceTypeFilter(videoSourceType, pool, sourceType);
+            pool = contentSourceTypeFilter(param.getStrategy(), pool, 2);
         }
         if (CollectionUtils.isNotEmpty(pool)) {
             int i = RandomUtils.nextInt(0, Math.min(pool.size(), 5));
@@ -131,7 +139,12 @@ public class RankService implements InitializingBean {
         }
     }
 
-    public static List<Content> contentSourceTypeFilter(Integer videoSourceType, List<Content> pool, Integer sourceType) {
+    public static List<Content> contentSourceTypeFilter(String strategy, List<Content> pool, Integer index) {
+        if (!staticStrategyPoolSourceTypeMap.containsKey(strategy)) {
+            return pool;
+        }
+        Integer sourceType = getStrategyPoolSourceType(strategy, index);
+        Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
         if (Objects.nonNull(sourceType) && sourceType.equals(videoSourceType)) {
             pool = pool.stream().filter(o -> Objects.equals(o.getSourceType(), videoSourceType)).collect(Collectors.toList());
         } else {
@@ -144,9 +157,7 @@ public class RankService implements InitializingBean {
                                           Map<String, List<Content>> contentMap, String strategy) {
         List<Content> pool = contentMap.get(contentPools[2]);
         if (CollectionUtils.isNotEmpty(pool)) {
-            Integer sourceType = getAccountPoolSourceType(param.getGhId(), 3);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool = contentSourceTypeFilter(videoSourceType, pool, sourceType);
+            pool = contentSourceTypeFilter(param.getStrategy(), pool, 3);
         }
         if (CollectionUtils.isNotEmpty(pool) && param.getSize() > result.size()) {
             RankService.printSortLog(strategy, param.getAccountName(), "3-8", pool.subList(0, Math.min(pool.size(), 200)));

+ 1 - 18
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/HisJumpRankStrategy.java

@@ -1,7 +1,5 @@
 package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
-import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
 import com.tzld.longarticle.recommend.server.service.recommend.config.AccountContentPoolConfigService;
@@ -88,12 +86,7 @@ public class HisJumpRankStrategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        if (CollectionUtils.isNotEmpty(pool1)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 1);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool1 = RankService.contentSourceTypeFilter(videoSourceType, pool1, sourceType);
-        }
-        RankService.printSortLog(RankStrategyEnum.HIS_JUMP_STRATEGY.getStrategy(), param.getAccountName(), "头条", pool1);
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
         if (CollectionUtils.isNotEmpty(pool1)) {
             int i = RandomUtils.nextInt(0, Math.min(pool1.size(), 20));
             result.add(pool1.get(i));
@@ -103,11 +96,6 @@ public class HisJumpRankStrategy implements RankStrategy {
         }
         // 次
         List<Content> pool2 = contentMap.get(contentPools[1]);
-        if (CollectionUtils.isNotEmpty(pool2)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 2);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool2 = RankService.contentSourceTypeFilter(videoSourceType, pool2, sourceType);
-        }
         if (CollectionUtils.isNotEmpty(pool2)) {
             int i = RandomUtils.nextInt(0, Math.min(pool2.size(), 20));
             result.add(pool2.get(i));
@@ -126,11 +114,6 @@ public class HisJumpRankStrategy implements RankStrategy {
 
         // 3-8
         List<Content> pool = contentMap.get(contentPools[2]);
-        if (CollectionUtils.isNotEmpty(pool)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 3);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool = RankService.contentSourceTypeFilter(videoSourceType, pool, sourceType);
-        }
         if (CollectionUtils.isNotEmpty(pool) && param.getSize() > result.size()) {
             int slotNum = param.getSize() - result.size();
             List<Content> subPool = pool.subList(0, Math.min(pool.size(), 30));

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

@@ -73,7 +73,7 @@ public class InfiniteRankStrategy implements RankStrategy {
         }
 
         // 全部使用3-8内容池
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.INFINITE_STRATEGY.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         return new RankResult(result);
     }

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

@@ -73,7 +73,7 @@ public class LateRankStrategy implements RankStrategy {
         }
 
         // 全部使用3-8内容池
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.LATE_STRATEGY.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         return new RankResult(result);
     }

+ 0 - 16
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RandomRankStrategy.java

@@ -1,6 +1,5 @@
 package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
-import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
 import com.tzld.longarticle.recommend.server.service.recommend.config.AccountContentPoolConfigService;
 import com.tzld.longarticle.recommend.server.service.recommend.config.StrategyIndexScoreWeightService;
@@ -44,22 +43,12 @@ public class RandomRankStrategy implements RankStrategy {
         }
         // 头
         List<Content> pool = contentMap.get(contentPools[0]);
-        if (CollectionUtils.isNotEmpty(pool)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 1);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool = RankService.contentSourceTypeFilter(videoSourceType, pool, sourceType);
-        }
         if (CollectionUtils.isNotEmpty(pool)) {
             Collections.shuffle(pool);
             result.add(pool.get(0));
         }
         // 次
         pool = contentMap.get(contentPools[1]);
-        if (CollectionUtils.isNotEmpty(pool)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 2);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool = RankService.contentSourceTypeFilter(videoSourceType, pool, sourceType);
-        }
         if (CollectionUtils.isNotEmpty(pool)) {
             Collections.shuffle(pool);
             result.add(pool.get(0));
@@ -69,11 +58,6 @@ public class RandomRankStrategy implements RankStrategy {
         }
         // 全部使用3-8内容池
         pool = contentMap.get(contentPools[2]);
-        if (CollectionUtils.isNotEmpty(pool)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 3);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool = RankService.contentSourceTypeFilter(videoSourceType, pool, sourceType);
-        }
         if (CollectionUtils.isNotEmpty(pool)) {
             Collections.shuffle(pool);
             result.addAll(pool.subList(0, Math.min(pool.size(), param.getSize())));

+ 1 - 8
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV10Strategy.java

@@ -1,8 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
 
-import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.ContentPoolEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
@@ -104,11 +102,6 @@ public class RankV10Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        if (CollectionUtils.isNotEmpty(pool1)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 1);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool1 = RankService.contentSourceTypeFilter(videoSourceType, pool1, sourceType);
-        }
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -119,7 +112,7 @@ public class RankV10Strategy implements RankStrategy {
         RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV10.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

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

@@ -1,8 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
 
-import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.ContentPoolEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
@@ -123,12 +121,7 @@ public class RankV11Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        if (CollectionUtils.isNotEmpty(pool1)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 1);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool1 = RankService.contentSourceTypeFilter(videoSourceType, pool1, sourceType);
-        }
-        RankService.printSortLog(RankStrategyEnum.ArticleRankV11.getStrategy(), param.getAccountName(), "头条", pool1);
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -139,7 +132,7 @@ public class RankV11Strategy implements RankStrategy {
         RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV11.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

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

@@ -1,8 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
 
-import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.ContentPoolEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
@@ -123,12 +121,7 @@ public class RankV12Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        if (CollectionUtils.isNotEmpty(pool1)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 1);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool1 = RankService.contentSourceTypeFilter(videoSourceType, pool1, sourceType);
-        }
-        RankService.printSortLog(RankStrategyEnum.ArticleRankV12.getStrategy(), param.getAccountName(), "头条", pool1);
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -139,7 +132,7 @@ public class RankV12Strategy implements RankStrategy {
         RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV12.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

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

@@ -1,8 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
 
-import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.ContentPoolEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
@@ -124,12 +122,7 @@ public class RankV13Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        if (CollectionUtils.isNotEmpty(pool1)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 1);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool1 = RankService.contentSourceTypeFilter(videoSourceType, pool1, sourceType);
-        }
-        RankService.printSortLog(RankStrategyEnum.ArticleRankV13.getStrategy(), param.getAccountName(), "头条", pool1);
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -140,7 +133,7 @@ public class RankV13Strategy implements RankStrategy {
         RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV13.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

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

@@ -1,8 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
 
-import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.ContentPoolEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
@@ -124,12 +122,7 @@ public class RankV14Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        if (CollectionUtils.isNotEmpty(pool1)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 1);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool1 = RankService.contentSourceTypeFilter(videoSourceType, pool1, sourceType);
-        }
-        RankService.printSortLog(RankStrategyEnum.ArticleRankV14.getStrategy(), param.getAccountName(), "头条", pool1);
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -140,7 +133,7 @@ public class RankV14Strategy implements RankStrategy {
         RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV14.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

+ 133 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV15Strategy.java

@@ -0,0 +1,133 @@
+package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
+
+
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
+import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
+import com.tzld.longarticle.recommend.server.model.dto.Content;
+import com.tzld.longarticle.recommend.server.model.entity.crawler.Article;
+import com.tzld.longarticle.recommend.server.repository.crawler.ArticleRepository;
+import com.tzld.longarticle.recommend.server.service.recommend.config.AccountContentPoolConfigService;
+import com.tzld.longarticle.recommend.server.service.recommend.config.StrategyIndexScoreWeightService;
+import com.tzld.longarticle.recommend.server.service.recommend.rank.*;
+import com.tzld.longarticle.recommend.server.service.recommend.score.AccountIndexReplacePoolConfig;
+import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreResult;
+import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreService;
+import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+/**
+ * @author dyp
+ */
+@Service
+@Slf4j
+public class RankV15Strategy implements RankStrategy {
+
+    @Autowired
+    private ScoreService scoreService;
+    @Autowired
+    private AccountContentPoolConfigService accountContentPoolConfigService;
+    @Autowired
+    private ArticleRepository articleRepository;
+    @Autowired
+    private StrategyIndexScoreWeightService weightService;
+
+    @ApolloJsonValue("${touliu.account.ghIds:[\"gh_93e00e187787\", \"gh_ac43e43b253b\", \"gh_68e7fdc09fe4\",\"gh_77f36c109fb1\", \"gh_b181786a6c8c\", \"gh_1ee2e1b39ccf\"]}")
+    private List<String> touliuAccountGhIds;
+
+    public RankResult rank(RankParam param) {
+        List<Content> result = new ArrayList<>();
+
+        ScoreResult scoreResult = scoreService.score(RankStrategy.convertToScoreParam(param));
+
+        Map<String, Map<String, Double>> scoreMap = scoreResult.getScoreMap();
+        String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
+        Map<Integer, AccountIndexReplacePoolConfig> indexReplacePoolConfigMap = accountContentPoolConfigService.getContentReplacePools(param.getAccountName());
+
+        List<RankItem> items = CommonCollectionUtils.toList(param.getContents(), c -> {
+            RankItem item = new RankItem();
+            item.setContent(c);
+            c.setScoreMap(scoreMap.get(c.getId()));
+            item.setScoreMap(scoreMap.get(c.getId()));
+            double score;
+            int index = weightService.getIndex(item.getContent().getContentPoolType(), contentPools);
+            if (contentPools[0].equals(item.getContent().getContentPoolType())
+                    || contentPools[1].equals(item.getContent().getContentPoolType())) {
+                score = item.getScore(ScoreStrategyEnum.SIMILARITY.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.SIMILARITY.value())
+                        + item.getScore(ScoreStrategyEnum.CATEGORY.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.CATEGORY.value())
+                        + item.getScore(ScoreStrategyEnum.FLOW_CTL_DECREASE.value())
+                        + item.getScore(ScoreStrategyEnum.CRAWLER_DAYS_DECREASE_STRATEGY.value());
+                if (item.getScore(ScoreStrategyEnum.PUBLISH_TIMES.value()) >= 0) {
+                    score += item.getScore(ScoreStrategyEnum.VIEW_COUNT_RATE.value())
+                            * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                            ScoreStrategyEnum.VIEW_COUNT_RATE.value());
+                }
+            } else {
+                score = item.getScore(ScoreStrategyEnum.SIMILARITY.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.SIMILARITY.value())
+                        + item.getScore(ScoreStrategyEnum.CATEGORY.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.CATEGORY.value())
+                        + item.getScore(ScoreStrategyEnum.ACCOUNT_PRE_DISTRIBUTE.value())
+                        + item.getScore(ScoreStrategyEnum.PUBLISH_TIMES.value())
+                        + item.getScore(ScoreStrategyEnum.CRAWLER_DAYS_DECREASE_STRATEGY.value())
+                        + item.getScore(ScoreStrategyEnum.FLOW_CTL_DECREASE.value());
+            }
+            c.setScore(score);
+            item.setScore(score);
+            return item;
+        });
+        // 相似度评分为0 报警返回
+        List<Article> hisPublishFirstArticleList = articleRepository.getByGhIdAndItemIndexAndTypeEqualsAndStatusEquals(
+                param.getGhId(), 1, param.getType(), 1);
+        if (RankStrategy.SimilarityScoreZero(items, param, hisPublishFirstArticleList)) {
+            return new RankResult(result);
+        }
+
+        // 1 排序
+        Collections.sort(items, (o1, o2) -> -Double.compare(o1.getScore(), o2.getScore()));
+        // 2 相似去重
+        List<Content> contents = CommonCollectionUtils.toList(items, RankItem::getContent);
+
+        // 3 文章按照内容池分组
+        Map<String, List<Content>> contentMap = new HashMap<>();
+        for (Content c : contents) {
+            List<Content> data = contentMap.computeIfAbsent(c.getContentPoolType(), k -> new ArrayList<>());
+            data.add(c);
+        }
+        // 4 选文章
+        String[] publishPool = Arrays.copyOf(contentPools, contentPools.length);
+
+        // 头
+        List<Content> pool1 = contentMap.get(contentPools[0]);
+        if (CollectionUtils.isNotEmpty(pool1)) {
+            pool1 = RankService.contentSourceTypeFilter(param.getStrategy(), pool1, 1);
+        }
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
+        if (CollectionUtils.isNotEmpty(pool1)) {
+            result.add(pool1.get(0));
+        } else {
+            RankStrategy.sendFeishuFirstPoolEmpty(param, contentPools[0]);
+            return new RankResult(result);
+        }
+        // 次
+        RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
+
+        // 3-8
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
+
+        RankStrategy.deduplication(result, contentMap, publishPool);
+
+        return new RankResult(result);
+    }
+
+}

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

@@ -1,7 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
 
-import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
@@ -94,11 +93,6 @@ public class RankV3Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        if (CollectionUtils.isNotEmpty(pool1)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 1);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool1 = RankService.contentSourceTypeFilter(videoSourceType, pool1, sourceType);
-        }
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -107,11 +101,6 @@ public class RankV3Strategy implements RankStrategy {
         }
         // 次
         List<Content> pool2 = contentMap.get(contentPools[1]);
-        if (CollectionUtils.isNotEmpty(pool2)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 2);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool2 = RankService.contentSourceTypeFilter(videoSourceType, pool2, sourceType);
-        }
         if (CollectionUtils.isNotEmpty(pool2)) {
             int i = RandomUtils.nextInt(0, Math.min(pool2.size(), 5));
             result.add(pool2.get(i));
@@ -121,7 +110,7 @@ public class RankV3Strategy implements RankStrategy {
         }
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV3.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

+ 1 - 8
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV4Strategy.java

@@ -1,8 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
 
-import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.ContentPoolEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
@@ -94,11 +92,6 @@ public class RankV4Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        if (CollectionUtils.isNotEmpty(pool1)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 1);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool1 = RankService.contentSourceTypeFilter(videoSourceType, pool1, sourceType);
-        }
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -109,7 +102,7 @@ public class RankV4Strategy implements RankStrategy {
         RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV4.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

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

@@ -2,8 +2,6 @@ package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
 
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
-import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
 import com.tzld.longarticle.recommend.server.model.entity.crawler.Article;
@@ -111,12 +109,7 @@ public class RankV5Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        if (CollectionUtils.isNotEmpty(pool1)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 1);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool1 = RankService.contentSourceTypeFilter(videoSourceType, pool1, sourceType);
-        }
-        RankService.printSortLog(RankStrategyEnum.ArticleRankV5.getStrategy(), param.getAccountName(), "头条", pool1);
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -127,7 +120,7 @@ public class RankV5Strategy implements RankStrategy {
         RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV5.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

+ 1 - 8
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV7Strategy.java

@@ -1,8 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
 
-import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.ContentPoolEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
@@ -96,11 +94,6 @@ public class RankV7Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        if (CollectionUtils.isNotEmpty(pool1)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 1);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool1 = RankService.contentSourceTypeFilter(videoSourceType, pool1, sourceType);
-        }
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -111,7 +104,7 @@ public class RankV7Strategy implements RankStrategy {
         RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV7.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

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

@@ -1,8 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
 
-import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.ContentPoolEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
@@ -107,12 +105,7 @@ public class RankV8Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        if (CollectionUtils.isNotEmpty(pool1)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 1);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool1 = RankService.contentSourceTypeFilter(videoSourceType, pool1, sourceType);
-        }
-        RankService.printSortLog(RankStrategyEnum.ArticleRankV8.getStrategy(), param.getAccountName(), "头条", pool1);
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -123,7 +116,7 @@ public class RankV8Strategy implements RankStrategy {
         RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV8.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

+ 1 - 8
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV9Strategy.java

@@ -1,8 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
 
-import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.ContentPoolEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
@@ -96,11 +94,6 @@ public class RankV9Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        if (CollectionUtils.isNotEmpty(pool1)) {
-            Integer sourceType = RankService.getAccountPoolSourceType(param.getGhId(), 1);
-            Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
-            pool1 = RankService.contentSourceTypeFilter(videoSourceType, pool1, sourceType);
-        }
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -111,7 +104,7 @@ public class RankV9Strategy implements RankStrategy {
         RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV9.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

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

@@ -122,7 +122,8 @@ public class ScoreService implements ApplicationContextAware {
                 || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV11.getStrategy())
                 || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV12.getStrategy())
                 || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV13.getStrategy())
-                || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV14.getStrategy())) {
+                || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV14.getStrategy())
+                || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV15.getStrategy())) {
             strategies.add(strategyMap.get(ScoreStrategyEnum.CATEGORY.value()));
             strategies.add(strategyMap.get(ScoreStrategyEnum.ACCOUNT_PRE_DISTRIBUTE.value()));
             strategies.add(strategyMap.get(ScoreStrategyEnum.FLOW_CTL_DECREASE.value()));