Bladeren bron

20260331-新增降权逻辑

luojunhui 10 uur geleden
bovenliggende
commit
f3f29b4145

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

@@ -21,6 +21,7 @@ public enum ScoreStrategyEnum {
     VIEW_COUNT("ViewCountStrategy"),
     VIEW_MULTIPLIER("ViewMultiplierStrategy"),
     CRAWLER_DAYS_DECREASE_STRATEGY("CrawlerDaysDecreaseStrategy"),
+    CRAWLER_DAYS_DECREASE_V2_STRATEGY("CrawlerDaysDecreaseV2Strategy"),
     I2I_RECOMMEND_STRATEGY("I2IRecommendStrategy"),
     ;
 

+ 2 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV21Strategy.java

@@ -76,9 +76,9 @@ public class RankV21Strategy implements RankStrategy {
                         * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
                         ScoreStrategyEnum.HIS_FISSION_OPEN_RATE.value())
                         + item.getScore(ScoreStrategyEnum.FLOW_CTL_DECREASE.value())
-                        + item.getScore(ScoreStrategyEnum.CRAWLER_DAYS_DECREASE_STRATEGY.value())
+                        + item.getScore(ScoreStrategyEnum.CRAWLER_DAYS_DECREASE_V2_STRATEGY.value())
                         * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
-                        ScoreStrategyEnum.CRAWLER_DAYS_DECREASE_STRATEGY.value());
+                        ScoreStrategyEnum.CRAWLER_DAYS_DECREASE_V2_STRATEGY.value());
                 if (item.getScore(ScoreStrategyEnum.PUBLISH_TIMES.value()) >= 0) {
                     score += item.getScore(ScoreStrategyEnum.VIEW_COUNT_RATE.value())
                             * weightService.getWeight(param.getStrategy(), param.getGhId(), index,

+ 60 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/score/strategy/CrawlerDaysDecreaseV2Strategy.java

@@ -0,0 +1,60 @@
+package com.tzld.longarticle.recommend.server.service.recommend.score.strategy;
+
+import com.tzld.longarticle.recommend.server.model.dto.Content;
+import com.tzld.longarticle.recommend.server.service.recommend.config.AccountContentPoolConfigService;
+import com.tzld.longarticle.recommend.server.service.recommend.score.Score;
+import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreParam;
+import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreStrategy;
+import com.tzld.longarticle.recommend.server.util.DateUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * 抓取时间越久,分数越负,用于抑制过老内容
+ */
+@Component
+@Slf4j
+public class CrawlerDaysDecreaseV2Strategy implements ScoreStrategy {
+
+    @Autowired
+    private AccountContentPoolConfigService accountContentPoolConfigService;
+
+    @Value("${recommend.score.crawler-days-decrease.min-score-days:7}")
+    private Double minScoreDays;
+
+
+    @Override
+    public List<Score> score(ScoreParam param) {
+        List<Score> scores = new ArrayList<>();
+        if (CollectionUtils.isEmpty(param.getContents())) {
+            return scores;
+        }
+        long now = DateUtils.getTodayStart();
+        for (Content content : param.getContents()) {
+//            String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
+//            if (!contentPools[2].equals(content.getContentPoolType())) {
+//                continue;
+//            }
+            Score score = new Score();
+            score.setStrategy(this);
+            score.setContentId(content.getId());
+            score.setScore(getContentScore(content, now));
+            scores.add(score);
+        }
+        return scores;
+    }
+
+    private Double getContentScore(Content content, long now) {
+        long timestamp = Optional.ofNullable(content.getRootPublishTimestamp()).orElse(content.getCrawlerTimestamp());
+        int days = (int) ((now - timestamp) / 86400000);
+        return -0.01 * days;
+    }
+
+}