丁云鹏 11 months ago
parent
commit
66fe364fa1

+ 1 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/HttpPoolFactory.java

@@ -8,7 +8,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
  */
 public final class HttpPoolFactory {
     private static CloseableHttpClient DEFAULT =
-            HttpClientFactory.create(1000, 1000, 200, 200, 0, 1000);
+            HttpClientFactory.create(10000, 10000, 200, 200, 0, 1000);
 
     private static CloseableHttpClient AIGC =
             HttpClientFactory.create(10000, 10000, 200, 200, 0, 10000);

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

@@ -5,8 +5,6 @@ import lombok.Getter;
 import lombok.NoArgsConstructor;
 import lombok.Setter;
 
-import java.util.List;
-
 /**
  * @author dyp
  */
@@ -18,9 +16,9 @@ import java.util.List;
 public class Content {
     private String id;
     private String title;
-    private String content;
-    private String coverUrl;
-    private List<String> imageUrls;
+    // private String content;
+//    private String coverUrl;
+//    private List<String> imageUrls;
     private String producePlanName;
     /**
      * "Level4": "autoArticlePoolLevel4",
@@ -31,13 +29,13 @@ public class Content {
     private String contentPoolType; // 内容池类别
     private String crawlerChannelContentId; // 抓取内容channelContentId
     private String category; // 品类
-    private String crawlerLink;
-    private String crawlerTitle;
+    //    private String crawlerLink;
+//    private String crawlerTitle;
     private String crawlerCoverUrl;
     private Integer crawlerViewCount;
-    private Integer crawlerLikeCount;
-    private Long crawlerPublishTimestamp;
-    private String crawlerAccountName;
+    //    private Integer crawlerLikeCount;
+//    private Long crawlerPublishTimestamp;
+//    private String crawlerAccountName;
     private String filterReason;
 }
 

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

@@ -6,7 +6,6 @@ import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigSer
 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.ContentPoolStrategy;
 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.util.CommonCollectionUtils;
@@ -15,6 +14,7 @@ import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.RandomUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -47,45 +47,49 @@ public class RankService {
             return item;
 
         });
-        Collections.sort(items, (o1, o2) -> {
-            int contentPoolComparison = Double.compare(
-                    o1.getScore(ContentPoolStrategy.class.getSimpleName()),
-                    o2.getScore(ContentPoolStrategy.class.getSimpleName())
-            );
-            if (contentPoolComparison != 0) {
-                return -contentPoolComparison; // 降序
-            }
 
-            int similarityComparison = Double.compare(
-                    o1.getScore(SimilarityStrategy.class.getSimpleName()),
-                    o2.getScore(SimilarityStrategy.class.getSimpleName())
-            );
-            if (similarityComparison != 0) {
-                return -similarityComparison; // 降序
+        // 1 排序
+        String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
+        Map<String, List<RankItem>> itemMap = new HashMap<>();
+        for (RankItem c : items) {
+            List<RankItem> data = itemMap.computeIfAbsent(c.getContent().getContentPoolType(), k -> new ArrayList<>());
+            data.add(c);
+        }
+        for (Map.Entry<String, List<RankItem>> e : itemMap.entrySet()) {
+            if (StringUtils.equals(contentPools[1], e.getKey())) {
+                // 播放量排序
+                Collections.sort(e.getValue(), (o1, o2) -> -Double.compare(
+                        o1.getScore(ViewCountStrategy.class.getSimpleName()),
+                        o2.getScore(ViewCountStrategy.class.getSimpleName())));
+            } else {
+                // 相似排序
+                Collections.sort(e.getValue(), (o1, o2) -> -Double.compare(
+                        o1.getScore(SimilarityStrategy.class.getSimpleName()),
+                        o2.getScore(SimilarityStrategy.class.getSimpleName())));
             }
+        }
 
-            return Double.compare(
-                    o1.getScore(ViewCountStrategy.class.getSimpleName()),
-                    o2.getScore(ViewCountStrategy.class.getSimpleName())
-            );
-        });
 
-        log.info("RankItem sort {}", JSONUtils.toJson(items));
+        List<RankItem> sortedItems = new ArrayList<>();
+        for (String pool : contentPools) {
+            sortedItems.addAll(itemMap.get(pool));
+        }
+        List<Content> contents = CommonCollectionUtils.toList(sortedItems, RankItem::getContent);
+        log.info("Sort result {}", JSONUtils.toJson(contents));
 
-        List<Content> contents = CommonCollectionUtils.toList(items, RankItem::getContent);
-        // 1 相似去重
+        // 3 相似去重
         contents = deduplication(contents);
         log.info("Deduplication {}", JSONUtils.toJson(contents));
 
-        // 2 文章按照内容池分组
+        // 4 文章按照内容池分组
         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 按位置选文章
+        log.info("ContentMap {}", JSONUtils.toJson(contentMap));
+        // 5 按位置选文章
         List<Content> result = new ArrayList<>();
-        String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
 
         // 头
         List<Content> pool = contentMap.get(contentPools[0]);