|
@@ -1,6 +1,5 @@
|
|
package com.tzld.piaoquan.recommend.server.service.recall.strategy;
|
|
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.model.Video;
|
|
import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
|
|
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.FilterResult;
|
|
@@ -8,15 +7,18 @@ 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.FilterParamFactory;
|
|
import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
|
|
import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
|
|
import com.tzld.piaoquan.recommend.server.service.recall.RecallStrategy;
|
|
import com.tzld.piaoquan.recommend.server.service.recall.RecallStrategy;
|
|
-import com.tzld.piaoquan.recommend.server.service.score.ScorerUtils;
|
|
|
|
-import com.tzld.piaoquan.recommend.server.service.score4recall.ScorerPipeline4Recall;
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
-import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.*;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author zhangbo
|
|
* @author zhangbo
|
|
@@ -28,31 +30,31 @@ public class AppFallbackRecallStrategy implements RecallStrategy {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private RegionFilterService filterService;
|
|
private RegionFilterService filterService;
|
|
|
|
+ @Autowired
|
|
|
|
+ @Qualifier("redisTemplate")
|
|
|
|
+ private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public List<Video> recall(RecallParam param) {
|
|
public List<Video> recall(RecallParam param) {
|
|
// 1 获取省份key 放入参数map中
|
|
// 1 获取省份key 放入参数map中
|
|
String regionCode = param.getRegionCode();
|
|
String regionCode = param.getRegionCode();
|
|
- if (StringUtils.isBlank(regionCode)) {
|
|
|
|
- regionCode = "";
|
|
|
|
|
|
+ String redisKey;
|
|
|
|
+ if (StringUtils.isBlank(regionCode) || StringUtils.equals(regionCode, "110100")
|
|
|
|
+ || StringUtils.equals(regionCode, "430100")) {
|
|
|
|
+ // 北京和长沙
|
|
|
|
+ redisKey = "app_fallback_recall_strategy_safe_videos";
|
|
|
|
+ } else {
|
|
|
|
+ // 其他
|
|
|
|
+ redisKey = "app_fallback_recall_unsafe_strategy_videos";
|
|
}
|
|
}
|
|
- Map<String, String> param4Model = new HashMap<>(1);
|
|
|
|
- param4Model.put("region_code", regionCode);
|
|
|
|
- // 2 通过model拿到召回list
|
|
|
|
- ScorerPipeline4Recall pipeline = ScorerUtils.getScorerPipeline4Recall("app_fallback_config.conf");
|
|
|
|
- List<List<Pair<Long, Double>>> results = pipeline.recall(param4Model);
|
|
|
|
- if (CollectionUtils.isEmpty(results)) {
|
|
|
|
|
|
+ String videoIds = redisTemplate.opsForValue().get(redisKey);
|
|
|
|
+ if (StringUtils.isBlank(videoIds)) {
|
|
return Collections.emptyList();
|
|
return Collections.emptyList();
|
|
}
|
|
}
|
|
- List<Pair<Long, Double>> result = results.get(0);
|
|
|
|
- for (int i = 1; i < results.size(); ++i) {
|
|
|
|
- result.addAll(results.get(i));
|
|
|
|
- }
|
|
|
|
- Map<Long, Double> videoMap = new LinkedHashMap<>();
|
|
|
|
- for (Pair<Long, Double> v : result) {
|
|
|
|
- videoMap.put(v.getLeft(), v.getRight());
|
|
|
|
- }
|
|
|
|
- FilterParam filterParam = FilterParamFactory.create(param, Lists.newArrayList(videoMap.keySet()));
|
|
|
|
|
|
+ List<Long> videoIdList = Arrays.asList(videoIds.split(",")).stream()
|
|
|
|
+ .map(Long::parseLong)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ FilterParam filterParam = FilterParamFactory.create(param, videoIdList);
|
|
filterParam.setForceTruncation(10000);
|
|
filterParam.setForceTruncation(10000);
|
|
filterParam.setConcurrent(true);
|
|
filterParam.setConcurrent(true);
|
|
filterParam.setNotUsePreView(false);
|
|
filterParam.setNotUsePreView(false);
|
|
@@ -64,7 +66,6 @@ public class AppFallbackRecallStrategy implements RecallStrategy {
|
|
Video video = new Video();
|
|
Video video = new Video();
|
|
video.setVideoId(vid);
|
|
video.setVideoId(vid);
|
|
video.setAbCode(param.getAbCode());
|
|
video.setAbCode(param.getAbCode());
|
|
- video.setRovScore(videoMap.get(vid));
|
|
|
|
video.setPushFrom(pushFrom());
|
|
video.setPushFrom(pushFrom());
|
|
videosResult.add(video);
|
|
videosResult.add(video);
|
|
});
|
|
});
|