Browse Source

ADD:PushFromIndex

sunxy 11 months ago
parent
commit
a2a78acb58

+ 32 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/RankService.java

@@ -97,6 +97,9 @@ public class RankService {
             return new RankResult(results);
         }
 
+        // 给所有重复视频打上多个召回源标记
+        tagDuplicateVideos(param);
+
         // 2 正常走分发 排序+冷启动
         List<Video> rovRecallRank = mergeAndRankRovRecall(param);
         List<Video> flowPoolRank = mergeAndRankFlowPoolRecall(param);
@@ -110,6 +113,35 @@ public class RankService {
         return mergeAndSort(param, rovRecallRank, flowPoolRank);
     }
 
+    private void tagDuplicateVideos(RankParam param) {
+        if (CollectionUtils.isEmpty(param.getRecallResult().getData())) {
+            return;
+        }
+        Map<Long, Set<String>> videoIdPushFromMap = new HashMap<>();
+        for (RecallResult.RecallData data : param.getRecallResult().getData()) {
+            if (CollectionUtils.isEmpty(data.getVideos())) {
+                continue;
+            }
+            for (Video video : data.getVideos()) {
+                Set<String> pushFromSet = videoIdPushFromMap.computeIfAbsent(video.getVideoId(), k -> new HashSet<>());
+                pushFromSet.add(data.getPushFrom());
+            }
+        }
+        for (RecallResult.RecallData data : param.getRecallResult().getData()) {
+            if (CollectionUtils.isEmpty(data.getVideos())) {
+                continue;
+            }
+            for (Video video : data.getVideos()) {
+                Set<String> pushFromSet = videoIdPushFromMap.get(video.getVideoId());
+                if (pushFromSet != null && pushFromSet.size() > 1) {
+                    Map<String, List<String>> map = new HashMap<>();
+                    pushFromSet.forEach(p -> map.computeIfAbsent(p, k -> new ArrayList<>()));
+                    video.setPushFromIndex(map);
+                }
+            }
+        }
+    }
+
     public void rankFilter(RankParam param, List<Video> rovRecallRank, List<Video> flowPoolRank) {
     }