ソースを参照

filter reason

wangyunpeng 11 ヶ月 前
コミット
ff68aaf030
12 ファイル変更65 行追加48 行削除
  1. 3 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/RecommendService.java
  2. 2 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/FilterResult.java
  3. 19 16
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/FilterService.java
  4. 1 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/FilterStrategy.java
  5. 10 2
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/strategy/BadStrategy.java
  6. 5 5
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/strategy/CategoryStrategy.java
  7. 5 4
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/strategy/DuplicateStrategy.java
  8. 10 2
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/strategy/HistoryTitleStrategy.java
  9. 1 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recall/RecallResult.java
  10. 1 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recall/RecallService.java
  11. 1 5
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recall/RecallStrategy.java
  12. 7 8
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recall/strategy/DefaultRecallStrategy.java

+ 3 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/RecommendService.java

@@ -44,8 +44,11 @@ public class RecommendService {
         // MergeResult mergeResult = mergeService.merge(convertToMergeParam(param, rankResult));
 
         List<Content> contentList = rankResult.getContents().stream().map(RankItem::getContent).collect(Collectors.toList());
+        List<Content> filterContentList = new ArrayList<>();
+        recallResult.getData().forEach(item -> filterContentList.addAll(item.getFilterContents()));
         ArticleSortResponseData data = new ArticleSortResponseData();
         data.setRank_list(contentList);
+        data.setFilter_list(filterContentList);
 
         RecommendResponse response = new RecommendResponse();
         response.setCode(0);

+ 2 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/FilterResult.java

@@ -1,5 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.filter;
 
+import com.tzld.longarticle.recommend.server.model.Content;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
@@ -14,4 +15,5 @@ import java.util.List;
 @AllArgsConstructor
 public class FilterResult {
     private List<String> contentIds;
+    private List<Content> filterContent;
 }

+ 19 - 16
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/FilterService.java

@@ -12,7 +12,6 @@ import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
@@ -26,18 +25,17 @@ public class FilterService {
     private final ExecutorService pool = ThreadPoolFactory.filterPool();
 
     public FilterResult filter(FilterParam param) {
-        List<String> contentIds = contentFilter(param);
-
-        return new FilterResult(contentIds);
+        return contentFilter(param);
     }
 
-    private List<String> contentFilter(FilterParam param) {
+    private FilterResult contentFilter(FilterParam param) {
+        FilterResult result = new FilterResult();
 
         List<FilterStrategy> strategies = getStrategies(param);
         CountDownLatch cdl = new CountDownLatch(strategies.size());
-        List<Future<List<String>>> futures = new ArrayList<>();
+        List<Future<FilterResult>> futures = new ArrayList<>();
         for (final FilterStrategy strategy : strategies) {
-            Future<List<String>> future = pool.submit(() -> {
+            Future<FilterResult> future = pool.submit(() -> {
                 try {
                     return strategy.filter(param);
                 } finally {
@@ -53,22 +51,27 @@ public class FilterService {
             return null;
         }
 
-        List<List<String>> contentIds = new ArrayList<>();
-        for (Future<List<String>> f : futures) {
+        List<List<String>> contentIdsList = new ArrayList<>();
+        List<Content> filterContents = new ArrayList<>();
+        for (Future<FilterResult> f : futures) {
             try {
-                contentIds.add(f.get());
+                FilterResult filterResult = f.get();
+                contentIdsList.add(filterResult.getContentIds());
+                filterContents.addAll(filterResult.getFilterContent());
             } catch (Exception e) {
                 log.error("future get error ", e);
             }
         }
-        if (CollectionUtils.isEmpty(contentIds)) {
-            return Collections.emptyList();
+        if (CollectionUtils.isEmpty(contentIdsList)) {
+            return result;
         }
-        List<String> result = param.getContents().stream().map(Content::getId).collect(Collectors.toList());
-        for (int i = 0; i < contentIds.size(); ++i) {
-            result.retainAll(contentIds.get(i));
+        List<String> contentIds = param.getContents().stream().map(Content::getId).collect(Collectors.toList());
+        for (int i = 0; i < contentIdsList.size(); ++i) {
+            contentIds.retainAll(contentIdsList.get(i));
         }
-        return null;
+        result.setContentIds(contentIds);
+        result.setFilterContent(filterContents);
+        return result;
     }
 
     private List<FilterStrategy> getStrategies(FilterParam param) {

+ 1 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/FilterStrategy.java

@@ -1,8 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.filter;
 
 
-import java.util.List;
-
 public interface FilterStrategy {
-    List<String> filter(FilterParam param);
+    FilterResult filter(FilterParam param);
 }

+ 10 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/strategy/BadStrategy.java

@@ -3,6 +3,7 @@ package com.tzld.longarticle.recommend.server.service.filter.strategy;
 import com.tzld.longarticle.recommend.server.model.Content;
 import com.tzld.longarticle.recommend.server.remote.AIGCRemoteService;
 import com.tzld.longarticle.recommend.server.service.filter.FilterParam;
+import com.tzld.longarticle.recommend.server.service.filter.FilterResult;
 import com.tzld.longarticle.recommend.server.service.filter.FilterStrategy;
 import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -48,15 +49,22 @@ public class BadStrategy  implements FilterStrategy {
     }
 
     @Override
-    public List<String> filter(FilterParam param) {
+    public FilterResult filter(FilterParam param) {
+        FilterResult filterResult = new FilterResult();
         List<String> result = new ArrayList<>();
         List<Content> contents  = param.getContents();
+        List<Content> filterContents  = new ArrayList<>();
         for (Content content : contents) {
             if (!TitleSimilarCheckUtil.isDuplicateContent(content.getTitle(), badTitles)) {
                 result.add(content.getId());
+            } else {
+                content.setFilterReason("历史表现差的文章");
+                filterContents.add(content);
             }
         }
-        return result;
+        filterResult.setContentIds(result);
+        filterResult.setFilterContent(filterContents);
+        return filterResult;
     }
 
 }

+ 5 - 5
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/strategy/CategoryStrategy.java

@@ -2,14 +2,13 @@ package com.tzld.longarticle.recommend.server.service.filter.strategy;
 
 import com.tzld.longarticle.recommend.server.model.Content;
 import com.tzld.longarticle.recommend.server.service.filter.FilterParam;
+import com.tzld.longarticle.recommend.server.service.filter.FilterResult;
 import com.tzld.longarticle.recommend.server.service.filter.FilterStrategy;
 import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
-import java.util.List;
-
 /**
  * @author dyp
  */
@@ -20,9 +19,10 @@ public class CategoryStrategy implements FilterStrategy {
     private String aaa;
 
     @Override
-    public List<String> filter(FilterParam param) {
-
-        return CommonCollectionUtils.toList(param.getContents(), Content::getId);
+    public FilterResult filter(FilterParam param) {
+        FilterResult filterResult = new FilterResult();
+        filterResult.setContentIds(CommonCollectionUtils.toList(param.getContents(), Content::getId));
+        return filterResult;
     }
 
 }

+ 5 - 4
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/strategy/DuplicateStrategy.java

@@ -2,13 +2,12 @@ package com.tzld.longarticle.recommend.server.service.filter.strategy;
 
 import com.tzld.longarticle.recommend.server.model.Content;
 import com.tzld.longarticle.recommend.server.service.filter.FilterParam;
+import com.tzld.longarticle.recommend.server.service.filter.FilterResult;
 import com.tzld.longarticle.recommend.server.service.filter.FilterStrategy;
 import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
-import java.util.List;
-
 /**
  * @author dyp
  */
@@ -17,8 +16,10 @@ import java.util.List;
 public class DuplicateStrategy implements FilterStrategy {
 
     @Override
-    public List<String> filter(FilterParam param) {
-        return CommonCollectionUtils.toList(param.getContents(), Content::getId);
+    public FilterResult filter(FilterParam param) {
+        FilterResult filterResult = new FilterResult();
+        filterResult.setContentIds(CommonCollectionUtils.toList(param.getContents(), Content::getId));
+        return filterResult;
     }
 
 }

+ 10 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/strategy/HistoryTitleStrategy.java

@@ -6,6 +6,7 @@ import com.tzld.longarticle.recommend.server.model.remote.Article;
 import com.tzld.longarticle.recommend.server.remote.ArticleListRemoteService;
 import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfig;
 import com.tzld.longarticle.recommend.server.service.filter.FilterParam;
+import com.tzld.longarticle.recommend.server.service.filter.FilterResult;
 import com.tzld.longarticle.recommend.server.service.filter.FilterStrategy;
 import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -36,8 +37,10 @@ public class HistoryTitleStrategy implements FilterStrategy {
     private List<AccountContentPoolConfig> accountContentPoolConfigList;
 
     @Override
-    public List<String> filter(FilterParam param) {
+    public FilterResult filter(FilterParam param) {
+        FilterResult filterResult = new FilterResult();
         List<String> result = new ArrayList<>();
+        List<Content> filterContents  = new ArrayList<>();
         List<Article> firstSecondArticleList = articleListRemoteService.articleList(param.getAccountName(), firstSecondIndex);
         List<String> firstSecondTitleList = firstSecondArticleList.stream().map(Article::getTitle).collect(Collectors.toList());
         List<Article> allArticleList = articleListRemoteService.articleList(param.getAccountName(), allIndex);
@@ -61,9 +64,14 @@ public class HistoryTitleStrategy implements FilterStrategy {
             }
             if (!isDuplicate) {
                 result.add(content.getId());
+            } else {
+                content.setFilterReason("历史已发布文章");
+                filterContents.add(content);
             }
         }
-        return result;
+        filterResult.setContentIds(result);
+        filterResult.setFilterContent(filterContents);
+        return filterResult;
     }
 
     private AccountContentPoolConfig getContentPoolConfig(String accountName) {

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

@@ -21,6 +21,7 @@ public class RecallResult {
     @NoArgsConstructor
     public static class RecallData {
         private List<Content> contents;
+        private List<Content> filterContents;
     }
 
 

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

@@ -1,7 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.recall;
 
 import com.tzld.longarticle.recommend.server.common.ThreadPoolFactory;
-import com.tzld.longarticle.recommend.server.model.Content;
 import com.tzld.longarticle.recommend.server.service.recall.strategy.DefaultRecallStrategy;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeansException;
@@ -46,8 +45,7 @@ public class RecallService implements ApplicationContextAware {
         for (final RecallStrategy strategy : strategies) {
             Future<RecallResult.RecallData> future = pool.submit(() -> {
                 try {
-                    List<Content> result = strategy.recall(param);
-                    return new RecallResult.RecallData(result);
+                    return strategy.recall(param);
                 } finally {
                     cdl.countDown();
                 }

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

@@ -1,12 +1,8 @@
 package com.tzld.longarticle.recommend.server.service.recall;
 
-import com.tzld.longarticle.recommend.server.model.Content;
-
-import java.util.List;
-
 /**
  * @author dyp
  */
 public interface RecallStrategy {
-    List<Content> recall(RecallParam param);
+    RecallResult.RecallData recall(RecallParam param);
 }

+ 7 - 8
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recall/strategy/DefaultRecallStrategy.java

@@ -5,10 +5,7 @@ import com.tzld.longarticle.recommend.server.remote.AIGCRemoteService;
 import com.tzld.longarticle.recommend.server.service.filter.FilterParam;
 import com.tzld.longarticle.recommend.server.service.filter.FilterResult;
 import com.tzld.longarticle.recommend.server.service.filter.FilterService;
-import com.tzld.longarticle.recommend.server.service.recall.ContentCategory;
-import com.tzld.longarticle.recommend.server.service.recall.FilterParamFactory;
-import com.tzld.longarticle.recommend.server.service.recall.RecallParam;
-import com.tzld.longarticle.recommend.server.service.recall.RecallStrategy;
+import com.tzld.longarticle.recommend.server.service.recall.*;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
@@ -34,7 +31,7 @@ public class DefaultRecallStrategy implements RecallStrategy {
     NamedParameterJdbcTemplate piaoquanCrawlerJdbcTemplate;
 
     @Override
-    public List<Content> recall(RecallParam param) {
+    public RecallResult.RecallData recall(RecallParam param) {
 
         List<Content> content = aigcRemoteService.getAllContent(param);
         // category 查询
@@ -43,9 +40,11 @@ public class DefaultRecallStrategy implements RecallStrategy {
         FilterParam filterParam = FilterParamFactory.create(param, content);
         FilterResult filterResult = filterService.filter(filterParam);
         // 处理 content
-
-        return content.stream().filter(o -> !filterResult.getContentIds().contains(o.getId()))
-                .collect(Collectors.toList());
+        RecallResult.RecallData result = new RecallResult.RecallData();
+        result.setContents(content.stream().filter(o -> !filterResult.getContentIds().contains(o.getId()))
+                .collect(Collectors.toList()));
+        result.setFilterContents(filterResult.getFilterContent());
+        return result;
     }
 
     private void setContentCategory(List<Content> contentList) {