|
|
@@ -75,14 +75,14 @@ public class HeadCate2AndChannelRovRecallStrategy implements RecallStrategy {
|
|
|
|
|
|
Map<String, Map<String, Double>> recallVideoMap = this.cate2Recall(new ArrayList<>(mergeCate2Pair.keySet()), channelName);
|
|
|
|
|
|
- // 过滤
|
|
|
- Map<Long, Double> scoresMap = new HashMap<>();
|
|
|
+ // 预算 scoresMap (按 mergeCate2Pair 顺序,同 vid 取首次出现的 cateScore*videoScore,业务原顺序)
|
|
|
+ Map<Long, Double> scoresMap = new LinkedHashMap<>();
|
|
|
for (Map.Entry<String, Double> entry : mergeCate2Pair.entrySet()) {
|
|
|
Double cateScore = entry.getValue();
|
|
|
Map<String, Double> videoMap = recallVideoMap.getOrDefault(entry.getKey(), new HashMap<>());
|
|
|
for (Map.Entry<String, Double> v : videoMap.entrySet()) {
|
|
|
long vid = Long.parseLong(v.getKey());
|
|
|
- scoresMap.merge(vid, cateScore * v.getValue(), Math::max);
|
|
|
+ scoresMap.putIfAbsent(vid, cateScore * v.getValue());
|
|
|
}
|
|
|
}
|
|
|
List<Long> allVid = new ArrayList<>(scoresMap.keySet());
|
|
|
@@ -92,34 +92,15 @@ public class HeadCate2AndChannelRovRecallStrategy implements RecallStrategy {
|
|
|
Set<Long> filterVids = new HashSet<>(filterResult.getVideoIds());
|
|
|
filterVids.remove(param.getVideoId());
|
|
|
|
|
|
- Set<Long> hit = new HashSet<>();
|
|
|
- for (Map.Entry<String, Double> entry : mergeCate2Pair.entrySet()) {
|
|
|
- String cate = entry.getKey();
|
|
|
- Double cateScore = entry.getValue();
|
|
|
-
|
|
|
- Map<String, Double> videoMap = recallVideoMap.getOrDefault(cate, new HashMap<>());
|
|
|
- for (Map.Entry<String, Double> videoEntry : videoMap.entrySet()) {
|
|
|
- long vid = Long.parseLong(videoEntry.getKey());
|
|
|
-
|
|
|
- // 过滤之后不存在的视频,过滤掉
|
|
|
- if (!filterVids.contains(vid)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- // 去重
|
|
|
- if (hit.contains(vid)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- hit.add(vid);
|
|
|
-
|
|
|
- Double videoScore = videoEntry.getValue();
|
|
|
-
|
|
|
- Video video = new Video();
|
|
|
- video.setVideoId(vid);
|
|
|
- video.setRovScore(cateScore * videoScore);
|
|
|
- video.setPushFrom(PUSH_FROM);
|
|
|
- videoResult.add(video);
|
|
|
- }
|
|
|
-
|
|
|
+ // 按 scoresMap 的 insertion order 输出
|
|
|
+ for (Map.Entry<Long, Double> e : scoresMap.entrySet()) {
|
|
|
+ long vid = e.getKey();
|
|
|
+ if (!filterVids.contains(vid)) continue;
|
|
|
+ Video video = new Video();
|
|
|
+ video.setVideoId(vid);
|
|
|
+ video.setRovScore(e.getValue());
|
|
|
+ video.setPushFrom(PUSH_FROM);
|
|
|
+ videoResult.add(video);
|
|
|
}
|
|
|
|
|
|
videoResult.sort(Comparator.comparingDouble(o -> -o.getRovScore()));
|