Просмотр исходного кода

无限发表策略不从第10条开始,从头开始

wangyunpeng 5 часов назад
Родитель
Сommit
3a844b012c

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

@@ -154,19 +154,17 @@ public class InfiniteRankStrategy implements RankStrategy {
         // 4 选文章
         String[] publishPool = Arrays.copyOf(contentPools, contentPools.length);
 
-        // 头 次 选取头条内容池 第11、12条内容 如果内容不足12条返回空
+        // 头 次 选取头条内容池 从上往下取前2条内容
         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) && pool1.size() >= 12) {
-            // 选取第11、12条内容
-            result.add(pool1.get(10));
-            result.add(pool1.get(11));
-        } else {
-            RankStrategy.sendFeishuFirstPoolEmpty(param, contentPools[0]);
-            return new RankResult(result);
+        if (CollectionUtils.isNotEmpty(pool1)) {
+            // 从上往下取前2条内容
+            for (int i = 0; i < Math.min(pool1.size(), 2); i++) {
+                result.add(pool1.get(i));
+            }
         }
 
         // 3-8
@@ -179,7 +177,7 @@ public class InfiniteRankStrategy implements RankStrategy {
                     .collect(Collectors.toCollection(LinkedList::new));
             Queue<Content> otherPoolQueue = pool.stream().filter(o -> !Objects.equals(o.getSourceType(), videoSourceType))
                     .collect(Collectors.toCollection(LinkedList::new));
-            for (int i = 3; i < param.getSize() + 1; i++) {
+            for (int i = result.size() + 1; i < param.getSize() + 1; i++) {
                 Integer sourceType = RankService.getStrategyPoolSourceType(param.getStrategy(), i);
                 if (Objects.equals(sourceType, videoSourceType) && !videoPoolQueue.isEmpty()) {
                     result.add(videoPoolQueue.poll());
@@ -192,6 +190,8 @@ public class InfiniteRankStrategy implements RankStrategy {
         rankService.checkPublishContentStatus(result, contentMap, publishPool);
         RankStrategy.deduplication(result, contentMap, publishPool);
 
+        result = result.subList(0, Math.min(result.size(), param.getSize()));
+
         return new RankResult(result);
     }