Pārlūkot izejas kodu

Merge branch 'main'

wangyunpeng 10 mēneši atpakaļ
vecāks
revīzija
c3af661dc7

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

@@ -47,6 +47,7 @@ public class RankV5Strategy implements RankStrategy {
 
         List<RankItem> items = CommonCollectionUtils.toList(param.getContents(), c -> {
             RankItem item = new RankItem();
+            c.setHisPublishArticleList(null);
             item.setContent(c);
             item.setScoreMap(scoreMap.get(c.getId()));
             double score;

+ 14 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/strategy/PublishTimesStrategy.java

@@ -16,6 +16,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
+import java.util.function.Function;
+
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -48,7 +50,18 @@ public class PublishTimesStrategy implements ScoreStrategy {
         // 获取今日已发布内容
         String dateStr = DateUtils.getCurrentDateStr("yyyy-MM-dd");
         List<PublishSortLog> hisPublishContentList = publishSortLogRepository.findByDateStr(dateStr);
-        Map<String, List<PublishSortLog>> hisPublishedContentMap = hisPublishContentList.stream().collect(Collectors.groupingBy(PublishSortLog::getTitle));
+        Map<String, Set<PublishSortLog>> hisPublishedContentMap = hisPublishContentList.stream()
+                .collect(Collectors.groupingBy(
+                        PublishSortLog::getTitle,
+                        Collectors.collectingAndThen(
+                                Collectors.toMap(
+                                        PublishSortLog::getGhId, // 用于去重的字段,例如 id
+                                        Function.identity(),
+                                        (existing, replacement) -> existing // 如果有重复的 id,保留已有的记录
+                                ),
+                                map -> new HashSet<>(map.values()) // 将结果转换为 Set<PublishSortLog>
+                        )
+                ));
         Map<Integer, AccountPublishTimesConfig> indexPublishTimesMap = Arrays.stream(indexPublishTimesArr).collect(Collectors.toMap(AccountPublishTimesConfig::getIndex, o -> o));
         String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
         for (Content content : param.getContents()) {

+ 34 - 5
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/strategy/ViewCountRateStrategy.java

@@ -32,23 +32,52 @@ public class ViewCountRateStrategy implements ScoreStrategy {
                 if (!contentPools[i].equals(content.getContentPoolType())) {
                     continue;
                 }
-                double firstAvgViewCount = accountIndexAvgViewCountService.getAvgReadCount(param.getGhId(), i + 1);
+                double avgViewCountPos = accountIndexAvgViewCountService.getAvgReadCount(param.getGhId(), i + 1);
+                double avgViewCountFirst = accountIndexAvgViewCountService.getAvgReadCount(param.getGhId(), 1);
+                double avgViewCountSecond = accountIndexAvgViewCountService.getAvgReadCount(param.getGhId(), 2);
                 double showViewCountSum = 0D;
                 double avgViewCountSum = 0D;
+                double showViewCountSumFirst = 0D;
+                double avgViewCountSumFirst = 0D;
+                double showViewCountSumSecond = 0D;
+                double avgViewCountSumSecond = 0D;
                 for (ContentHisPublishArticle hisItem : content.getHisPublishArticleList()) {
                     if (hisItem.isInnerAccount() && hisItem.getShowViewCount() > 0 && hisItem.getAvgViewCount() > 0) {
-                        showViewCountSum += hisItem.getShowViewCount();
-                        avgViewCountSum += hisItem.getAvgViewCount();
+                        if (hisItem.getItemIndex() == 1) {
+                            showViewCountSumFirst += hisItem.getShowViewCount();
+                            avgViewCountSumFirst += hisItem.getAvgViewCount();
+                        } else if (hisItem.getItemIndex() == 2) {
+                            showViewCountSumSecond += hisItem.getShowViewCount();
+                            avgViewCountSumSecond += hisItem.getAvgViewCount();
+                        } else {
+                            showViewCountSum += hisItem.getShowViewCount();
+                            avgViewCountSum += hisItem.getAvgViewCount();
+                        }
                     }
                 }
                 double viewCountRate = 0D; // 设置默认值
+                double minRate = 5D;
+                // 如果有头条反馈数据,优先选取头条反馈数据;
+                if (showViewCountSumFirst > 0) {
+                    showViewCountSum = showViewCountSumFirst;
+                    avgViewCountSum = avgViewCountSumFirst;
+                    avgViewCountPos = avgViewCountFirst;
+                } else if (showViewCountSumSecond > 0) {
+                    showViewCountSum = showViewCountSumSecond;
+                    avgViewCountSum = avgViewCountSumSecond;
+                    avgViewCountPos = avgViewCountFirst;
+                    // 如果是大号头条,则降权
+                    if (avgViewCountFirst >= 2000 && i == 0) {
+                        minRate = 1.001D;
+                    }
+                }
                 if (avgViewCountSum > 0) {
                     viewCountRate = showViewCountSum / avgViewCountSum;
                 }
-                double viewCountRateW = MathUtils.sigmoid(avgViewCountSum, 0.0005, firstAvgViewCount);
+                double viewCountRateW = MathUtils.sigmoid(avgViewCountSum, 0.0005, avgViewCountPos);
                 double viewCountRateScore = 0;
                 if (viewCountRate > 0) {
-                    viewCountRateScore = (Math.min(viewCountRate, 5) - 1D) * viewCountRateW;
+                    viewCountRateScore = (Math.min(viewCountRate, minRate) - 1D) * viewCountRateW;
                 }
                 Score score = new Score();
                 score.setStrategy(this);