Browse Source

homepage recommend

丁云鹏 1 year ago
parent
commit
5b3ddf8bd6
18 changed files with 193 additions and 267 deletions
  1. 1 0
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/model/RecommendParam.java
  2. 5 4
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/RecommendService.java
  3. 0 11
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/ThreadPoolFactory.java
  4. 0 3
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/FilterParam.java
  5. 1 1
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/FlowPoolWithLevelFilterService.java
  6. 1 1
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/FlowPoolWithLevelScoreFilterService.java
  7. 1 1
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/FlowPoolWithScoreFilterService.java
  8. 4 3
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/flowpool/FlowPoolConfigService.java
  9. 45 47
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/flowpool/FlowPoolService.java
  10. 81 73
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/RankService.java
  11. 31 0
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/FilterParamFactory.java
  12. 1 0
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/RecallParam.java
  13. 0 83
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/RecallService.java
  14. 5 8
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractFlowPoolWithLevelRecallStrategy.java
  15. 4 10
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractFlowPoolWithLevelScoreRecallStrategy.java
  16. 4 9
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractFlowPoolWithScoreRecallStrategy.java
  17. 2 4
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractRegionRecallStrategy.java
  18. 7 9
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractVideoRecallStrategy.java

+ 1 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/model/RecommendParam.java

@@ -25,4 +25,5 @@ public class RecommendParam {
     private String provinceCode;
     private String mid;
     private int size;
+    private String uid;
 }

+ 5 - 4
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/RecommendService.java

@@ -80,7 +80,6 @@ public class RecommendService {
         ab_initial_config_map.put(AppTypeEnum.LONGVIDEO.getCode(), "121");
         ab_initial_config_map.put(AppTypeEnum.LAO_HAO_KAN_VIDEO.getCode(), "074");
         ab_initial_config_map.put(AppTypeEnum.ZUI_JING_QI.getCode(), "069");
-        ab_initial_config_map.put(-1, "095-1");
     }
 
     public RecommendResponse homepageRecommend(RecommendRequest request) {
@@ -184,6 +183,7 @@ public class RecommendService {
         param.setTopK(3);
         param.setFlowPoolP(0.3);
         param.setMid(request.getMid());
+        param.setUid(request.getUid());
         param.setSize(request.getSize());
         param.setVideoId(request.getVideoId());
 
@@ -317,6 +317,7 @@ public class RecommendService {
         recallParam.setRuleKey(param.getRuleKey());
         recallParam.setMid(param.getMid());
         recallParam.setSize(param.getSize());
+        recallParam.setUid(param.getUid());
         return recallParam;
     }
 
@@ -389,13 +390,13 @@ public class RecommendService {
 
         switch (param.getFlowPoolAbtestGroup()) {
             case FlowPoolConstants.EXPERIMENTAL_FLOW_SET_LEVEL:
-                flowPoolService.updateLocalDistributeCountWithLevel(flowPoolVideos);
+                flowPoolService.updateDistributeCountWithLevel(flowPoolVideos);
                 break;
             case FlowPoolConstants.EXPERIMENTAL_FLOW_SET_LEVEL_SCORE:
-                flowPoolService.updateLocalDistributeCountWithLevelScore(flowPoolVideos);
+                flowPoolService.updateDistributeCountWithLevelScore(flowPoolVideos);
                 break;
             default:
-                flowPoolService.updateLocalDistributeCount(flowPoolVideos);
+                flowPoolService.updateDistributeCountWithScore(flowPoolVideos);
                 break;
         }
     }

+ 0 - 11
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/ThreadPoolFactory.java

@@ -26,14 +26,6 @@ public final class ThreadPoolFactory {
             new ThreadFactoryBuilder().setNameFormat("RecallService-%d").build(),
             new ThreadPoolExecutor.AbortPolicy());
 
-    public final static ExecutorService SPECIAL_REGION = new ThreadPoolExecutor(
-            4,
-            16,
-            0L, TimeUnit.SECONDS,
-            new LinkedBlockingQueue<>(1000),
-            new ThreadFactoryBuilder().setNameFormat("RecallService-%d").build(),
-            new ThreadPoolExecutor.AbortPolicy());
-
     public static ExecutorService defaultPool() {
         return DEFAULT;
     }
@@ -42,7 +34,4 @@ public final class ThreadPoolFactory {
         return RECALL;
     }
 
-    public static ExecutorService specialRegionPool() {
-        return SPECIAL_REGION;
-    }
 }

+ 0 - 3
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/FilterParam.java

@@ -12,10 +12,7 @@ import java.util.Map;
 public class FilterParam {
     private List<Long> videoIds;
     private Map<Long, String> flowPoolMap;
-    private String requestId;
     private int appType;
     private String mid;
     private String uid;
-    private String regionCode;
-    private String shieldConfig;
 }

+ 1 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/FlowPoolWithLevelFilterService.java

@@ -40,7 +40,7 @@ public class FlowPoolWithLevelFilterService extends AbstractFilterService {
                         v -> v,
                         v -> param.getFlowPoolMap().get(v)));
 
