丁云鹏 10 달 전
부모
커밋
aa07f162b4

+ 6 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/Content.java

@@ -22,6 +22,12 @@ public class Content {
     private String coverUrl;
     private String coverUrl;
     private List<String> imageUrls;
     private List<String> imageUrls;
     private String producePlanName;
     private String producePlanName;
+    /**
+     * "Level4": "autoArticlePoolLevel4",
+     * "Level3": "autoArticlePoolLevel3",
+     * "Level2": "autoArticlePoolLevel2",
+     * "Level1": "autoArticlePoolLevel1"
+     */
     private String contentPoolType; // 内容池类别
     private String contentPoolType; // 内容池类别
     private String crawlerChannelContentId; // 抓取内容channelContentId
     private String crawlerChannelContentId; // 抓取内容channelContentId
     private String category; // 品类
     private String category; // 品类

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

@@ -12,4 +12,5 @@ import java.util.List;
 public class RankParam {
 public class RankParam {
     private String accountName;
     private String accountName;
     private List<Content> contents;
     private List<Content> contents;
+    private int size;
 }
 }

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

@@ -2,6 +2,7 @@ package com.tzld.longarticle.recommend.server.service.rank;
 
 
 
 
 import com.tzld.longarticle.recommend.server.model.Content;
 import com.tzld.longarticle.recommend.server.model.Content;
+import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfig;
 import com.tzld.longarticle.recommend.server.service.score.ScoreParam;
 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.ScoreResult;
 import com.tzld.longarticle.recommend.server.service.score.ScoreService;
 import com.tzld.longarticle.recommend.server.service.score.ScoreService;
@@ -12,6 +13,8 @@ import com.tzld.longarticle.recommend.server.service.score.strategy.ViewCountStr
 import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
 import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
 import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
 import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.RandomUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
@@ -29,8 +32,8 @@ public class RankService {
 
 
     public RankResult rank(RankParam param) {
     public RankResult rank(RankParam param) {
 
 
-        ScoreResult result = scoreService.score(convertToScoreParam(param));
-        Map<String, Map<Class<? extends ScoreStrategy>, Double>> scoreMap = result.getScoreMap();
+        ScoreResult scoreResult = scoreService.score(convertToScoreParam(param));
+        Map<String, Map<Class<? extends ScoreStrategy>, Double>> scoreMap = scoreResult.getScoreMap();
 
 
         List<RankItem> items = CommonCollectionUtils.toList(param.getContents(), c -> {
         List<RankItem> items = CommonCollectionUtils.toList(param.getContents(), c -> {
             Map<Class<? extends ScoreStrategy>, Double> map = scoreMap.get(c.getId());
             Map<Class<? extends ScoreStrategy>, Double> map = scoreMap.get(c.getId());
@@ -50,13 +53,44 @@ public class RankService {
         List<Content> contents = CommonCollectionUtils.toList(items, RankItem::getContent);
         List<Content> contents = CommonCollectionUtils.toList(items, RankItem::getContent);
         // 1 相似去重
         // 1 相似去重
         contents = deduplication(contents);
         contents = deduplication(contents);
-        // 2 文章分组
+        // 2 文章按照内容池分组
+        Map<String, List<Content>> contentMap = new HashMap<>();
+        for (Content c : contents) {
+            List<Content> data = contentMap.computeIfAbsent(c.getContentPoolType(), k -> new ArrayList<>());
+            data.add(c);
+        }
+        // 3 按位置选文章
+        List<Content> result = new ArrayList<>();
+        AccountContentPoolConfig config = null;
+        String[] contentPools = config.getContentPools();
 
 
+        // 头
+        List<Content> pool = contentMap.get(contentPools[0]);
+        if (CollectionUtils.isNotEmpty(pool)) {
+            result.add(pool.get(RandomUtils.nextInt(0, Math.min(pool.size(), 5))));
+        }
 
 
-        // 3 按位置选文章
-        // 头条
+        // 次
+        pool = contentMap.get(contentPools[1]);
+        if (CollectionUtils.isNotEmpty(pool)) {
+            result.add(pool.get(0));
+            if (result.size() == 1 && pool.size() > 1) {
+                result.add(pool.get(1));
+            }
+        }
+
+        // 3-8
+        pool = contentMap.get(contentPools[1]);
+        if (CollectionUtils.isNotEmpty(pool)) {
+            if (pool.size() == 1) {
+                result.add(pool.get(0));
+            } else {
+                result.add(pool.get(0));
+                result.add(pool.get(1));
+            }
+        }
 
 
-        // 次条
+        // 其他
 
 
         // 3-8
         // 3-8