|
@@ -1,21 +1,19 @@
|
|
|
package com.tzld.longarticle.recommend.server.service.rank.strategy;
|
|
package com.tzld.longarticle.recommend.server.service.rank.strategy;
|
|
|
|
|
|
|
|
|
|
|
|
|
-import com.tzld.longarticle.recommend.server.common.enums.ContentPoolEnum;
|
|
|
|
|
import com.tzld.longarticle.recommend.server.model.Content;
|
|
import com.tzld.longarticle.recommend.server.model.Content;
|
|
|
import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigService;
|
|
import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigService;
|
|
|
import com.tzld.longarticle.recommend.server.service.rank.RankItem;
|
|
import com.tzld.longarticle.recommend.server.service.rank.RankItem;
|
|
|
import com.tzld.longarticle.recommend.server.service.rank.RankParam;
|
|
import com.tzld.longarticle.recommend.server.service.rank.RankParam;
|
|
|
import com.tzld.longarticle.recommend.server.service.rank.RankResult;
|
|
import com.tzld.longarticle.recommend.server.service.rank.RankResult;
|
|
|
import com.tzld.longarticle.recommend.server.service.rank.RankStrategy;
|
|
import com.tzld.longarticle.recommend.server.service.rank.RankStrategy;
|
|
|
-import com.tzld.longarticle.recommend.server.service.score.ScoreParam;
|
|
|
|
|
import com.tzld.longarticle.recommend.server.service.score.ScoreResult;
|
|
import com.tzld.longarticle.recommend.server.service.score.ScoreResult;
|
|
|
import com.tzld.longarticle.recommend.server.service.score.ScoreService;
|
|
import com.tzld.longarticle.recommend.server.service.score.ScoreService;
|
|
|
import com.tzld.longarticle.recommend.server.service.score.strategy.SimilarityStrategy;
|
|
import com.tzld.longarticle.recommend.server.service.score.strategy.SimilarityStrategy;
|
|
|
import com.tzld.longarticle.recommend.server.service.score.strategy.ViewCountStrategy;
|
|
import com.tzld.longarticle.recommend.server.service.score.strategy.ViewCountStrategy;
|
|
|
import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
|
|
import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
|
|
|
import com.tzld.longarticle.recommend.server.util.JSONUtils;
|
|
import com.tzld.longarticle.recommend.server.util.JSONUtils;
|
|
|
-import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
|
|
|
|
|
|
|
+import com.tzld.longarticle.recommend.server.util.feishu.FeishuMessageSender;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
@@ -37,9 +35,9 @@ public class DefaultRankStrategy implements RankStrategy {
|
|
|
private AccountContentPoolConfigService accountContentPoolConfigService;
|
|
private AccountContentPoolConfigService accountContentPoolConfigService;
|
|
|
|
|
|
|
|
public RankResult rank(RankParam param) {
|
|
public RankResult rank(RankParam param) {
|
|
|
-
|
|
|
|
|
|
|
+ List<Content> result = new ArrayList<>();
|
|
|
//log.info("RankParam {}", JSONUtils.toJson(param));
|
|
//log.info("RankParam {}", JSONUtils.toJson(param));
|
|
|
- ScoreResult scoreResult = scoreService.score(convertToScoreParam(param));
|
|
|
|
|
|
|
+ ScoreResult scoreResult = scoreService.score(RankStrategy.convertToScoreParam(param));
|
|
|
//log.info("ScoreResult {}", JSONUtils.toJson(scoreResult));
|
|
//log.info("ScoreResult {}", JSONUtils.toJson(scoreResult));
|
|
|
|
|
|
|
|
Map<String, Map<String, Double>> scoreMap = scoreResult.getScoreMap();
|
|
Map<String, Map<String, Double>> scoreMap = scoreResult.getScoreMap();
|
|
@@ -82,6 +80,12 @@ public class DefaultRankStrategy implements RankStrategy {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 相似度评分为0 报警返回
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(items) && items.get(0).getScoreMap().get(SimilarityStrategy.class.getSimpleName()) == 0) {
|
|
|
|
|
+ FeishuMessageSender.sendWebHookMessage("eca8eee2-33bc-4532-9be1-4ce427cff5fa", param.getAccountName() + " 内容评分为0");
|
|
|
|
|
+ return new RankResult(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
log.info("Sort result {}", JSONUtils.toJson(sortedItems));
|
|
log.info("Sort result {}", JSONUtils.toJson(sortedItems));
|
|
|
List<Content> contents = CommonCollectionUtils.toList(sortedItems, RankItem::getContent);
|
|
List<Content> contents = CommonCollectionUtils.toList(sortedItems, RankItem::getContent);
|
|
|
|
|
|
|
@@ -98,13 +102,12 @@ public class DefaultRankStrategy implements RankStrategy {
|
|
|
}
|
|
}
|
|
|
log.info("ContentMap {}", JSONUtils.toJson(contentMap));
|
|
log.info("ContentMap {}", JSONUtils.toJson(contentMap));
|
|
|
// 5 按位置选文章
|
|
// 5 按位置选文章
|
|
|
- List<Content> result = new ArrayList<>();
|
|
|
|
|
-
|
|
|
|
|
// 头
|
|
// 头
|
|
|
List<Content> pool = contentMap.get(contentPools[0]);
|
|
List<Content> pool = contentMap.get(contentPools[0]);
|
|
|
if (CollectionUtils.isNotEmpty(pool)) {
|
|
if (CollectionUtils.isNotEmpty(pool)) {
|
|
|
result.add(pool.get(RandomUtils.nextInt(0, Math.min(pool.size(), 5))));
|
|
result.add(pool.get(RandomUtils.nextInt(0, Math.min(pool.size(), 5))));
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ FeishuMessageSender.sendWebHookMessage("eca8eee2-33bc-4532-9be1-4ce427cff5fa", param.getAccountName() + " 内容池1为空");
|
|
|
return new RankResult(result);
|
|
return new RankResult(result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -129,31 +132,4 @@ public class DefaultRankStrategy implements RankStrategy {
|
|
|
return new RankResult(result);
|
|
return new RankResult(result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private ScoreParam convertToScoreParam(RankParam param) {
|
|
|
|
|
- ScoreParam scoreParam = new ScoreParam();
|
|
|
|
|
- scoreParam.setGhId(param.getGhId());
|
|
|
|
|
- scoreParam.setAccountName(param.getAccountName());
|
|
|
|
|
- scoreParam.setContents(param.getContents());
|
|
|
|
|
- return scoreParam;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private List<Content> deduplication(List<Content> contents) {
|
|
|
|
|
- List<String> titles = new ArrayList<>();
|
|
|
|
|
- List<Content> result = new ArrayList<>();
|
|
|
|
|
- // 遍历所有列表
|
|
|
|
|
- for (String contentPool : ContentPoolEnum.getOrderContentPool()) {
|
|
|
|
|
- for (Content c : contents) {
|
|
|
|
|
- if (!contentPool.equals(c.getContentPoolType())) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- if (!TitleSimilarCheckUtil.isDuplicateContent(c.getTitle(), titles)) {
|
|
|
|
|
- result.add(c);
|
|
|
|
|
- titles.add(c.getTitle());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|