-        Map<Long, Integer> distributeCountMap = flowPoolService.getLocalDistributeCountWithLevel(flowPoolMap);
+        Map<Long, Integer> distributeCountMap = flowPoolService.getDistributeCountWithLevel(flowPoolMap);
 
         List<Long> remainVideoIds = new ArrayList<>();
         for (Long videoId : videoIds) {

+ 1 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/FlowPoolWithLevelScoreFilterService.java

@@ -40,7 +40,7 @@ public class FlowPoolWithLevelScoreFilterService extends AbstractFilterService {
                         v -> v,
                         v -> param.getFlowPoolMap().get(v)));
 
-        Map<Long, Integer> distributeCountMap = flowPoolService.getLocalDistributeCountWithLevelScore(flowPoolMap);
+        Map<Long, Integer> distributeCountMap = flowPoolService.getDistributeCountWithLevelScore(flowPoolMap);
 
         List<Long> remainVideoIds = new ArrayList<>();
         for (Long videoId : videoIds) {

+ 1 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/FlowPoolWithScoreFilterService.java

@@ -40,7 +40,7 @@ public class FlowPoolWithScoreFilterService extends AbstractFilterService {
                         v -> v,
                         v -> param.getFlowPoolMap().get(v)));
 
-        Map<Long, Integer> distributeCountMap = flowPoolService.getLocalDistributeCountWithScore(flowPoolMap);
+        Map<Long, Integer> distributeCountMap = flowPoolService.getDistributeCountWithScore(flowPoolMap);
 
         List<Long> remainVideoIds = new ArrayList<>();
         for (Long videoId : videoIds) {

+ 4 - 3
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/flowpool/FlowPoolConfigService.java

@@ -25,6 +25,7 @@ public class FlowPoolConfigService {
     @Autowired
     private RedisTemplate<String, String> redisTemplate;
 
+    // TODO 这些配置可以用配置中心么?
     // {"control_group": [], "experimental_flow_set_level": [10, 11, 12, 13, 14, 15, 16, 17], "experimental_flow_set_level_score": [9, 18]}
     private LoadingCache<String, Map<String, List<Integer>>> flowPoolConfigCache = CacheBuilder.newBuilder()
             .maximumSize(10)
@@ -46,9 +47,9 @@ public class FlowPoolConfigService {
 
     private LoadingCache<String, Map<String, Double>> levelWeightConfigCache = CacheBuilder.newBuilder()
             .maximumSize(10)
-            .refreshAfterWrite(600, TimeUnit.SECONDS)
-            .expireAfterWrite(600, TimeUnit.SECONDS)
-            .expireAfterAccess(600, TimeUnit.SECONDS)
+            .refreshAfterWrite(60, TimeUnit.SECONDS)
+            .expireAfterWrite(60, TimeUnit.SECONDS)
+            .expireAfterAccess(60, TimeUnit.SECONDS)
             .build(new CacheLoader<String, Map<String, Double>>() {
                 @Override
                 public Map<String, Double> load(String key) throws Exception {

+ 45 - 47
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/flowpool/FlowPoolService.java

@@ -41,7 +41,7 @@ public class FlowPoolService {
             LAO_HAO_KAN_VIDEO.getCode(), ZUI_JING_QI.getCode(), PIAO_QUAN_VIDEO_PLUS.getCode(), JOURNEY.getCode()};
 
 
-    public Map<Long, Integer> getLocalDistributeCountWithLevel(Map<Long, String> videoFlowPoolMap) {
+    public Map<Long, Integer> getDistributeCountWithLevel(Map<Long, String> videoFlowPoolMap) {
         if (MapUtils.isEmpty(videoFlowPoolMap)) {
             return Collections.emptyMap();
         }
@@ -56,29 +56,22 @@ public class FlowPoolService {
                         e -> e.getKey(),
                         e -> e.getValue()
                 ));
-        asyncDelLocalDistributeCountWithLevel(dirties);
+        asyncDelDistributeCountWithLevel(dirties);
 
         return result;
     }
 
-    private Map<Long, Integer> getDistributeCount(Map<Long, String> videoFlowPoolMap) {
-        // 为了保证有序
-        List<Map.Entry<Long, String>> entries =
-                videoFlowPoolMap.entrySet().stream().sorted().collect(Collectors.toList());
+    public void updateDistributeCountWithLevel(List<Video> videos) {
+        if (CollectionUtils.isEmpty(videos)) {
+            return;
+        }
+        Map<Long, String> removeMap = updateDistributeCount(videos);
 
-        List<String> keys = entries.stream()
-                .map(v -> String.format(localDistributeCountFormat, v.getKey(), v.getValue()))
-                .collect(Collectors.toList());
-        List<Integer> counts = redisTemplate.opsForValue().multiGet(keys);
+        asyncDelDistributeCountWithLevel(removeMap);
 
-        Map<Long, Integer> result = new HashMap<>();
-        for (int i = 0; i < entries.size(); i++) {
-            result.put(entries.get(i).getKey(), counts.get(i));
-        }
-        return result;
     }
 
-    private void asyncDelLocalDistributeCountWithLevel(Map<Long, String> videoFlowPoolMap) {
+    private void asyncDelDistributeCountWithLevel(Map<Long, String> videoFlowPoolMap) {
         if (MapUtils.isEmpty(videoFlowPoolMap)) {
             return;
         }
@@ -101,7 +94,7 @@ public class FlowPoolService {
         });
     }
 
-    public Map<Long, Integer> getLocalDistributeCountWithLevelScore(Map<Long, String> videoFlowPoolMap) {
+    public Map<Long, Integer> getDistributeCountWithLevelScore(Map<Long, String> videoFlowPoolMap) {
         if (MapUtils.isEmpty(videoFlowPoolMap)) {
             return Collections.emptyMap();
         }
@@ -114,12 +107,21 @@ public class FlowPoolService {
                         e -> e.getKey(),
                         e -> e.getValue()
                 ));
-        asyncDelLocalDistributeCountWithLevelScore(dirties);
+        asyncLocalDistributeCountWithLevelScore(dirties);
 
         return result;
     }
 
-    private void asyncDelLocalDistributeCountWithLevelScore(Map<Long, String> videoFlowPoolMap) {
+    public void updateDistributeCountWithLevelScore(List<Video> videos) {
+        if (CollectionUtils.isEmpty(videos)) {
+            return;
+        }
+        Map<Long, String> removeMap = updateDistributeCount(videos);
+
+        asyncLocalDistributeCountWithLevelScore(removeMap);
+    }
+
+    private void asyncLocalDistributeCountWithLevelScore(Map<Long, String> videoFlowPoolMap) {
         if (MapUtils.isEmpty(videoFlowPoolMap)) {
             return;
         }
@@ -142,7 +144,7 @@ public class FlowPoolService {
         });
     }
 
-    public Map<Long, Integer> getLocalDistributeCountWithScore(Map<Long, String> videoFlowPoolMap) {
+    public Map<Long, Integer> getDistributeCountWithScore(Map<Long, String> videoFlowPoolMap) {
         if (MapUtils.isEmpty(videoFlowPoolMap)) {
             return Collections.emptyMap();
         }
@@ -154,12 +156,19 @@ public class FlowPoolService {
                         e -> e.getKey(),
                         e -> e.getValue()
                 ));
-        asyncDelLocalDistributeCountWithScore(dirties);
-
+        asyncDelDistributeCountWithScore(dirties);
         return result;
     }
 
-    private void asyncDelLocalDistributeCountWithScore(Map<Long, String> videoFlowPoolMap) {
+    public void updateDistributeCountWithScore(List<Video> videos) {
+        if (CollectionUtils.isEmpty(videos)) {
+            return;
+        }
+        Map<Long, String> removeMap = updateDistributeCount(videos);
+        asyncDelDistributeCountWithScore(removeMap);
+    }
+
+    private void asyncDelDistributeCountWithScore(Map<Long, String> videoFlowPoolMap) {
         if (MapUtils.isEmpty(videoFlowPoolMap)) {
             return;
         }
@@ -182,14 +191,21 @@ public class FlowPoolService {
         });
     }
 
-    public void updateLocalDistributeCountWithLevel(List<Video> videos) {
-        if (CollectionUtils.isEmpty(videos)) {
-            return;
-        }
-        Map<Long, String> removeMap = updateDistributeCount(videos);
+    private Map<Long, Integer> getDistributeCount(Map<Long, String> videoFlowPoolMap) {
+        // 为了保证有序
+        List<Map.Entry<Long, String>> entries =
+                videoFlowPoolMap.entrySet().stream().sorted().collect(Collectors.toList());
 
-        asyncDelLocalDistributeCountWithLevel(removeMap);
+        List<String> keys = entries.stream()
+                .map(v -> String.format(localDistributeCountFormat, v.getKey(), v.getValue()))
+                .collect(Collectors.toList());
+        List<Integer> counts = redisTemplate.opsForValue().multiGet(keys);
 
+        Map<Long, Integer> result = new HashMap<>();
+        for (int i = 0; i < entries.size(); i++) {
+            result.put(entries.get(i).getKey(), counts.get(i));
+        }
+        return result;
     }
 
     private Map<Long, String> updateDistributeCount(List<Video> videos) {
@@ -203,22 +219,4 @@ public class FlowPoolService {
         });
         return removeMap;
     }
-
-    public void updateLocalDistributeCountWithLevelScore(List<Video> videos) {
-        if (CollectionUtils.isEmpty(videos)) {
-            return;
-        }
-        Map<Long, String> removeMap = updateDistributeCount(videos);
-
-        asyncDelLocalDistributeCountWithLevelScore(removeMap);
-    }
-
-    public void updateLocalDistributeCount(List<Video> videos) {
-        if (CollectionUtils.isEmpty(videos)) {
-            return;
-        }
-        Map<Long, String> removeMap = updateDistributeCount(videos);
-
-        asyncDelLocalDistributeCountWithScore(removeMap);
-    }
 }

+ 81 - 73
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/RankService.java

@@ -32,81 +32,10 @@ public class RankService {
         List<Video> rovRecallRank = mergeAndRankRovRecall(param);
         List<Video> flowPoolRank = mergeAndRankFlowPoolRecall(param);
 
-        // TODO 重构 rov和流量池 融合排序
-        //    去重原则:
-        //        如果视频在ROV召回池topK,则保留ROV召回池,否则保留流量池
-        // 1 rov pool topK
-        Set<Long> rovTopKVideoIds = new HashSet<>();
-        for (int i = 0; i < param.getTopK() && i < rovRecallRank.size(); i++) {
-            rovTopKVideoIds.add(rovRecallRank.get(i).getVideoId());
-        }
-
-        // 2 flow pool 移除topK视频
-        Set<Long> flowPoolVideoIds = new HashSet<>();
-        Iterator<Video> flowRecallRankIte = flowPoolRank.iterator();
-        while (flowRecallRankIte.hasNext()) {
-            Video data = flowRecallRankIte.next();
-            if (rovTopKVideoIds.contains(data.getVideoId())) {
-                flowRecallRankIte.remove();
-            } else {
-                flowPoolVideoIds.add(data.getVideoId());
-            }
-        }
-
-        // rov pool 移除flow中的视频
-        Iterator<Video> rovRecallRankIte = rovRecallRank.iterator();
-        while (rovRecallRankIte.hasNext()) {
-            Video data = rovRecallRankIte.next();
-            if (flowPoolVideoIds.contains(data.getVideoId())) {
-                rovRecallRankIte.remove();
-            }
-        }
+        removeDuplicate(param, rovRecallRank, flowPoolRank);
 
         // 融合排序
-        if (CollectionUtils.isEmpty(rovRecallRank)) {
-            if (param.getSize() < flowPoolRank.size()) {
-                return new RankResult(flowPoolRank.subList(0, param.getSize()));
-            } else {
-                return new RankResult(flowPoolRank);
-            }
-        }
-
-        List<Video> result = new ArrayList<>();
-        for (int i = 0; i < param.getTopK() && i < rovRecallRank.size(); i++) {
-            result.add(rovRecallRank.get(i));
-        }
-
-        double flowPoolP = getFlowPoolP(param);
-        int flowPoolIndex = 0;
-        int rovPoolIndex = param.getTopK() - 1;
-
-        for (int i = 0; i < param.getSize() - param.getTopK(); i++) {
-            double rand = RandomUtils.nextDouble(0, 1);
-            if (rand < flowPoolP) {
-                if (flowPoolIndex < flowPoolRank.size()) {
-                    result.add(flowPoolRank.get(flowPoolIndex++));
-                } else {
-                    break;
-                }
-            } else {
-                if (rovPoolIndex < rovRecallRank.size()) {
-                    result.add(rovRecallRank.get(rovPoolIndex++));
-                } else {
-                    break;
-                }
-            }
-        }
-        if (rovPoolIndex >= rovRecallRank.size()) {
-            for (int i = flowPoolIndex; i < flowPoolRank.size() && result.size() < param.getSize(); i++) {
-                result.add(flowPoolRank.get(i));
-            }
-        }
-        if (flowPoolIndex >= flowPoolRank.size()) {
-            for (int i = rovPoolIndex; i < rovRecallRank.size() && result.size() < param.getSize(); i++) {
-                result.add(rovRecallRank.get(i));
-            }
-        }
-        return new RankResult(result);
+        return mergeAndSort(param, rovRecallRank, flowPoolRank);
     }
 
     private List<Video> mergeAndRankRovRecall(RankParam param) {
@@ -207,4 +136,83 @@ public class RankService {
         }
     }
 
+    private void removeDuplicate(RankParam param, List<Video> rovRecallRank, List<Video> flowPoolRank) {
+        // TODO 重构 rov和流量池 融合排序
+        //    去重原则:
+        //        如果视频在ROV召回池topK,则保留ROV召回池,否则保留流量池
+        // 1 rov pool topK
+        Set<Long> rovTopKVideoIds = new HashSet<>();
+        for (int i = 0; i < param.getTopK() && i < rovRecallRank.size(); i++) {
+            rovTopKVideoIds.add(rovRecallRank.get(i).getVideoId());
+        }
+
+        // 2 flow pool 移除topK视频
+        Set<Long> flowPoolVideoIds = new HashSet<>();
+        Iterator<Video> flowRecallRankIte = flowPoolRank.iterator();
+        while (flowRecallRankIte.hasNext()) {
+            Video data = flowRecallRankIte.next();
+            if (rovTopKVideoIds.contains(data.getVideoId())) {
+                flowRecallRankIte.remove();
+            } else {
+                flowPoolVideoIds.add(data.getVideoId());
+            }
+        }
+
+        // rov pool 移除flow中的视频
+        Iterator<Video> rovRecallRankIte = rovRecallRank.iterator();
+        while (rovRecallRankIte.hasNext()) {
+            Video data = rovRecallRankIte.next();
+            if (flowPoolVideoIds.contains(data.getVideoId())) {
+                rovRecallRankIte.remove();
+            }
+        }
+    }
+
+    private RankResult mergeAndSort(RankParam param, List<Video> rovRecallRank, List<Video> flowPoolRank) {
+        if (CollectionUtils.isEmpty(rovRecallRank)) {
+            if (param.getSize() < flowPoolRank.size()) {
+                return new RankResult(flowPoolRank.subList(0, param.getSize()));
+            } else {
+                return new RankResult(flowPoolRank);
+            }
+        }
+
+        List<Video> result = new ArrayList<>();
+        for (int i = 0; i < param.getTopK() && i < rovRecallRank.size(); i++) {
+            result.add(rovRecallRank.get(i));
+        }
+
+        double flowPoolP = getFlowPoolP(param);
+        int flowPoolIndex = 0;
+        int rovPoolIndex = param.getTopK() - 1;
+
+        for (int i = 0; i < param.getSize() - param.getTopK(); i++) {
+            double rand = RandomUtils.nextDouble(0, 1);
+            if (rand < flowPoolP) {
+                if (flowPoolIndex < flowPoolRank.size()) {
+                    result.add(flowPoolRank.get(flowPoolIndex++));
+                } else {
+                    break;
+                }
+            } else {
+                if (rovPoolIndex < rovRecallRank.size()) {
+                    result.add(rovRecallRank.get(rovPoolIndex++));
+                } else {
+                    break;
+                }
+            }
+        }
+        if (rovPoolIndex >= rovRecallRank.size()) {
+            for (int i = flowPoolIndex; i < flowPoolRank.size() && result.size() < param.getSize(); i++) {
+                result.add(flowPoolRank.get(i));
+            }
+        }
+        if (flowPoolIndex >= flowPoolRank.size()) {
+            for (int i = rovPoolIndex; i < rovRecallRank.size() && result.size() < param.getSize(); i++) {
+                result.add(rovRecallRank.get(i));
+            }
+        }
+        return new RankResult(result);
+    }
+
 }

+ 31 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/FilterParamFactory.java

@@ -0,0 +1,31 @@
+package com.tzld.piaoquan.recommend.server.service.recall;
+
+import com.google.common.collect.Lists;
+import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author dyp
+ */
+public class FilterParamFactory {
+    public static FilterParam create(RecallParam param, Map<Long, String> videoFlowPoolMap) {
+        FilterParam filterParam = new FilterParam();
+        filterParam.setVideoIds(Lists.newArrayList(videoFlowPoolMap.keySet()));
+        filterParam.setAppType(param.getAppType());
+        filterParam.setMid(param.getMid());
+        filterParam.setUid(param.getUid());
+        filterParam.setFlowPoolMap(videoFlowPoolMap);
+        return filterParam;
+    }
+
+    public static FilterParam create(RecallParam param, List<Long> videoIds) {
+        FilterParam filterParam = new FilterParam();
+        filterParam.setVideoIds(videoIds);
+        filterParam.setAppType(param.getAppType());
+        filterParam.setMid(param.getMid());
+        filterParam.setUid(param.getUid());
+        return filterParam;
+    }
+}

+ 1 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/RecallParam.java

@@ -17,5 +17,6 @@ public class RecallParam {
     private int size;
     private String flowPoolAbtestGroup;
     private Long videoId;
+    private String uid;
 
 }

+ 0 - 83
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/RecallService.java

@@ -128,89 +128,6 @@ public class RecallService implements ApplicationContextAware {
         return strategies;
     }
 
-//    private RecallResult merge(List<Future<Pair<String, List<Video>>>> recallResultFutures, RecallParam param) {
-//
-//        // TODO 重构 merge sim recall and return recall
-//        Set<Long> videoIds = new HashSet<>();
-//        List<Video> datas = new ArrayList<>();
-//        if (param.getAbCode().equals("60054")
-//                || param.getAbCode().equals("60068")
-//                || param.getAbCode().equals("60081")
-//                || param.getAbCode().equals("60084")) {
-//            if (results.size() >= 2) {
-//                List<Video> region_recall = results.get(0);
-//                if (CollectionUtils.isNotEmpty(region_recall)) {
-//                    for (Video data : region_recall) {
-//                        if (!videoIds.contains(data.getVideoId())) {
-//                            datas.add(data);
-//                            videoIds.add(data.getVideoId());
-//                        }
-//                    }
-//                }
-//                List<Video> simRecall = null;
-//                List<Video> returnRecall = null;
-//                if (param.getAppType() == AppTypeEnum.LAO_HAO_KAN_VIDEO.getCode()
-//                        || param.getAppType() == AppTypeEnum.ZUI_JING_QI.getCode()) {
-//                    simRecall = results.get(1);
-//                } else {
-//                    if (results.size() >= 4) {
-//                        simRecall = results.get(3);
-//                    }
-//                    if (results.size() >= 5 && !param.getAbCode().equals("60054")) {
-//                        returnRecall = results.get(4);
-//                    }
-//                }
-//
-//                if (simRecall != null && CollectionUtils.isNotEmpty(simRecall)) {
-//                    for (Video data : simRecall) {
-//                        if (!videoIds.contains(data.getVideoId())) {
-//                            datas.add(data);
-//                            videoIds.add(data.getVideoId());
-//                        }
-//                    }
-//                }
-//
-//                if (returnRecall != null && CollectionUtils.isNotEmpty(returnRecall)) {
-//                    for (Video data : returnRecall) {
-//                        if (!videoIds.contains(data.getVideoId())) {
-//                            datas.add(data);
-//                            videoIds.add(data.getVideoId());
-//                        }
-//                    }
-//                }
-//                if (CollectionUtils.isNotEmpty(datas)) {
-//                    results.set(0, datas);
-//                }
-//            }
-//        }
-//
-//
-//        RecallResult result = new RecallResult();
-//        if (param.getAppType() == AppTypeEnum.LAO_HAO_KAN_VIDEO.getCode()
-//                || param.getAppType() == AppTypeEnum.ZUI_JING_QI.getCode()) {
-//            // TODO 可能没有这个code
-//            if (param.getAbCode().equals("30001")
-//                    || param.getAbCode().equals("30002")
-//                    || param.getAbCode().equals("80001")) {
-//                result.setRovPoolRecall(results.get(0));
-//                result.setFlowPoolRecall(results.get(1));
-//            } else {
-//                result.setRovPoolRecall(results.get(0));
-//            }
-//        } else {
-//            if (CollectionUtils.isNotEmpty(results.get(1))) {
-//                result.setQuickPool(true);
-//                result.setRovPoolRecall(results.get(0));
-//                result.setFlowPoolRecall(results.get(1));
-//
-//            } else {
-//                result.setRovPoolRecall(results.get(0));
-//                result.setFlowPoolRecall(results.get(2));
-//            }
-//        }
-//        return result;
-//    }
-
     @Override
     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
         this.applicationContext = applicationContext;

+ 5 - 8
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractFlowPoolWithLevelRecallStrategy.java

@@ -1,10 +1,9 @@
 package com.tzld.piaoquan.recommend.server.service.recall.strategy;
 
-import com.google.common.collect.Lists;
 import com.tzld.piaoquan.recommend.server.model.Video;
-import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
 import com.tzld.piaoquan.recommend.server.service.filter.FilterResult;
 import com.tzld.piaoquan.recommend.server.service.filter.FlowPoolWithLevelFilterService;
+import com.tzld.piaoquan.recommend.server.service.recall.FilterParamFactory;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallStrategy;
 import org.apache.commons.collections4.CollectionUtils;
@@ -41,15 +40,13 @@ public abstract class AbstractFlowPoolWithLevelRecallStrategy implements RecallS
         if (CollectionUtils.isEmpty(data)) {
             return null;
         }
-        Map<Long, String> videoMap = new HashMap<>();
+        Map<Long, String> videoFlowPoolMap = new HashMap<>();
         for (String value : data) {
             String[] values = value.split("-");
-            videoMap.put(NumberUtils.toLong(values[0], 0), values[1]);
+            videoFlowPoolMap.put(NumberUtils.toLong(values[0], 0), values[1]);
         }
 
-        FilterParam filterParam = new FilterParam();
-        filterParam.setVideoIds(Lists.newArrayList(videoMap.keySet()));
-        FilterResult filterResult = filterService.filter(filterParam);
+        FilterResult filterResult = filterService.filter(FilterParamFactory.create(param, videoFlowPoolMap));
 
         if (filterResult != null && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {
             filterResult.getVideoIds().stream().forEach(vid -> {
@@ -58,7 +55,7 @@ public abstract class AbstractFlowPoolWithLevelRecallStrategy implements RecallS
                 recallData.setAbCode(param.getAbCode());
                 recallData.setRovScore(RandomUtils.nextInt(0, 100));
                 recallData.setPushFrom(pushFrom());
-                recallData.setFlowPool(videoMap.get(vid));
+                recallData.setFlowPool(videoFlowPoolMap.get(vid));
                 recallData.setFlowPoolAbtestGroup(param.getFlowPoolAbtestGroup());
                 recallData.setLevel(level);
                 results.add(recallData);

+ 4 - 10
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractFlowPoolWithLevelScoreRecallStrategy.java

@@ -1,11 +1,9 @@
 package com.tzld.piaoquan.recommend.server.service.recall.strategy;
 
-import com.google.common.collect.Lists;
 import com.tzld.piaoquan.recommend.server.model.Video;
-import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
 import com.tzld.piaoquan.recommend.server.service.filter.FilterResult;
-import com.tzld.piaoquan.recommend.server.service.filter.FlowPoolWithLevelFilterService;
 import com.tzld.piaoquan.recommend.server.service.filter.FlowPoolWithLevelScoreFilterService;
+import com.tzld.piaoquan.recommend.server.service.recall.FilterParamFactory;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallStrategy;
 import org.apache.commons.collections4.CollectionUtils;
@@ -33,16 +31,14 @@ public abstract class AbstractFlowPoolWithLevelScoreRecallStrategy implements Re
         String flowPoolKey = flowPoolKeyAndLevel.getLeft();
         String level = flowPoolKeyAndLevel.getRight();
 
-        int idx = 0;
         int getSize = param.getSize() * 5;
         List<Video> results = new ArrayList<>();
 
-        Set<ZSetOperations.TypedTuple<String>> data = redisTemplate.opsForZSet().reverseRangeWithScores(flowPoolKey, idx,
-                idx + getSize - 1);
+        Set<ZSetOperations.TypedTuple<String>> data = redisTemplate.opsForZSet().reverseRangeWithScores(flowPoolKey, 0,
+                getSize - 1);
         if (CollectionUtils.isEmpty(data)) {
             return null;
         }
-        idx += getSize;
 
         Map<Long, Double> videoScoreMap = new HashMap<>();
         Map<Long, String> videoFlowPoolMap = new HashMap<>();
@@ -52,9 +48,7 @@ public abstract class AbstractFlowPoolWithLevelScoreRecallStrategy implements Re
             videoScoreMap.put(NumberUtils.toLong(values[0], 0), t.getScore());
         }
 
-        FilterParam filterParam = new FilterParam();
-        filterParam.setVideoIds(Lists.newArrayList(videoFlowPoolMap.keySet()));
-        FilterResult filterResult = filterService.filter(filterParam);
+        FilterResult filterResult = filterService.filter(FilterParamFactory.create(param, videoFlowPoolMap));
 
         if (filterResult != null && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {
             filterResult.getVideoIds().stream().forEach(vid -> {

+ 4 - 9
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractFlowPoolWithScoreRecallStrategy.java

@@ -1,10 +1,9 @@
 package com.tzld.piaoquan.recommend.server.service.recall.strategy;
 
-import com.google.common.collect.Lists;
 import com.tzld.piaoquan.recommend.server.model.Video;
-import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
 import com.tzld.piaoquan.recommend.server.service.filter.FilterResult;
 import com.tzld.piaoquan.recommend.server.service.filter.FlowPoolWithScoreFilterService;
+import com.tzld.piaoquan.recommend.server.service.recall.FilterParamFactory;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallStrategy;
 import org.apache.commons.collections4.CollectionUtils;
@@ -29,16 +28,14 @@ public abstract class AbstractFlowPoolWithScoreRecallStrategy implements RecallS
     public List<Video> recall(RecallParam param) {
         String flowPoolKey = flowPoolKey(param);
 
-        int idx = 0;
         int getSize = param.getSize() * 5;
         List<Video> results = new ArrayList<>();
 
-        Set<ZSetOperations.TypedTuple<String>> data = redisTemplate.opsForZSet().reverseRangeWithScores(flowPoolKey, idx,
-                idx + getSize - 1);
+        Set<ZSetOperations.TypedTuple<String>> data = redisTemplate.opsForZSet().reverseRangeWithScores(flowPoolKey, 0,
+                getSize - 1);
         if (CollectionUtils.isEmpty(data)) {
             return null;
         }
-        idx += getSize;
 
         Map<Long, Double> videoScoreMap = new HashMap<>();
         Map<Long, String> videoFlowPoolMap = new HashMap<>();
@@ -48,9 +45,7 @@ public abstract class AbstractFlowPoolWithScoreRecallStrategy implements RecallS
             videoScoreMap.put(NumberUtils.toLong(values[0], 0), t.getScore());
         }
 
-        FilterParam filterParam = new FilterParam();
-        filterParam.setVideoIds(Lists.newArrayList(videoFlowPoolMap.keySet()));
-        FilterResult filterResult = filterService.filter(filterParam);
+        FilterResult filterResult = filterService.filter(FilterParamFactory.create(param, videoFlowPoolMap));
 
         if (filterResult != null && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {
             filterResult.getVideoIds().stream().forEach(vid -> {

+ 2 - 4
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractRegionRecallStrategy.java

@@ -3,9 +3,9 @@ package com.tzld.piaoquan.recommend.server.service.recall.strategy;
 import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import com.tzld.piaoquan.recommend.server.model.Video;
-import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
 import com.tzld.piaoquan.recommend.server.service.filter.FilterResult;
 import com.tzld.piaoquan.recommend.server.service.filter.RegionFilterService;
+import com.tzld.piaoquan.recommend.server.service.recall.FilterParamFactory;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallStrategy;
 import com.tzld.piaoquan.recommend.server.util.DateUtils;
@@ -97,9 +97,7 @@ public abstract class AbstractRegionRecallStrategy implements RecallStrategy {
                 videoMap.put(NumberUtils.toLong(t.getValue(), 0), t.getScore());
             }
 
-            FilterParam filterParam = new FilterParam();
-            filterParam.setVideoIds(Lists.newArrayList(videoMap.keySet()));
-            FilterResult filterResult = filterService.filter(filterParam);
+            FilterResult filterResult = filterService.filter(FilterParamFactory.create(param, Lists.newArrayList(videoMap.keySet())));
             if (filterResult != null && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {
                 filterResult.getVideoIds().stream().forEach(vid -> {
                     Video recallData = new Video();

+ 7 - 9
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractVideoRecallStrategy.java

@@ -3,9 +3,9 @@ package com.tzld.piaoquan.recommend.server.service.recall.strategy;
 import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import com.tzld.piaoquan.recommend.server.model.Video;
-import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
 import com.tzld.piaoquan.recommend.server.service.filter.FilterResult;
 import com.tzld.piaoquan.recommend.server.service.filter.VideoFilterService;
+import com.tzld.piaoquan.recommend.server.service.recall.FilterParamFactory;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
 import com.tzld.piaoquan.recommend.server.service.recall.RecallStrategy;
 import lombok.Data;
@@ -15,10 +15,7 @@ import org.apache.commons.lang3.math.NumberUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @author dyp
@@ -28,12 +25,15 @@ public abstract class AbstractVideoRecallStrategy implements RecallStrategy {
     protected RedisTemplate<String, String> redisTemplate;
 
     @Autowired
-    protected VideoFilterService simHotItemFilterService;
+    protected VideoFilterService filterService;
 
     @Override
     public List<Video> recall(RecallParam param) {
 
 
+        if (param.getVideoId() == null) {
+            return Collections.emptyList();
+        }
         String recall_key = recallKey(param);
         // [[16687915, 0.5], [16528093, 0.5]]
         String value = redisTemplate.opsForValue().get(recall_key);
@@ -50,9 +50,7 @@ public abstract class AbstractVideoRecallStrategy implements RecallStrategy {
                     NumberUtils.toDouble(item.getScore(), 0));
         }
 
-        FilterParam filterParam = new FilterParam();
-        filterParam.setVideoIds(Lists.newArrayList(videoScoreMap.keySet()));
-        FilterResult filterResult = simHotItemFilterService.filter(filterParam);
+        FilterResult filterResult = filterService.filter(FilterParamFactory.create(param, Lists.newArrayList(videoScoreMap.keySet())));
 
         if (filterResult != null && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {
             filterResult.getVideoIds().stream().forEach(vid -> {