Prechádzať zdrojové kódy

HistoryHighViewStrategy

wangyunpeng 6 dní pred
rodič
commit
220d226d33

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

@@ -130,6 +130,7 @@ public class FilterService {
         strategies.add(ServiceBeanFactory.getBean(TodayPublishStrategy.class));
         strategies.add(ServiceBeanFactory.getBean(OldStrategy.class));
         strategies.add(ServiceBeanFactory.getBean(CategoryFilterStrategy.class));
+        strategies.add(ServiceBeanFactory.getBean(HistoryHighViewStrategy.class));
 //        strategies.add(ServiceBeanFactory.getBean(VideoPoolBadAuditStrategy.class));
         if (param.getScene().equals(FWH_COLD_START)) {
             strategies.add(ServiceBeanFactory.getBean(HistoryTitleForFwhColdStartStrategy.class));
@@ -153,6 +154,7 @@ public class FilterService {
         strategies.add(ServiceBeanFactory.getBean(ArticlePromotionStrategy.class));
         strategies.add(ServiceBeanFactory.getBean(OldStrategy.class));
         strategies.add(ServiceBeanFactory.getBean(CategoryFilterStrategy.class));
+        strategies.add(ServiceBeanFactory.getBean(HistoryHighViewStrategy.class));
         if (param.getScene().equals(FWH_COLD_START)) {
             strategies.add(ServiceBeanFactory.getBean(HistoryTitleForFwhColdStartStrategy.class));
         } else {

+ 82 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/filter/strategy/HistoryHighViewStrategy.java

@@ -0,0 +1,82 @@
+package com.tzld.longarticle.recommend.server.service.recommend.filter.strategy;
+
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
+import com.tzld.longarticle.recommend.server.model.dto.Content;
+import com.tzld.longarticle.recommend.server.model.dto.ContentHisPublishArticle;
+import com.tzld.longarticle.recommend.server.model.entity.crawler.AccountAvgInfo;
+import com.tzld.longarticle.recommend.server.repository.crawler.AccountAvgInfoRepository;
+import com.tzld.longarticle.recommend.server.service.recommend.filter.FilterParam;
+import com.tzld.longarticle.recommend.server.service.recommend.filter.FilterResult;
+import com.tzld.longarticle.recommend.server.service.recommend.filter.FilterStrategy;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+
+@Component
+@Slf4j
+public class HistoryHighViewStrategy implements FilterStrategy {
+
+    @Autowired
+    AccountAvgInfoRepository accountAvgInfoRepository;
+
+    @Value("${filter.history-high-view-rate:0.002}")
+    private Double historyHighViewRate;
+    @ApolloJsonValue("${filter.history-high-view.account.list:[]}")
+    private List<String> historyHighViewAccountList;
+
+    /**
+     * 该账号历史已发布文章中,点击量/粉丝数 > 0.002 的文章,过滤掉
+     *
+     * @param param
+     * @return
+     */
+    @Override
+    public FilterResult filter(FilterParam param) {
+        FilterResult filterResult = new FilterResult();
+        List<String> result = new ArrayList<>(param.getContents().size());
+        List<Content> filterContents = new ArrayList<>();
+        if (!historyHighViewAccountList.contains(param.getAccountName())) {
+            result.addAll(param.getContents().stream().map(Content::getId).collect(Collectors.toList()));
+            filterResult.setContentIds(result);
+            return filterResult;
+        }
+        List<AccountAvgInfo> avgInfoList = accountAvgInfoRepository.getAllByGhIdEqualsAndStatusEquals(param.getGhId(), 1);
+        Map<String, AccountAvgInfo> avgInfoMap = avgInfoList.stream().collect(Collectors.toMap(AccountAvgInfo::getPosition, o -> o, (o1, o2) -> o2));
+        AccountAvgInfo info = avgInfoMap.get("1");
+        Integer fans = Objects.nonNull(info) ? info.getFans() : null;
+        for (Content content : param.getContents()) {
+            List<ContentHisPublishArticle> historyArticleList = content.getHisPublishArticleList();
+            if (CollectionUtils.isNotEmpty(historyArticleList)) {
+                boolean filter = false;
+                for (ContentHisPublishArticle article : historyArticleList) {
+                    if (article.getGhId().equals(param.getGhId()) && article.getItemIndex() == 1) {
+                        if (article.getViewCount() / (double) (Objects.nonNull(fans) ? fans : article.getFans()) > historyHighViewRate) {
+                            content.setFilterReason("历史已发布高阅读率文章");
+                            filterContents.add(content);
+                            filter = true;
+                            break;
+                        }
+                    }
+                }
+                if (!filter) {
+                    result.add(content.getId());
+                }
+            } else {
+                result.add(content.getId());
+            }
+        }
+        filterResult.setContentIds(result);
+        filterResult.setFilterContent(filterContents);
+        return filterResult;
+    }
+
+}

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

@@ -1,6 +1,5 @@
 package com.tzld.longarticle.recommend.server.service.recommend.filter.strategy;
 
-import com.tzld.longarticle.recommend.server.common.ThreadPoolFactory;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
 import com.tzld.longarticle.recommend.server.model.entity.crawler.Article;
 import com.tzld.longarticle.recommend.server.remote.ArticleListRemoteService;
@@ -13,10 +12,10 @@ import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.util.*;
-import java.util.concurrent.ExecutorService;
 import java.util.stream.Collectors;
 
 /**
@@ -34,7 +33,8 @@ public class HistoryTitleStrategy implements FilterStrategy {
     private static final List<Integer> firstSecondIndex = Arrays.asList(1, 2);
     private static final List<Integer> allIndex = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8);
 
-    private final ExecutorService pool = ThreadPoolFactory.deDuplicatePool();
+    @Value("${filter.history-title-filter-first-day:60}")
+    private Integer historyTitleFilterFirstDay;
 
     @Override
     public FilterResult filter(FilterParam param) {
@@ -43,7 +43,7 @@ public class HistoryTitleStrategy implements FilterStrategy {
         List<Content> filterContents = new ArrayList<>();
         List<Article> allArticleList = articleListRemoteService.articleList(param.getGhId(), allIndex, param.getType());
         List<String> allTitleList = allArticleList.stream().map(Article::getTitle).distinct().collect(Collectors.toList());
-        Long publishTimestampFilter = DateUtils.getBeforeDayStart(60);
+        Long publishTimestampFilter = DateUtils.getBeforeDayStart(historyTitleFilterFirstDay);
         List<String> firstSecondTitleList = allArticleList.stream()
                 .filter(article -> firstSecondIndex.contains(article.getItemIndex())
                         && article.getPublishTimestamp() > publishTimestampFilter)