|  | @@ -1,6 +1,7 @@
 | 
	
		
			
				|  |  |  package com.tzld.longarticle.recommend.server.service.rank;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.tzld.longarticle.recommend.server.model.Content;
 | 
	
		
			
				|  |  |  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.ScoreService;
 | 
	
	
		
			
				|  | @@ -9,14 +10,12 @@ import com.tzld.longarticle.recommend.server.service.score.strategy.ContentPoolS
 | 
	
		
			
				|  |  |  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.util.CommonCollectionUtils;
 | 
	
		
			
				|  |  | +import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import java.util.Collections;
 | 
	
		
			
				|  |  | -import java.util.Comparator;
 | 
	
		
			
				|  |  | -import java.util.List;
 | 
	
		
			
				|  |  | -import java.util.Map;
 | 
	
		
			
				|  |  | +import java.util.*;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * @author dyp
 | 
	
	
		
			
				|  | @@ -46,6 +45,22 @@ public class RankService {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |          Collections.sort(items, Comparator.comparingDouble(o -> -o.getScore()));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<Content> contents = CommonCollectionUtils.toList(items, RankItem::getContent);
 | 
	
		
			
				|  |  | +        // 1 相似去重
 | 
	
		
			
				|  |  | +        contents = deduplication(contents);
 | 
	
		
			
				|  |  | +        // 2 文章分组
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 3 按位置选文章
 | 
	
		
			
				|  |  | +        // 头条
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 次条
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 3-8
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          return new RankResult(items);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -56,4 +71,24 @@ public class RankService {
 | 
	
		
			
				|  |  |          return scoreParam;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private List<Content> deduplication(List<Content> contents) {
 | 
	
		
			
				|  |  | +        List<String> titles = new ArrayList<>();
 | 
	
		
			
				|  |  | +        List<Content> result = new ArrayList<>();
 | 
	
		
			
				|  |  | +        // 遍历所有列表
 | 
	
		
			
				|  |  | +        for (Content c : contents) {
 | 
	
		
			
				|  |  | +            if (similarity(c.getTitle(), titles)) {
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                result.add(c);
 | 
	
		
			
				|  |  | +                titles.add(c.getTitle());
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return result;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private boolean similarity(String title, List<String> titles) {
 | 
	
		
			
				|  |  | +        return TitleSimilarCheckUtil.isDuplicateContent(title, titles);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 |