|
@@ -113,65 +113,74 @@ public class FlowPoolWithLevelRecallStrategyTomson extends AbstractFlowPoolWithL
|
|
|
|
|
|
@Override
|
|
|
public List<Video> recall(RecallParam param) {
|
|
|
- Pair<String, String> flowPoolKeyAndLevel = flowPoolKeyAndLevel(param);
|
|
|
- String flowPoolKey = flowPoolKeyAndLevel.getLeft();
|
|
|
- String level = flowPoolKeyAndLevel.getRight();
|
|
|
- Set<String> data = redisTemplate.opsForSet().members(flowPoolKey);
|
|
|
- if (CollectionUtils.isEmpty(data)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- Map<String, String> videoFlowPoolMap = new LinkedHashMap<>();
|
|
|
- Map<Long, String> videoFlowPoolMap_ = new LinkedHashMap<>();
|
|
|
- for (String value : data) {
|
|
|
- String[] values = value.split("-");
|
|
|
- videoFlowPoolMap.put(values[0], values[1]);
|
|
|
- videoFlowPoolMap_.put(NumberUtils.toLong(values[0], 0), values[1]);
|
|
|
- }
|
|
|
- Map<Long, Double> resultmap = null;
|
|
|
- if ("1".equals(level) && ifOneLevelRandom){
|
|
|
- // 流量池一层改为全随机
|
|
|
- int limitSize = 60;
|
|
|
- List<Long> keyList = new ArrayList<>(videoFlowPoolMap_.keySet());
|
|
|
- Collections.shuffle(keyList);
|
|
|
- resultmap = keyList.stream().limit(limitSize).collect(Collectors.toMap(
|
|
|
- key -> key,
|
|
|
- key -> Math.random()
|
|
|
- ));
|
|
|
- }else{
|
|
|
- ScorerPipeline4Recall pipeline = ScorerUtils.getScorerPipeline4Recall("feeds_recall_config_tomson.conf");
|
|
|
- List<List<Pair<Long, Double>>> results = pipeline.recall(videoFlowPoolMap);
|
|
|
- List<Pair<Long, Double>> result = results.get(0);
|
|
|
- resultmap = result.stream()
|
|
|
- .collect(Collectors.toMap(
|
|
|
- Pair::getLeft, // 键是Pair的left值
|
|
|
- Pair::getRight, // 值是Pair的right值
|
|
|
- (existingValue, newValue) -> existingValue, // 如果键冲突,选择保留现有的值(或者你可以根据需要定义其他合并策略)
|
|
|
- LinkedHashMap::new // 使用LinkedHashMap来保持插入顺序(如果需要的话)
|
|
|
+ try {
|
|
|
+
|
|
|
+
|
|
|
+ Pair<String, String> flowPoolKeyAndLevel = flowPoolKeyAndLevel(param);
|
|
|
+ String flowPoolKey = flowPoolKeyAndLevel.getLeft();
|
|
|
+ String level = flowPoolKeyAndLevel.getRight();
|
|
|
+ Set<String> data = redisTemplate.opsForSet().members(flowPoolKey);
|
|
|
+ if (CollectionUtils.isEmpty(data)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Map<String, String> videoFlowPoolMap = new LinkedHashMap<>();
|
|
|
+ Map<Long, String> videoFlowPoolMap_ = new LinkedHashMap<>();
|
|
|
+ for (String value : data) {
|
|
|
+ String[] values = value.split("-");
|
|
|
+ videoFlowPoolMap.put(values[0], values[1]);
|
|
|
+ videoFlowPoolMap_.put(NumberUtils.toLong(values[0], 0), values[1]);
|
|
|
+ }
|
|
|
+ Map<Long, Double> resultmap = null;
|
|
|
+ if ("1".equals(level) && ifOneLevelRandom) {
|
|
|
+ // 流量池一层改为全随机
|
|
|
+ int limitSize = 60;
|
|
|
+ List<Long> keyList = new ArrayList<>(videoFlowPoolMap_.keySet());
|
|
|
+ Collections.shuffle(keyList);
|
|
|
+ resultmap = keyList.stream().limit(limitSize).collect(Collectors.toMap(
|
|
|
+ key -> key,
|
|
|
+ key -> Math.random()
|
|
|
));
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ ScorerPipeline4Recall pipeline = ScorerUtils.getScorerPipeline4Recall("feeds_recall_config_tomson.conf");
|
|
|
+ List<List<Pair<Long, Double>>> results = pipeline.recall(videoFlowPoolMap);
|
|
|
+ List<Pair<Long, Double>> result = results.get(0);
|
|
|
+ resultmap = result.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Pair::getLeft, // 键是Pair的left值
|
|
|
+ Pair::getRight, // 值是Pair的right值
|
|
|
+ (existingValue, newValue) -> existingValue, // 如果键冲突,选择保留现有的值(或者你可以根据需要定义其他合并策略)
|
|
|
+ LinkedHashMap::new // 使用LinkedHashMap来保持插入顺序(如果需要的话)
|
|
|
+ ));
|
|
|
+ }
|
|
|
|
|
|
- // 3 召回内部过滤
|
|
|
- FilterParam filterParam = FilterParamFactory.create(param, new ArrayList<>(resultmap.keySet()));
|
|
|
- filterParam.setForceTruncation(10000);
|
|
|
- filterParam.setConcurrent(true);
|
|
|
- filterParam.setNotUsePreView(false);
|
|
|
- FilterResult filterResult = filterService.filter(filterParam);
|
|
|
- List<Video> videosResult = new ArrayList<>();
|
|
|
- if (filterResult != null && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {
|
|
|
- Map<Long, Double> finalResultmap = resultmap;
|
|
|
- filterResult.getVideoIds().forEach(vid -> {
|
|
|
- Video recallData = new Video();
|
|
|
- recallData.setVideoId(vid);
|
|
|
- recallData.setAbCode(param.getAbCode());
|
|
|
- recallData.setRovScore(finalResultmap.getOrDefault(vid, 0.0));
|
|
|
- recallData.setPushFrom(pushFrom());
|
|
|
- recallData.setFlowPool(videoFlowPoolMap_.get(vid));
|
|
|
- recallData.setFlowPoolAbtestGroup(param.getFlowPoolAbtestGroup());
|
|
|
- recallData.setLevel(level);
|
|
|
- videosResult.add(recallData);
|
|
|
- });
|
|
|
+ // 3 召回内部过滤
|
|
|
+ FilterParam filterParam = FilterParamFactory.create(param, new ArrayList<>(resultmap.keySet()));
|
|
|
+ filterParam.setForceTruncation(10000);
|
|
|
+ filterParam.setConcurrent(true);
|
|
|
+ filterParam.setNotUsePreView(false);
|
|
|
+ FilterResult filterResult = filterService.filter(filterParam);
|
|
|
+ List<Video> videosResult = new ArrayList<>();
|
|
|
+ if (filterResult != null && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {
|
|
|
+ Map<Long, Double> finalResultmap = resultmap;
|
|
|
+ filterResult.getVideoIds().forEach(vid -> {
|
|
|
+ Video recallData = new Video();
|
|
|
+ recallData.setVideoId(vid);
|
|
|
+ recallData.setAbCode(param.getAbCode());
|
|
|
+ recallData.setRovScore(finalResultmap.getOrDefault(vid, 0.0));
|
|
|
+ recallData.setPushFrom(pushFrom());
|
|
|
+ recallData.setFlowPool(videoFlowPoolMap_.get(vid));
|
|
|
+ recallData.setFlowPoolAbtestGroup(param.getFlowPoolAbtestGroup());
|
|
|
+ recallData.setLevel(level);
|
|
|
+ videosResult.add(recallData);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ videosResult.sort(Comparator.comparingDouble(o -> -o.getRovScore()));
|
|
|
+
|
|
|
+ return videosResult;
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+ log.error("liuliangchi", e);
|
|
|
}
|
|
|
- videosResult.sort(Comparator.comparingDouble(o -> -o.getRovScore()));
|
|
|
- return videosResult;
|
|
|
+ return Collections.emptyList();
|
|
|
}
|
|
|
}
|