Browse Source

文章品类匹配增加冷启层内容

wangyunpeng 8 months ago
parent
commit
bd0a60d475

+ 12 - 5
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/recall/RecallService.java

@@ -191,14 +191,21 @@ public class RecallService implements ApplicationContextAware {
         // 根据produceContentId查询category
         List<ArticleCategory> articleCategoryList = articleCategoryRepository.getByProduceContentIdIn(produceContentIds);
         Map<String, ArticleCategory> categoryMap = articleCategoryList.stream().collect(Collectors.toMap(ArticleCategory::getProduceContentId, Function.identity()));
+        // 冷启层直接用channelContentId查询
+        List<ArticleCategory> coldStartArticleCategoryList = articleCategoryRepository.getAllByChannelContentIdIn(channelContentIds);
+        Map<String, ArticleCategory> coldStartCategoryMap = coldStartArticleCategoryList.stream().collect(Collectors.toMap(ArticleCategory::getChannelContentId, Function.identity(), (a, b) -> a));
         for (Content content : contentList) {
             ArticlePoolPromotionSource source = sourceMap.get(content.getCrawlerChannelContentId());
+            ArticleCategory category = null;
             if (Objects.nonNull(source) && Objects.nonNull(source.getRootProduceContentId())) {
-                ArticleCategory category = categoryMap.get(source.getRootProduceContentId());
-                if (Objects.nonNull(category)) {
-                    content.setCategory(Collections.singletonList(category.getCategory()));
-                    continue;
-                }
+                category = categoryMap.get(source.getRootProduceContentId());
+            }
+            if (Objects.isNull(category)) {
+                category = coldStartCategoryMap.get(content.getCrawlerChannelContentId());
+            }
+            if (Objects.nonNull(category)) {
+                content.setCategory(Collections.singletonList(category.getCategory()));
+                continue;
             }
             log.error("setContentCategory NullError channelContentId:{}", content.getCrawlerChannelContentId());
         }

+ 6 - 2
long-article-recommend-service/src/test/java/com/tzld/longarticle/recommend/server/XxlJobTest.java

@@ -1,5 +1,6 @@
 package com.tzld.longarticle.recommend.server;
 
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
 import com.tzld.longarticle.recommend.server.mapper.longArticle.LongArticleBaseMapper;
 import com.tzld.longarticle.recommend.server.model.dto.CrawlerContent;
@@ -33,6 +34,11 @@ public class XxlJobTest {
     @Resource
     private ArticleCategoryRepository articleCategoryRepository;
 
+    @ApolloJsonValue("${cold.pool.produce.planId:[\"20240802021606053813696\", \"20240802080355355308981\",\n" +
+            "\"20240805154433785506170\", \"20240805154359027876170\", \"20241024100016206421084\", " +
+            "\"20241030070010871546586\"]}")
+    private static List<String> producePlanIds;
+
     @Test
     public void test() {
         List<String> planIds = Arrays.asList("20240804003153130851174", "20240802171417146947657", "20240802143345289374071");
@@ -58,8 +64,6 @@ public class XxlJobTest {
 
     @Test
     public void articleCategoryTest() {
-        List<String> producePlanIds = Arrays.asList("20240802021606053813696", "20240802080355355308981",
-                "20240805154433785506170", "20240805154359027876170", "20241024100016206421084", "20241030070010871546586");
         List<ProducePlanExeRecord> produceContentList = aigcBaseMapper.getAllByProducePlanId(producePlanIds);
         List<String> channelContentIds = produceContentList.stream().map(ProducePlanExeRecord::getChannelContentId).distinct().collect(Collectors.toList());
         List<ArticleCategory> articleCategoryList = articleCategoryRepository.getAllByChannelContentIdIn(channelContentIds);