소스 검색

先验地域内容加权
565同步567

jch 3 주 전
부모
커밋
53970b7dce

+ 54 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelBasic.java

@@ -19,6 +19,7 @@ import com.tzld.piaoquan.recommend.server.service.rank.processor.RankProcessorTa
 import com.tzld.piaoquan.recommend.server.util.JSONUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang.math.NumberUtils;
 import org.apache.commons.lang3.RandomUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
@@ -55,6 +56,7 @@ public abstract class RankStrategy4RegionMergeModelBasic extends RankService {
     private Set<String> strPlusCalibrationMergeCate2;
 
     public static final String STR_PLUS_CALIBRATION_ATTRIBUTE_KEY_PREFIX = "alg_rec_model_calibration_str:";
+    public static final String prioriProvinceWeightPrefix = "priori_province_weight";
 
     String CLASS_NAME = this.getClass().getSimpleName();
 
@@ -442,6 +444,58 @@ public abstract class RankStrategy4RegionMergeModelBasic extends RankService {
         return 1d;
     }
 
+    /**
+     * 获取先验地域加权
+     */
+    protected Map<String, Double> getPrioriVidProvinceRovn(String province, List<RankItem> items, Map<String, Map<String, Map<String, String>>> videoBaseInfoMap) {
+        Map<String, Double> map = new HashMap<>();
+        try {
+            if (null != province && !province.isEmpty() && null != items && !items.isEmpty() && null != videoBaseInfoMap && !videoBaseInfoMap.isEmpty()) {
+                List<String> vids = new ArrayList<>();
+                List<String> keys = new ArrayList<>();
+                for (RankItem item : items) {
+                    String vid = String.valueOf(item.getVideoId());
+                    Map<String, String> videoInfo = videoBaseInfoMap.getOrDefault(vid, new HashMap<>()).getOrDefault("alg_vid_feature_basic_info", new HashMap<>());
+                    String attributeProvince = videoInfo.get("attribute_province");
+                    if (null != attributeProvince && !attributeProvince.isEmpty()) {
+                        vids.add(vid);
+                        keys.add(String.format("%s:%s:%s:%s", prioriProvinceWeightPrefix, vid, province, "rovn"));
+                    }
+                }
+                if (!keys.isEmpty()) {
+                    List<String> values = redisTemplate.opsForValue().multiGet(keys);
+                    if (null != values && vids.size() == values.size()) {
+                        for (int i = 0; i < vids.size(); i++) {
+                            String vid = vids.get(i);
+                            String value = values.get(i);
+                            if (null != value && !value.isEmpty()) {
+                                double v = NumberUtils.toDouble(value, -1);
+                                if (v > 0) {
+                                    map.put(vid, v);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("priori province weight", e);
+        }
+        return map;
+    }
+
+    protected double getPrioriVidProvinceWeight(double highValue, double highWeight, double lowValue, double lowWeight, String vid, Map<String, Double> map) {
+        if (null != map && map.containsKey(vid)) {
+            double value = map.get(vid);
+            if (value >= highValue) {
+                return highWeight;
+            } else if (value <= lowValue) {
+                return lowWeight;
+            }
+        }
+        return 1.0;
+    }
+
     private boolean isInsertDouHotFlowPoolVideo() {
         double rand = RandomUtils.nextDouble(0, 1);
         return rand <= newFlowPoolSelectRate;

+ 19 - 43
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV565.java

@@ -8,7 +8,6 @@ import com.tzld.piaoquan.recommend.server.model.MachineInfo;
 import com.tzld.piaoquan.recommend.server.model.Video;
 import com.tzld.piaoquan.recommend.server.service.FeatureService;
 import com.tzld.piaoquan.recommend.server.service.rank.RankParam;
-import com.tzld.piaoquan.recommend.server.service.rank.bo.UserSRBO;
 import com.tzld.piaoquan.recommend.server.service.rank.bo.UserShareReturnProfile;
 import com.tzld.piaoquan.recommend.server.service.rank.extractor.ExtractVideoMergeCate;
 import com.tzld.piaoquan.recommend.server.service.rank.tansform.FeatureV6;
@@ -30,6 +29,7 @@ import java.util.concurrent.TimeUnit;
 public class RankStrategy4RegionMergeModelV565 extends RankStrategy4RegionMergeModelBasic {
     @ApolloJsonValue("${rank.score.merge.weightv565:}")
     private Map<String, Double> mergeWeight;
+
     @Autowired
     private FeatureService featureService;
 
@@ -74,6 +74,10 @@ public class RankStrategy4RegionMergeModelV565 extends RankStrategy4RegionMergeM
         RecallUtils.extractRecall(mergeWeight.getOrDefault("prioriProvinceStr", 1.0).intValue(), param, PrioriProvinceStrRecallStrategy.PUSH_FROM, setVideo, rovRecallRank);
         //-------------------priori province ros------------------
         RecallUtils.extractRecall(mergeWeight.getOrDefault("prioriProvinceRos", 1.0).intValue(), param, PrioriProvinceRosRecallStrategy.PUSH_FROM, setVideo, rovRecallRank);
+        //-------------------return1 cate2 ros------------------
+        RecallUtils.extractRecall(mergeWeight.getOrDefault("return1Cate2Ros", 5.0).intValue(), param, Return1Cate2RosRecallStrategy.PUSH_FORM, setVideo, rovRecallRank);
+        //-------------------return1 cate2 str------------------
+        RecallUtils.extractRecall(mergeWeight.getOrDefault("return1Cate2Str", 5.0).intValue(), param, Return1Cate2StrRecallStrategy.PUSH_FORM, setVideo, rovRecallRank);
 
         //-------------------排-------------------
         //-------------------序-------------------
@@ -83,29 +87,29 @@ public class RankStrategy4RegionMergeModelV565 extends RankStrategy4RegionMergeM
 
         // 1. 批量获取特征  省份参数要对齐  headvid  要传递过来!
         // k1:视频、k2:表、k3:特征、v:特征值
+        Map<String, String> headVideoInfo = param.getHeadInfo();
         List<String> vids = CommonCollectionUtils.toListDistinct(rovRecallRank, v -> String.valueOf(v.getVideoId()));
-        String headVid = String.valueOf(param.getHeadVid());
-        Map<String, Map<String, Map<String, String>>> videoBaseInfoMap = featureService.getVideoBaseInfo(headVid, vids);
-        FeatureService.Feature feature = featureService.getFeatureV3(param, videoBaseInfoMap, vids);
+        Map<String, Map<String, Map<String, String>>> videoBaseInfoMap = featureService.getVideoBaseInfo("", vids);
+        FeatureService.Feature feature = featureService.getFeatureV4(param, headVideoInfo, videoBaseInfoMap, vids);
         Map<String, Map<String, String>> featureOriginUser = feature.getUserFeature();
         Map<String, Map<String, Map<String, String>>> featureOriginVideo = feature.getVideoFeature();
-        Map<String, String> headVideoInfo = videoBaseInfoMap.getOrDefault(headVid, new HashMap<>()).getOrDefault("alg_vid_feature_basic_info", new HashMap<>());
 
         // 2. 用户信息预处理
         Map<String, Map<String, String[]>> newC7Map = FeatureV6.parseUCFScore(featureOriginUser.getOrDefault("alg_mid_feature_sharecf", new HashMap<>()));
         Map<String, Map<String, String[]>> newC8Map = FeatureV6.parseUCFScore(featureOriginUser.getOrDefault("alg_mid_feature_returncf", new HashMap<>()));
         UserShareReturnProfile userProfile = parseUserProfile(featureOriginUser);
-        Map<String, Map<String, String>> userBehaviorVideoMap = getUserBehaviorVideoMap(userProfile);
+        Map<String, Map<String, String>> userBehaviorVideoMap = param.getBehaviorVideos();
+        Map<String, String> creativeInfo = param.getCreativeInfoFeature();
 
         // 3. 特征处理
         List<RankItem> rankItems = CommonCollectionUtils.toList(rovRecallRank, RankItem::new);
-        Map<String, Float> userFeatureMap = getUserFeature(currentMs, param, headVideoInfo, userProfile, featureOriginUser);
-        batchGetVideoFeature(currentMs, userProfile, headVideoInfo, videoBaseInfoMap,
+        Map<String, Float> userFeatureMap = getUserFeature(currentMs, param, creativeInfo, headVideoInfo, userProfile, featureOriginUser);
+        batchGetVideoFeature(currentMs, userProfile, creativeInfo, headVideoInfo, videoBaseInfoMap,
                 newC7Map, newC8Map, featureOriginUser, userBehaviorVideoMap, featureOriginVideo, rankItems);
 
         // 4. 排序模型计算
         Map<String, Float> sceneFeatureMap = new HashMap<>(0);
-        List<RankItem> items = ScorerUtils.getScorerPipeline("feeds_score_config_fm_xgb_20250317.conf").scoring(sceneFeatureMap, userFeatureMap, userFeatureMap, rankItems);
+        List<RankItem> items = ScorerUtils.getScorerPipeline("feeds_score_config_fm_xgb_20250729.conf").scoring(sceneFeatureMap, userFeatureMap, userFeatureMap, rankItems);
 
         // 5. 排序公式特征
         double xgbRovNegRate = mergeWeight.getOrDefault("xgbRovNegRate", 0.059);
@@ -129,7 +133,6 @@ public class RankStrategy4RegionMergeModelV565 extends RankStrategy4RegionMergeM
         List<Video> result = new ArrayList<>();
         for (RankItem item : items) {
             String vidMergeCate2 = this.findVideoMergeCate2(videoBaseInfoMap, String.valueOf(item.getVideoId()));
-
             double strPlusCalibrationCoefficient = this.calcStrPlusCalibrationCoefficientByMergeCate2(vidMergeCate2);
 
             double score;
@@ -137,7 +140,6 @@ public class RankStrategy4RegionMergeModelV565 extends RankStrategy4RegionMergeM
             item.getScoresMap().put("fmRovOrigin", fmRovOrigin);
             double fmRovCoefficientBefore = restoreScore(fmRovOrigin, xgbRovNegRate);
             item.getScoresMap().put("fmRovCoefficientBefore", fmRovCoefficientBefore);
-
             double fmRov = fmRovCoefficientBefore * strPlusCalibrationCoefficient;
             item.getScoresMap().put("fmRov", fmRov);
             item.getScoresMap().put("strPlusCalibrationCoefficient", strPlusCalibrationCoefficient);
@@ -210,42 +212,13 @@ public class RankStrategy4RegionMergeModelV565 extends RankStrategy4RegionMergeM
         return null;
     }
 
-    private Map<String, Map<String, String>> getUserBehaviorVideoMap(UserShareReturnProfile userProfile) {
-        Set<String> vidSet = new HashSet<>();
-        if (null != userProfile) {
-            for (List<UserSRBO> list : Arrays.asList(userProfile.getM_s_s(), userProfile.getM_r_s(), userProfile.getL_s_s(), userProfile.getL_r_s())) {
-                if (null != list) {
-                    for (UserSRBO u : list) {
-                        if (null != u) {
-                            vidSet.add(u.getId() + "");
-                        }
-                    }
-                }
-            }
-        }
-
-        Map<String, Map<String, String>> historyVideoMap = new HashMap<>();
-        if (!vidSet.isEmpty()) {
-            Map<String, Map<String, Map<String, String>>> videoMap = featureService.getVideoBaseInfo("", new ArrayList<>(vidSet));
-            if (null != videoMap && !videoMap.isEmpty()) {
-                for (Map.Entry<String, Map<String, Map<String, String>>> entry : videoMap.entrySet()) {
-                    String vid = entry.getKey();
-                    Map<String, Map<String, String>> map = entry.getValue();
-                    if (null != map && map.containsKey("alg_vid_feature_basic_info")) {
-                        historyVideoMap.put(vid, map.get("alg_vid_feature_basic_info"));
-                    }
-                }
-            }
-        }
-        return historyVideoMap;
-    }
-
-    private Map<String, Float> getUserFeature(long currentMs, RankParam param, Map<String, String> headInfo, UserShareReturnProfile userProfile, Map<String, Map<String, String>> userOriginInfo) {
+    private Map<String, Float> getUserFeature(long currentMs, RankParam param, Map<String, String> creativeInfo, Map<String, String> headInfo, UserShareReturnProfile userProfile, Map<String, Map<String, String>> userOriginInfo) {
         Map<String, Double> featMap = new HashMap<>();
         // context feature
         String appType = String.valueOf(param.getAppType());
         String hotSceneType = String.valueOf(param.getHotSceneType());
         FeatureV6.getContextFeature(currentMs, appType, hotSceneType, featMap);
+        FeatureV6.getCreativeBaseFeature("e1", creativeInfo, featMap);
 
         // head video feature
         FeatureV6.getVideoBaseFeature("h", currentMs, headInfo, featMap);
@@ -260,6 +233,7 @@ public class RankStrategy4RegionMergeModelV565 extends RankStrategy4RegionMergeM
 
     private Map<String, Float> getVideoFeature(long currentMs, String vid,
                                                UserShareReturnProfile userProfile,
+                                               Map<String, String> creativeInfo,
                                                Map<String, String> headInfo, Map<String, String> rankInfo,
                                                Map<String, Map<String, String[]>> c7Map,
                                                Map<String, Map<String, String[]>> c8Map,
@@ -279,6 +253,7 @@ public class RankStrategy4RegionMergeModelV565 extends RankStrategy4RegionMergeM
 
         // head&rank cross feature
         FeatureV6.getHeadRankVideoCrossFeature(headInfo, rankInfo, featMap);
+        FeatureV6.getCreativeCrossFeature("e1", creativeInfo, rankInfo, featMap);
 
         // user profile & rank cross
         FeatureV6.getProfileVideoCrossFeature(currentMs, userProfile, rankInfo, historyVideoMap, featMap);
@@ -288,6 +263,7 @@ public class RankStrategy4RegionMergeModelV565 extends RankStrategy4RegionMergeM
 
     private void batchGetVideoFeature(long currentMs,
                                       UserShareReturnProfile userProfile,
+                                      Map<String, String> creativeInfo,
                                       Map<String, String> headInfo,
                                       Map<String, Map<String, Map<String, String>>> videoBaseInfoMap,
                                       Map<String, Map<String, String[]>> c7Map,
@@ -302,7 +278,7 @@ public class RankStrategy4RegionMergeModelV565 extends RankStrategy4RegionMergeM
                 String vid = item.getVideoId() + "";
                 Map<String, String> rankInfo = videoBaseInfoMap.getOrDefault(vid, new HashMap<>()).getOrDefault("alg_vid_feature_basic_info", new HashMap<>());
                 Future<Integer> future = ThreadPoolFactory.defaultPool().submit(() -> {
-                    item.featureMap = getVideoFeature(currentMs, vid, userProfile, headInfo, rankInfo, c7Map, c8Map, userOriginInfo, historyVideoMap, videoOriginInfo);
+                    item.featureMap = getVideoFeature(currentMs, vid, userProfile, creativeInfo, headInfo, rankInfo, c7Map, c8Map, userOriginInfo, historyVideoMap, videoOriginInfo);
                     item.norFeatureMap = item.featureMap;
                     return 1;
                 });

+ 30 - 49
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV566.java

@@ -8,9 +8,9 @@ import com.tzld.piaoquan.recommend.server.model.MachineInfo;
 import com.tzld.piaoquan.recommend.server.model.Video;
 import com.tzld.piaoquan.recommend.server.service.FeatureService;
 import com.tzld.piaoquan.recommend.server.service.rank.RankParam;
-import com.tzld.piaoquan.recommend.server.service.rank.bo.UserSRBO;
 import com.tzld.piaoquan.recommend.server.service.rank.bo.UserShareReturnProfile;
 import com.tzld.piaoquan.recommend.server.service.rank.extractor.ExtractVideoMergeCate;
+import com.tzld.piaoquan.recommend.server.service.rank.extractor.ExtractorUtils;
 import com.tzld.piaoquan.recommend.server.service.rank.tansform.FeatureV6;
 import com.tzld.piaoquan.recommend.server.service.recall.strategy.*;
 import com.tzld.piaoquan.recommend.server.service.score.ScorerUtils;
@@ -75,10 +75,12 @@ public class RankStrategy4RegionMergeModelV566 extends RankStrategy4RegionMergeM
         RecallUtils.extractRecall(mergeWeight.getOrDefault("prioriProvinceStr", 1.0).intValue(), param, PrioriProvinceStrRecallStrategy.PUSH_FROM, setVideo, rovRecallRank);
         //-------------------priori province ros------------------
         RecallUtils.extractRecall(mergeWeight.getOrDefault("prioriProvinceRos", 1.0).intValue(), param, PrioriProvinceRosRecallStrategy.PUSH_FROM, setVideo, rovRecallRank);
-        //-------------------channel layer rovn------------------
-        RecallUtils.extractRecall(mergeWeight.getOrDefault("channelLayerRov", 5.0).intValue(), param, ChannelLayerRovnRecallStrategy.PUSH_FROM, setVideo, rovRecallRank);
-        //-------------------channel layer head rovn------------------
-        RecallUtils.extractRecall(mergeWeight.getOrDefault("channelLayerHeadRov", 5.0).intValue(), param, ChannelLayerHeadRovnRecallStrategy.PUSH_FROM, setVideo, rovRecallRank);
+        //-------------------return1 cate2 ros------------------
+        RecallUtils.extractRecall(mergeWeight.getOrDefault("return1Cate2Ros", 5.0).intValue(), param, Return1Cate2RosRecallStrategy.PUSH_FORM, setVideo, rovRecallRank);
+        //-------------------return1 cate2 str------------------
+        RecallUtils.extractRecall(mergeWeight.getOrDefault("return1Cate2Str", 5.0).intValue(), param, Return1Cate2StrRecallStrategy.PUSH_FORM, setVideo, rovRecallRank);
+        //-------------------priori premium rovn------------------
+        RecallUtils.extractRecall(mergeWeight.getOrDefault("prioriPremiumRovn", 0.0).intValue(), param, PrioriPremiumRovnRecallStrategy.PUSH_FORM, setVideo, rovRecallRank);
 
         //-------------------排-------------------
         //-------------------序-------------------
@@ -88,10 +90,9 @@ public class RankStrategy4RegionMergeModelV566 extends RankStrategy4RegionMergeM
 
         // 1. 批量获取特征  省份参数要对齐  headvid  要传递过来!
         // k1:视频、k2:表、k3:特征、v:特征值
+        Map<String, String> headVideoInfo = param.getHeadInfo();
         List<String> vids = CommonCollectionUtils.toListDistinct(rovRecallRank, v -> String.valueOf(v.getVideoId()));
-        String headVid = String.valueOf(param.getHeadVid());
-        Map<String, Map<String, Map<String, String>>> videoBaseInfoMap = featureService.getVideoBaseInfo(headVid, vids);
-        Map<String, String> headVideoInfo = videoBaseInfoMap.getOrDefault(headVid, new HashMap<>()).getOrDefault("alg_vid_feature_basic_info", new HashMap<>());
+        Map<String, Map<String, Map<String, String>>> videoBaseInfoMap = featureService.getVideoBaseInfo("", vids);
         FeatureService.Feature feature = featureService.getFeatureV4(param, headVideoInfo, videoBaseInfoMap, vids);
         Map<String, Map<String, String>> featureOriginUser = feature.getUserFeature();
         Map<String, Map<String, Map<String, String>>> featureOriginVideo = feature.getVideoFeature();
@@ -100,7 +101,7 @@ public class RankStrategy4RegionMergeModelV566 extends RankStrategy4RegionMergeM
         Map<String, Map<String, String[]>> newC7Map = FeatureV6.parseUCFScore(featureOriginUser.getOrDefault("alg_mid_feature_sharecf", new HashMap<>()));
         Map<String, Map<String, String[]>> newC8Map = FeatureV6.parseUCFScore(featureOriginUser.getOrDefault("alg_mid_feature_returncf", new HashMap<>()));
         UserShareReturnProfile userProfile = parseUserProfile(featureOriginUser);
-        Map<String, Map<String, String>> userBehaviorVideoMap = getUserBehaviorVideoMap(userProfile);
+        Map<String, Map<String, String>> userBehaviorVideoMap = param.getBehaviorVideos();
         Map<String, String> creativeInfo = param.getCreativeInfoFeature();
 
         // 3. 特征处理
@@ -111,12 +112,16 @@ public class RankStrategy4RegionMergeModelV566 extends RankStrategy4RegionMergeM
 
         // 4. 排序模型计算
         Map<String, Float> sceneFeatureMap = new HashMap<>(0);
-        List<RankItem> items = ScorerUtils.getScorerPipeline("feeds_score_config_fm_xgb_20250808.conf").scoring(sceneFeatureMap, userFeatureMap, userFeatureMap, rankItems);
+        List<RankItem> items = ScorerUtils.getScorerPipeline("feeds_score_config_fm_xgb_20250729.conf").scoring(sceneFeatureMap, userFeatureMap, userFeatureMap, rankItems);
 
         // 5. 排序公式特征
         double xgbRovNegRate = mergeWeight.getOrDefault("xgbRovNegRate", 0.059);
         double xgbNorPowerWeight = mergeWeight.getOrDefault("xgbNorPowerWeight", 1.22);
         double xgbNorPowerExp = mergeWeight.getOrDefault("xgbNorPowerExp", 1.15);
+        double prioriHighValue = mergeWeight.getOrDefault("prioriHighValue", 1.5);
+        double prioriHighWeight = mergeWeight.getOrDefault("prioriHighWeight", 1.3);
+        double prioriLowValue = mergeWeight.getOrDefault("prioriLowValue", 0.5);
+        double prioriLowWeight = mergeWeight.getOrDefault("prioriLowWeight", 1.0);
         Map<String, Map<String, String>> vid2MapFeature = this.getVideoRedisFeature(vids, "redis:vid_hasreturn_vor:");
 
         // 获取权重
@@ -131,27 +136,33 @@ public class RankStrategy4RegionMergeModelV566 extends RankStrategy4RegionMergeM
         }
         Double cate2CoefficientDenominator = mergeWeight.getOrDefault("cate2CoefficientDenominator", 1d);
         Map<String, String> regionMap = getUserRegion(param);
+        Map<String, Double> prioriVidProvinceRovn = this.getPrioriVidProvinceRovn(param.getProvince(), items, videoBaseInfoMap);
 
         List<Video> result = new ArrayList<>();
         for (RankItem item : items) {
             double score;
+            String vid = String.valueOf(item.getVideoId());
             double fmRovOrigin = item.getScoreRov();
             item.getScoresMap().put("fmRovOrigin", fmRovOrigin);
             double fmRov = restoreScore(fmRovOrigin, xgbRovNegRate);
             item.getScoresMap().put("fmRov", fmRov);
-            double hasReturnRovScore = Double.parseDouble(vid2MapFeature.getOrDefault(item.getVideoId() + "", new HashMap<>()).getOrDefault("rov", "0"));
+            double hasReturnRovScore = Double.parseDouble(vid2MapFeature.getOrDefault(vid, new HashMap<>()).getOrDefault("rov", "0"));
             item.getScoresMap().put("hasReturnRovScore", hasReturnRovScore);
             double norXGBScore = item.getScoresMap().getOrDefault("NorXGBScore", 0d);
             double newNorXGBScore = norPowerCalibration(xgbNorPowerWeight, xgbNorPowerExp, norXGBScore);
-            double vor = Double.parseDouble(vid2MapFeature.getOrDefault(item.getVideoId() + "", new HashMap<>()).getOrDefault("vor", "0"));
+            double vor = Double.parseDouble(vid2MapFeature.getOrDefault(vid, new HashMap<>()).getOrDefault("vor", "0"));
             item.getScoresMap().put("vor", vor);
 
-            String vidMergeCate2 = this.findVideoMergeCate2(videoBaseInfoMap, String.valueOf(item.getVideoId()));
+            String vidMergeCate2 = this.findVideoMergeCate2(videoBaseInfoMap, vid);
             Double scoreCoefficient = cate2Coefficient.getOrDefault(vidMergeCate2, 0d);
             item.getScoresMap().put("scoreCoefficient", scoreCoefficient);
             item.getScoresMap().put("cate2CoefficientDenominator", cate2CoefficientDenominator);
 
-            score = fmRov * (0.1 + newNorXGBScore) * (0.1 + vor) * (1 + scoreCoefficient / cate2CoefficientDenominator);
+            double prioriWeight = getPrioriVidProvinceWeight(prioriHighValue, prioriHighWeight, prioriLowValue, prioriLowWeight, vid, prioriVidProvinceRovn);
+            score = prioriWeight * fmRov * (0.1 + newNorXGBScore) * (0.1 + vor) * (1 + scoreCoefficient / cate2CoefficientDenominator);
+            if (!ExtractorUtils.isDoubleEqualToZero(prioriWeight - 1.0)) {
+                item.getScoresMap().put("prioriWeight", prioriWeight);
+            }
 
             Video video = item.getVideo();
             video.setScore(score);
@@ -159,16 +170,16 @@ public class RankStrategy4RegionMergeModelV566 extends RankStrategy4RegionMergeM
             video.setScoresMap(item.getScoresMap());
             // video.setAllFeatureMap(item.getAllFeatureMap());
 
-            String mergeCate2 = ExtractVideoMergeCate.parseMergeCate2(String.valueOf(item.getVideoId()), videoBaseInfoMap);
+            String mergeCate2 = ExtractVideoMergeCate.parseMergeCate2(vid, videoBaseInfoMap);
             if (StringUtils.isNotBlank(mergeCate2)) {
                 video.getMergeCateList().add(mergeCate2);
             }
 
-            if (MapUtils.isNotEmpty(feature.getVideoFeature()) && MapUtils.isNotEmpty(feature.getVideoFeature().get(item.getVideoId() + ""))) {
-                video.getMetaFeatureMap().putAll(feature.getVideoFeature().get(item.getVideoId() + ""));
+            if (MapUtils.isNotEmpty(feature.getVideoFeature()) && MapUtils.isNotEmpty(feature.getVideoFeature().get(vid))) {
+                video.getMetaFeatureMap().putAll(feature.getVideoFeature().get(vid));
             }
-            if (MapUtils.isNotEmpty(videoBaseInfoMap) && MapUtils.isNotEmpty(videoBaseInfoMap.get(item.getVideoId() + ""))) {
-                video.getMetaFeatureMap().putAll(videoBaseInfoMap.get(item.getVideoId() + ""));
+            if (MapUtils.isNotEmpty(videoBaseInfoMap) && MapUtils.isNotEmpty(videoBaseInfoMap.get(vid))) {
+                video.getMetaFeatureMap().putAll(videoBaseInfoMap.get(vid));
             }
             if (MapUtils.isNotEmpty(headVideoInfo)) {
                 video.getMetaFeatureMap().put("head_video", headVideoInfo);
@@ -209,36 +220,6 @@ public class RankStrategy4RegionMergeModelV566 extends RankStrategy4RegionMergeM
         return null;
     }
 
-    private Map<String, Map<String, String>> getUserBehaviorVideoMap(UserShareReturnProfile userProfile) {
-        Set<String> vidSet = new HashSet<>();
-        if (null != userProfile) {
-            for (List<UserSRBO> list : Arrays.asList(userProfile.getM_s_s(), userProfile.getM_r_s(), userProfile.getL_s_s(), userProfile.getL_r_s())) {
-                if (null != list) {
-                    for (UserSRBO u : list) {
-                        if (null != u) {
-                            vidSet.add(u.getId() + "");
-                        }
-                    }
-                }
-            }
-        }
-
-        Map<String, Map<String, String>> historyVideoMap = new HashMap<>();
-        if (!vidSet.isEmpty()) {
-            Map<String, Map<String, Map<String, String>>> videoMap = featureService.getVideoBaseInfo("", new ArrayList<>(vidSet));
-            if (null != videoMap && !videoMap.isEmpty()) {
-                for (Map.Entry<String, Map<String, Map<String, String>>> entry : videoMap.entrySet()) {
-                    String vid = entry.getKey();
-                    Map<String, Map<String, String>> map = entry.getValue();
-                    if (null != map && map.containsKey("alg_vid_feature_basic_info")) {
-                        historyVideoMap.put(vid, map.get("alg_vid_feature_basic_info"));
-                    }
-                }
-            }
-        }
-        return historyVideoMap;
-    }
-
     private Map<String, Float> getUserFeature(long currentMs, RankParam param, Map<String, String> creativeInfo, Map<String, String> headInfo, UserShareReturnProfile userProfile, Map<String, Map<String, String>> userOriginInfo) {
         Map<String, Double> featMap = new HashMap<>();
         // context feature

+ 40 - 63
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV568.java

@@ -8,9 +8,9 @@ import com.tzld.piaoquan.recommend.server.model.MachineInfo;
 import com.tzld.piaoquan.recommend.server.model.Video;
 import com.tzld.piaoquan.recommend.server.service.FeatureService;
 import com.tzld.piaoquan.recommend.server.service.rank.RankParam;
-import com.tzld.piaoquan.recommend.server.service.rank.bo.UserSRBO;
 import com.tzld.piaoquan.recommend.server.service.rank.bo.UserShareReturnProfile;
 import com.tzld.piaoquan.recommend.server.service.rank.extractor.ExtractVideoMergeCate;
+import com.tzld.piaoquan.recommend.server.service.rank.extractor.ExtractorUtils;
 import com.tzld.piaoquan.recommend.server.service.rank.tansform.FeatureV6;
 import com.tzld.piaoquan.recommend.server.service.recall.strategy.*;
 import com.tzld.piaoquan.recommend.server.service.score.ScorerUtils;
@@ -75,6 +75,12 @@ public class RankStrategy4RegionMergeModelV568 extends RankStrategy4RegionMergeM
         RecallUtils.extractRecall(mergeWeight.getOrDefault("prioriProvinceStr", 1.0).intValue(), param, PrioriProvinceStrRecallStrategy.PUSH_FROM, setVideo, rovRecallRank);
         //-------------------priori province ros------------------
         RecallUtils.extractRecall(mergeWeight.getOrDefault("prioriProvinceRos", 1.0).intValue(), param, PrioriProvinceRosRecallStrategy.PUSH_FROM, setVideo, rovRecallRank);
+        //-------------------return1 cate2 ros------------------
+        RecallUtils.extractRecall(mergeWeight.getOrDefault("return1Cate2Ros", 5.0).intValue(), param, Return1Cate2RosRecallStrategy.PUSH_FORM, setVideo, rovRecallRank);
+        //-------------------return1 cate2 str------------------
+        RecallUtils.extractRecall(mergeWeight.getOrDefault("return1Cate2Str", 5.0).intValue(), param, Return1Cate2StrRecallStrategy.PUSH_FORM, setVideo, rovRecallRank);
+        //-------------------priori premium rovn------------------
+        RecallUtils.extractRecall(mergeWeight.getOrDefault("prioriPremiumRovn", 0.0).intValue(), param, PrioriPremiumRovnRecallStrategy.PUSH_FORM, setVideo, rovRecallRank);
 
         //-------------------排-------------------
         //-------------------序-------------------
@@ -84,36 +90,38 @@ public class RankStrategy4RegionMergeModelV568 extends RankStrategy4RegionMergeM
 
         // 1. 批量获取特征  省份参数要对齐  headvid  要传递过来!
         // k1:视频、k2:表、k3:特征、v:特征值
+        Map<String, String> headVideoInfo = param.getHeadInfo();
         List<String> vids = CommonCollectionUtils.toListDistinct(rovRecallRank, v -> String.valueOf(v.getVideoId()));
-        String headVid = String.valueOf(param.getHeadVid());
-        Map<String, Map<String, Map<String, String>>> videoBaseInfoMap = featureService.getVideoBaseInfo(headVid, vids);
-        FeatureService.Feature feature = featureService.getFeatureV3(param, videoBaseInfoMap, vids);
+        Map<String, Map<String, Map<String, String>>> videoBaseInfoMap = featureService.getVideoBaseInfo("", vids);
+        FeatureService.Feature feature = featureService.getFeatureV4(param, headVideoInfo, videoBaseInfoMap, vids);
         Map<String, Map<String, String>> featureOriginUser = feature.getUserFeature();
         Map<String, Map<String, Map<String, String>>> featureOriginVideo = feature.getVideoFeature();
-        Map<String, String> headVideoInfo = videoBaseInfoMap.getOrDefault(headVid, new HashMap<>()).getOrDefault("alg_vid_feature_basic_info", new HashMap<>());
 
         // 2. 用户信息预处理
         Map<String, Map<String, String[]>> newC7Map = FeatureV6.parseUCFScore(featureOriginUser.getOrDefault("alg_mid_feature_sharecf", new HashMap<>()));
         Map<String, Map<String, String[]>> newC8Map = FeatureV6.parseUCFScore(featureOriginUser.getOrDefault("alg_mid_feature_returncf", new HashMap<>()));
         UserShareReturnProfile userProfile = parseUserProfile(featureOriginUser);
-        Map<String, Map<String, String>> userBehaviorVideoMap = getUserBehaviorVideoMap(userProfile);
+        Map<String, Map<String, String>> userBehaviorVideoMap = param.getBehaviorVideos();
+        Map<String, String> creativeInfo = param.getCreativeInfoFeature();
 
         // 3. 特征处理
         List<RankItem> rankItems = CommonCollectionUtils.toList(rovRecallRank, RankItem::new);
-        Map<String, Float> userFeatureMap = getUserFeature(currentMs, param, headVideoInfo, userProfile, featureOriginUser);
-        batchGetVideoFeature(currentMs, userProfile, headVideoInfo, videoBaseInfoMap,
+        Map<String, Float> userFeatureMap = getUserFeature(currentMs, param, creativeInfo, headVideoInfo, userProfile, featureOriginUser);
+        batchGetVideoFeature(currentMs, userProfile, creativeInfo, headVideoInfo, videoBaseInfoMap,
                 newC7Map, newC8Map, featureOriginUser, userBehaviorVideoMap, featureOriginVideo, rankItems);
 
         // 4. 排序模型计算
         Map<String, Float> sceneFeatureMap = new HashMap<>(0);
-        List<RankItem> items = ScorerUtils.getScorerPipeline("feeds_score_config_fm_xgb_20250317.conf").scoring(sceneFeatureMap, userFeatureMap, userFeatureMap, rankItems);
+        List<RankItem> items = ScorerUtils.getScorerPipeline("feeds_score_config_fm_xgb_20250729.conf").scoring(sceneFeatureMap, userFeatureMap, userFeatureMap, rankItems);
 
         // 5. 排序公式特征
         double xgbRovNegRate = mergeWeight.getOrDefault("xgbRovNegRate", 0.059);
         double xgbNorPowerWeight = mergeWeight.getOrDefault("xgbNorPowerWeight", 1.22);
         double xgbNorPowerExp = mergeWeight.getOrDefault("xgbNorPowerExp", 1.15);
-        double modelNorWeight = mergeWeight.getOrDefault("modelNorWeight", 0.5);
-        double statNorWeight = mergeWeight.getOrDefault("statNorWeight", 0.5);
+        double prioriHighValue = mergeWeight.getOrDefault("prioriHighValue", 1.5);
+        double prioriHighWeight = mergeWeight.getOrDefault("prioriHighWeight", 1.0);
+        double prioriLowValue = mergeWeight.getOrDefault("prioriLowValue", 0.5);
+        double prioriLowWeight = mergeWeight.getOrDefault("prioriLowWeight", 0.8);
         Map<String, Map<String, String>> vid2MapFeature = this.getVideoRedisFeature(vids, "redis:vid_hasreturn_vor:");
 
         // 获取权重
@@ -128,28 +136,33 @@ public class RankStrategy4RegionMergeModelV568 extends RankStrategy4RegionMergeM
         }
         Double cate2CoefficientDenominator = mergeWeight.getOrDefault("cate2CoefficientDenominator", 1d);
         Map<String, String> regionMap = getUserRegion(param);
+        Map<String, Double> prioriVidProvinceRovn = this.getPrioriVidProvinceRovn(param.getProvince(), items, videoBaseInfoMap);
 
         List<Video> result = new ArrayList<>();
         for (RankItem item : items) {
             double score;
+            String vid = String.valueOf(item.getVideoId());
             double fmRovOrigin = item.getScoreRov();
             item.getScoresMap().put("fmRovOrigin", fmRovOrigin);
             double fmRov = restoreScore(fmRovOrigin, xgbRovNegRate);
             item.getScoresMap().put("fmRov", fmRov);
-            double hasReturnRovScore = Double.parseDouble(vid2MapFeature.getOrDefault(item.getVideoId() + "", new HashMap<>()).getOrDefault("rov", "0"));
+            double hasReturnRovScore = Double.parseDouble(vid2MapFeature.getOrDefault(vid, new HashMap<>()).getOrDefault("rov", "0"));
             item.getScoresMap().put("hasReturnRovScore", hasReturnRovScore);
             double norXGBScore = item.getScoresMap().getOrDefault("NorXGBScore", 0d);
             double newNorXGBScore = norPowerCalibration(xgbNorPowerWeight, xgbNorPowerExp, norXGBScore);
-            newNorXGBScore = norFusion(modelNorWeight, newNorXGBScore, statNorWeight, hasReturnRovScore);
-            double vor = Double.parseDouble(vid2MapFeature.getOrDefault(item.getVideoId() + "", new HashMap<>()).getOrDefault("vor", "0"));
+            double vor = Double.parseDouble(vid2MapFeature.getOrDefault(vid, new HashMap<>()).getOrDefault("vor", "0"));
             item.getScoresMap().put("vor", vor);
 
-            String vidMergeCate2 = this.findVideoMergeCate2(videoBaseInfoMap, String.valueOf(item.getVideoId()));
+            String vidMergeCate2 = this.findVideoMergeCate2(videoBaseInfoMap, vid);
             Double scoreCoefficient = cate2Coefficient.getOrDefault(vidMergeCate2, 0d);
             item.getScoresMap().put("scoreCoefficient", scoreCoefficient);
             item.getScoresMap().put("cate2CoefficientDenominator", cate2CoefficientDenominator);
 
-            score = fmRov * (0.1 + newNorXGBScore) * (0.1 + vor) * (1 + scoreCoefficient / cate2CoefficientDenominator);
+            double prioriWeight = getPrioriVidProvinceWeight(prioriHighValue, prioriHighWeight, prioriLowValue, prioriLowWeight, vid, prioriVidProvinceRovn);
+            score = prioriWeight * fmRov * (0.1 + newNorXGBScore) * (0.1 + vor) * (1 + scoreCoefficient / cate2CoefficientDenominator);
+            if (!ExtractorUtils.isDoubleEqualToZero(prioriWeight - 1.0)) {
+                item.getScoresMap().put("prioriWeight", prioriWeight);
+            }
 
             Video video = item.getVideo();
             video.setScore(score);
@@ -157,16 +170,16 @@ public class RankStrategy4RegionMergeModelV568 extends RankStrategy4RegionMergeM
             video.setScoresMap(item.getScoresMap());
             // video.setAllFeatureMap(item.getAllFeatureMap());
 
-            String mergeCate2 = ExtractVideoMergeCate.parseMergeCate2(String.valueOf(item.getVideoId()), videoBaseInfoMap);
+            String mergeCate2 = ExtractVideoMergeCate.parseMergeCate2(vid, videoBaseInfoMap);
             if (StringUtils.isNotBlank(mergeCate2)) {
                 video.getMergeCateList().add(mergeCate2);
             }
 
-            if (MapUtils.isNotEmpty(feature.getVideoFeature()) && MapUtils.isNotEmpty(feature.getVideoFeature().get(item.getVideoId() + ""))) {
-                video.getMetaFeatureMap().putAll(feature.getVideoFeature().get(item.getVideoId() + ""));
+            if (MapUtils.isNotEmpty(feature.getVideoFeature()) && MapUtils.isNotEmpty(feature.getVideoFeature().get(vid))) {
+                video.getMetaFeatureMap().putAll(feature.getVideoFeature().get(vid));
             }
-            if (MapUtils.isNotEmpty(videoBaseInfoMap) && MapUtils.isNotEmpty(videoBaseInfoMap.get(item.getVideoId() + ""))) {
-                video.getMetaFeatureMap().putAll(videoBaseInfoMap.get(item.getVideoId() + ""));
+            if (MapUtils.isNotEmpty(videoBaseInfoMap) && MapUtils.isNotEmpty(videoBaseInfoMap.get(vid))) {
+                video.getMetaFeatureMap().putAll(videoBaseInfoMap.get(vid));
             }
             if (MapUtils.isNotEmpty(headVideoInfo)) {
                 video.getMetaFeatureMap().put("head_video", headVideoInfo);
@@ -207,42 +220,13 @@ public class RankStrategy4RegionMergeModelV568 extends RankStrategy4RegionMergeM
         return null;
     }
 
-    private Map<String, Map<String, String>> getUserBehaviorVideoMap(UserShareReturnProfile userProfile) {
-        Set<String> vidSet = new HashSet<>();
-        if (null != userProfile) {
-            for (List<UserSRBO> list : Arrays.asList(userProfile.getM_s_s(), userProfile.getM_r_s(), userProfile.getL_s_s(), userProfile.getL_r_s())) {
-                if (null != list) {
-                    for (UserSRBO u : list) {
-                        if (null != u) {
-                            vidSet.add(u.getId() + "");
-                        }
-                    }
-                }
-            }
-        }
-
-        Map<String, Map<String, String>> historyVideoMap = new HashMap<>();
-        if (!vidSet.isEmpty()) {
-            Map<String, Map<String, Map<String, String>>> videoMap = featureService.getVideoBaseInfo("", new ArrayList<>(vidSet));
-            if (null != videoMap && !videoMap.isEmpty()) {
-                for (Map.Entry<String, Map<String, Map<String, String>>> entry : videoMap.entrySet()) {
-                    String vid = entry.getKey();
-                    Map<String, Map<String, String>> map = entry.getValue();
-                    if (null != map && map.containsKey("alg_vid_feature_basic_info")) {
-                        historyVideoMap.put(vid, map.get("alg_vid_feature_basic_info"));
-                    }
-                }
-            }
-        }
-        return historyVideoMap;
-    }
-
-    private Map<String, Float> getUserFeature(long currentMs, RankParam param, Map<String, String> headInfo, UserShareReturnProfile userProfile, Map<String, Map<String, String>> userOriginInfo) {
+    private Map<String, Float> getUserFeature(long currentMs, RankParam param, Map<String, String> creativeInfo, Map<String, String> headInfo, UserShareReturnProfile userProfile, Map<String, Map<String, String>> userOriginInfo) {
         Map<String, Double> featMap = new HashMap<>();
         // context feature
         String appType = String.valueOf(param.getAppType());
         String hotSceneType = String.valueOf(param.getHotSceneType());
         FeatureV6.getContextFeature(currentMs, appType, hotSceneType, featMap);
+        FeatureV6.getCreativeBaseFeature("e1", creativeInfo, featMap);
 
         // head video feature
         FeatureV6.getVideoBaseFeature("h", currentMs, headInfo, featMap);
@@ -257,6 +241,7 @@ public class RankStrategy4RegionMergeModelV568 extends RankStrategy4RegionMergeM
 
     private Map<String, Float> getVideoFeature(long currentMs, String vid,
                                                UserShareReturnProfile userProfile,
+                                               Map<String, String> creativeInfo,
                                                Map<String, String> headInfo, Map<String, String> rankInfo,
                                                Map<String, Map<String, String[]>> c7Map,
                                                Map<String, Map<String, String[]>> c8Map,
@@ -276,6 +261,7 @@ public class RankStrategy4RegionMergeModelV568 extends RankStrategy4RegionMergeM
 
         // head&rank cross feature
         FeatureV6.getHeadRankVideoCrossFeature(headInfo, rankInfo, featMap);
+        FeatureV6.getCreativeCrossFeature("e1", creativeInfo, rankInfo, featMap);
 
         // user profile & rank cross
         FeatureV6.getProfileVideoCrossFeature(currentMs, userProfile, rankInfo, historyVideoMap, featMap);
@@ -285,6 +271,7 @@ public class RankStrategy4RegionMergeModelV568 extends RankStrategy4RegionMergeM
 
     private void batchGetVideoFeature(long currentMs,
                                       UserShareReturnProfile userProfile,
+                                      Map<String, String> creativeInfo,
                                       Map<String, String> headInfo,
                                       Map<String, Map<String, Map<String, String>>> videoBaseInfoMap,
                                       Map<String, Map<String, String[]>> c7Map,
@@ -299,7 +286,7 @@ public class RankStrategy4RegionMergeModelV568 extends RankStrategy4RegionMergeM
                 String vid = item.getVideoId() + "";
                 Map<String, String> rankInfo = videoBaseInfoMap.getOrDefault(vid, new HashMap<>()).getOrDefault("alg_vid_feature_basic_info", new HashMap<>());
                 Future<Integer> future = ThreadPoolFactory.defaultPool().submit(() -> {
-                    item.featureMap = getVideoFeature(currentMs, vid, userProfile, headInfo, rankInfo, c7Map, c8Map, userOriginInfo, historyVideoMap, videoOriginInfo);
+                    item.featureMap = getVideoFeature(currentMs, vid, userProfile, creativeInfo, headInfo, rankInfo, c7Map, c8Map, userOriginInfo, historyVideoMap, videoOriginInfo);
                     item.norFeatureMap = item.featureMap;
                     return 1;
                 });
@@ -416,14 +403,4 @@ public class RankStrategy4RegionMergeModelV568 extends RankStrategy4RegionMergeM
         Map<String, String> videoInfo = featureOriginVideo.getOrDefault(vid, new HashMap<>()).getOrDefault("alg_vid_feature_basic_info", new HashMap<>());
         return videoInfo.get("merge_second_level_cate");
     }
-
-    private double norFusion(double modelWeight, double modelScore, double statWeight, double statScore) {
-        if (modelScore < 1E-8) {
-            return statScore;
-        } else if (statScore < 1E-8) {
-            return modelScore;
-        } else {
-            return modelWeight * modelScore + statWeight * statScore;
-        }
-    }
 }

+ 6 - 7
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/RecallService.java

@@ -121,14 +121,13 @@ public class RecallService implements ApplicationContextAware {
         strategies.add(strategyMap.get(PrioriProvinceRovnRecallStrategy.class.getSimpleName()));
         strategies.add(strategyMap.get(PrioriProvinceStrRecallStrategy.class.getSimpleName()));
         strategies.add(strategyMap.get(PrioriProvinceRosRecallStrategy.class.getSimpleName()));
+        strategies.add(strategyMap.get(Return1Cate2RosRecallStrategy.class.getSimpleName()));
+        strategies.add(strategyMap.get(Return1Cate2StrRecallStrategy.class.getSimpleName()));
         Set<String> abExpCodes = param.getAbExpCodes();
-        if (CollectionUtils.isNotEmpty(abExpCodes) && abExpCodes.contains("566")) {
-            strategies.add(strategyMap.get(ChannelLayerRovnRecallStrategy.class.getSimpleName()));
-            strategies.add(strategyMap.get(ChannelLayerHeadRovnRecallStrategy.class.getSimpleName()));
-        }
-        if (CollectionUtils.isNotEmpty(abExpCodes) && abExpCodes.contains("567")) {
-            strategies.add(strategyMap.get(Return1Cate2RosRecallStrategy.class.getSimpleName()));
-            strategies.add(strategyMap.get(Return1Cate2StrRecallStrategy.class.getSimpleName()));
+        if (CollectionUtils.isNotEmpty(abExpCodes)) {
+            if (abExpCodes.contains("566") || abExpCodes.contains("568")) {
+                strategies.add(strategyMap.get(PrioriPremiumRovnRecallStrategy.class.getSimpleName()));
+            }
         }
 
         // 命中用户黑名单不走流量池

+ 0 - 100
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/PremiumROVRecallStrategy.java

@@ -1,100 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.recall.strategy;
-
-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.FilterService;
-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.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.tuple.MutablePair;
-import org.apache.commons.lang3.tuple.Pair;
-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 java.util.*;
-import java.util.stream.Collectors;
-
-@Component
-@Slf4j
-public class PremiumROVRecallStrategy implements RecallStrategy {
-    private final String CLASS_NAME = this.getClass().getSimpleName();
-    @Autowired
-    private FilterService filterService;
-    @Autowired
-    @Qualifier("redisTemplate")
-    public RedisTemplate<String, String> redisTemplate;
-
-    public static final String PUSH_FROM = "premium_rov";
-    public static final String redisKey = "high_rovn_low_exp_recall:all";
-
-    @Override
-    public String pushFrom() {
-        return PUSH_FROM;
-    }
-
-    @Override
-    public List<Video> recall(RecallParam param) {
-        List<Video> videosResult = new ArrayList<>();
-        try {
-            String redisValue = redisTemplate.opsForValue().get(redisKey);
-            if (null == redisValue || redisValue.isEmpty()) {
-                return videosResult;
-            }
-            Pair<List<Long>, Map<Long, Double>> pair = parsePair(redisValue, param.getVideoId(), 100);
-            fillVideoResult(param, pair, videosResult);
-        } catch (Exception e) {
-            log.error("recall is wrong in {}, error={}", CLASS_NAME, e);
-        }
-        return videosResult;
-    }
-
-    private Pair<List<Long>, Map<Long, Double>> parsePair(String data, long headVid, int size) {
-        List<Long> idsList = new ArrayList<>();
-        Map<Long, Double> scoresMap = new HashMap<>();
-        if (!StringUtils.isBlank(data)) {
-            String[] cells = data.split("\t");
-            if (2 == cells.length) {
-                List<Long> ids = Arrays.stream(cells[0].split(",")).map(Long::valueOf).collect(Collectors.toList());
-                List<Double> scores = Arrays.stream(cells[1].split(",")).map(Double::valueOf).collect(Collectors.toList());
-                if (!ids.isEmpty() && ids.size() == scores.size()) {
-                    int minSize = Math.min(size, ids.size());
-                    for (int i = 0; i < minSize; ++i) {
-                        long id = ids.get(i);
-                        double score = scores.get(i);
-                        if (score > 0.01 && headVid != id && !scoresMap.containsKey(id)) {
-                            idsList.add(id);
-                            scoresMap.put(id, score);
-                        }
-                    }
-                }
-            }
-        }
-        return new MutablePair<>(idsList, scoresMap);
-    }
-
-    private void fillVideoResult(RecallParam param, Pair<List<Long>, Map<Long, Double>> pair, List<Video> videosResult) {
-        if (null != pair) {
-            List<Long> ids = pair.getLeft();
-            Map<Long, Double> scoresMap = pair.getRight();
-            if (null != ids && null != scoresMap && !ids.isEmpty()) {
-                FilterParam filterParam = FilterParamFactory.create(param, ids);
-                FilterResult filterResult = filterService.filter(filterParam);
-                if (null != filterResult && CollectionUtils.isNotEmpty(filterResult.getVideoIds())) {
-                    filterResult.getVideoIds().forEach(vid -> {
-                        Video video = new Video();
-                        video.setVideoId(vid);
-                        video.setRovScore(scoresMap.getOrDefault(vid, 0D));
-                        video.setPushFrom(pushFrom());
-                        videosResult.add(video);
-                    });
-                }
-            }
-        }
-    }
-}

+ 36 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/PrioriPremiumRovnRecallStrategy.java

@@ -0,0 +1,36 @@
+package com.tzld.piaoquan.recommend.server.service.recall.strategy;
+
+import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class PrioriPremiumRovnRecallStrategy extends AbstractRedisRecallStrategy {
+    private static final int topN = 60;
+    public static final String PUSH_FORM = "priori_premium_rovn";
+    private static final String redisKeyPrefix = "priori_premium_rovn_recall";
+
+    @Override
+    public String pushFrom() {
+        return PUSH_FORM;
+    }
+
+    @Override
+    protected List<String> getRedisKeys(RecallParam param) {
+        List<String> keys = new ArrayList<>();
+        if (null != param) {
+            String province = param.getProvince();
+            if (null != province && !province.isEmpty()) {
+                keys.add(String.format("%s:%s", redisKeyPrefix, province));
+            }
+        }
+        return keys;
+    }
+
+    @Override
+    protected int getTopN() {
+        return topN;
+    }
+}