|
@@ -5,12 +5,21 @@ 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;
|
|
|
+import com.tzld.longarticle.recommend.server.service.score.ScoreStrategy;
|
|
|
+import com.tzld.longarticle.recommend.server.service.score.strategy.ContentPoolStrategy;
|
|
|
+import com.tzld.longarticle.recommend.server.service.score.strategy.SimilarityStrategy;
|
|
|
import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+<<<<<<< HEAD
|
|
|
import java.util.*;
|
|
|
+=======
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+>>>>>>> 432e804 (init)
|
|
|
|
|
|
/**
|
|
|
* @author dyp
|
|
@@ -25,10 +34,43 @@ public class RankService {
|
|
|
public RankResult rank(RankParam param) {
|
|
|
|
|
|
ScoreResult result = scoreService.score(convertToScoreParam(param));
|
|
|
+ Map<String, Map<Class<? extends ScoreStrategy>, Double>> scoreMap = result.getScoreMap();
|
|
|
+
|
|
|
+ Collections.sort(param.getContents(), (o1, o2) -> {
|
|
|
+ String o1Id = o1.getId();
|
|
|
+ String o2Id = o2.getId();
|
|
|
+
|
|
|
+ double o1SimilarityScore = scoreMap.get(o1Id) != null
|
|
|
+ ? scoreMap.get(o1Id).get(SimilarityStrategy.class)
|
|
|
+ : 0.0;
|
|
|
+ double o2SimilarityScore = scoreMap.get(o2Id) != null
|
|
|
+ ? scoreMap.get(o2Id).get(SimilarityStrategy.class)
|
|
|
+ : 0.0;
|
|
|
+ if (o1SimilarityScore < o2SimilarityScore) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (o1SimilarityScore > o2SimilarityScore) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ double o1ContentPoolScore = scoreMap.get(o1Id) != null
|
|
|
+ ? scoreMap.get(o1Id).get(ContentPoolStrategy.class)
|
|
|
+ : 0.0;
|
|
|
+ double o2ContentPoolScore = scoreMap.get(o2Id) != null
|
|
|
+ ? scoreMap.get(o2Id).get(ContentPoolStrategy.class)
|
|
|
+ : 0.0;
|
|
|
+ if (o1ContentPoolScore < o2ContentPoolScore) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (o1ContentPoolScore > o2ContentPoolScore) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ });
|
|
|
|
|
|
|
|
|
- Collections.sort(items, (o1, o2) -> Double.compare(o2.getScore(), o1.getScore()));
|
|
|
- List<Content> contents = CommonCollectionUtils.toList(items, RankItem::getContent);
|
|
|
+ // 标题相似过滤
|
|
|
+ param.getContents();
|
|
|
|
|
|
return new RankResult(contents);
|
|
|
}
|