|
|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|