|
@@ -2,6 +2,7 @@ package com.tzld.longarticle.recommend.server.service.rank;
|
|
|
|
|
|
|
|
|
|
import com.tzld.longarticle.recommend.server.model.Content;
|
|
import com.tzld.longarticle.recommend.server.model.Content;
|
|
|
|
+import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfig;
|
|
import com.tzld.longarticle.recommend.server.service.score.ScoreParam;
|
|
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;
|
|
@@ -12,6 +13,8 @@ import com.tzld.longarticle.recommend.server.service.score.strategy.ViewCountStr
|
|
import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
|
|
import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
|
|
import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
|
|
import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
+import org.apache.commons.lang3.RandomUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -29,8 +32,8 @@ public class RankService {
|
|
|
|
|
|
public RankResult rank(RankParam param) {
|
|
public RankResult rank(RankParam param) {
|
|
|
|
|
|
- ScoreResult result = scoreService.score(convertToScoreParam(param));
|
|
|
|
- Map<String, Map<Class<? extends ScoreStrategy>, Double>> scoreMap = result.getScoreMap();
|
|
|
|
|
|
+ ScoreResult scoreResult = scoreService.score(convertToScoreParam(param));
|
|
|
|
+ Map<String, Map<Class<? extends ScoreStrategy>, Double>> scoreMap = scoreResult.getScoreMap();
|
|
|
|
|
|
List<RankItem> items = CommonCollectionUtils.toList(param.getContents(), c -> {
|
|
List<RankItem> items = CommonCollectionUtils.toList(param.getContents(), c -> {
|
|
Map<Class<? extends ScoreStrategy>, Double> map = scoreMap.get(c.getId());
|
|
Map<Class<? extends ScoreStrategy>, Double> map = scoreMap.get(c.getId());
|
|
@@ -50,13 +53,44 @@ public class RankService {
|
|
List<Content> contents = CommonCollectionUtils.toList(items, RankItem::getContent);
|
|
List<Content> contents = CommonCollectionUtils.toList(items, RankItem::getContent);
|
|
// 1 相似去重
|
|
// 1 相似去重
|
|
contents = deduplication(contents);
|
|
contents = deduplication(contents);
|
|
- // 2 文章分组
|
|
|
|
|
|
+ // 2 文章按照内容池分组
|
|
|
|
+ Map<String, List<Content>> contentMap = new HashMap<>();
|
|
|
|
+ for (Content c : contents) {
|
|
|
|
+ List<Content> data = contentMap.computeIfAbsent(c.getContentPoolType(), k -> new ArrayList<>());
|
|
|
|
+ data.add(c);
|
|
|
|
+ }
|
|
|
|
+ // 3 按位置选文章
|
|
|
|
+ List<Content> result = new ArrayList<>();
|
|
|
|
+ AccountContentPoolConfig config = null;
|
|
|
|
+ String[] contentPools = config.getContentPools();
|
|
|
|
|
|
|
|
+ // 头
|
|
|
|
+ List<Content> pool = contentMap.get(contentPools[0]);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(pool)) {
|
|
|
|
+ result.add(pool.get(RandomUtils.nextInt(0, Math.min(pool.size(), 5))));
|
|
|
|
+ }
|
|
|
|
|
|
- // 3 按位置选文章
|
|
|
|
- // 头条
|
|
|
|
|
|
+ // 次
|
|
|
|
+ pool = contentMap.get(contentPools[1]);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(pool)) {
|
|
|
|
+ result.add(pool.get(0));
|
|
|
|
+ if (result.size() == 1 && pool.size() > 1) {
|
|
|
|
+ result.add(pool.get(1));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 3-8
|
|
|
|
+ pool = contentMap.get(contentPools[1]);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(pool)) {
|
|
|
|
+ if (pool.size() == 1) {
|
|
|
|
+ result.add(pool.get(0));
|
|
|
|
+ } else {
|
|
|
|
+ result.add(pool.get(0));
|
|
|
|
+ result.add(pool.get(1));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- // 次条
|
|
|
|
|
|
+ // 其他
|
|
|
|
|
|
// 3-8
|
|
// 3-8
|
|
|
|
|