Преглед на файлове

Merge branch 'feature_20260520_province_rovn_recall' of algorithm/recommend-server into master

yangxiaohui преди 3 дни
родител
ревизия
0f5cf4a43a

+ 49 - 0
CLAUDE.md

@@ -0,0 +1,49 @@
+# recommend-server 项目须知
+
+## 提交规则(最重要)
+
+以下文件/目录是**本地调试/同步用**,**不要 git add 进任何业务 PR**:
+
+- `recommend-server-service/src/main/resources/application-dev.yml`
+  - 用户本地会把 eureka / redis hostName / apollo meta 改成自己的调试地址
+  - 看到这个文件有 diff 时,**默认跳过它**(用户会自己处理)
+- `apollo/` 目录(如 `apollo/rank.score.merge.weightv564.json` 等)
+  - Git untracked,是 Apollo 后台配置的本地参考副本
+  - 改这个文件**不会**自动同步到 Apollo 后台,运维要单独操作
+  - **修改 Apollo JSON 永远不要 commit**
+- `docs/` 目录、`实验配置/` 目录 — 本地资料,同上
+
+`git add` 时手动列文件名,**不要用 `git add -A` 或 `git add .`**,避免把这些误带进去。
+
+## 召回 / 排序架构
+
+- **召回是公共池**:`RecallService.getStrategies()` 给所有用户挂载一组召回策略,并发跑 Redis 拿候选视频写入候选池
+- **Rank 实验各挑各的**:每个 `RankStrategy4RegionMergeModelVxxx` 在 `mergeAndRankRovRecall()` 里通过 `RecallUtils.extractRecall(weight, param, PUSH_FROM/FORM, ...)` 按 `PUSH_FROM` 字符串挑想要的召回路
+- **推论**:往 `RecallService` 加新召回**不会自动**进任何 rank 实验,必须同时改对应 rank 类的 `extractRecall` 调用才能生效
+- **实验门控的两种模式**:
+  - 加法门(主流):`if (isHitXxxExp) strategies.add(...)` — 命中实验才挂载(842/568 用此模式)
+  - 减法门(V564 新增):`if (isHit564Exp) { strategies.add(...); strategies.removeIf(...) }` — 命中实验时挂新召回 + 剔除该实验不要的召回,省 Redis 调用
+- **`judgeHitExp` 用 `rootSessionId` 分桶**:同一用户同一会话里要么始终命中要么始终不命中,召回/排序天然对齐
+
+## 命名陷阱
+
+- `PUSH_FORM`(拼错的,6+ 处)vs `PUSH_FROM`(正确,3 处)在 recall strategy 里并存
+  - 加新策略时**用 `PUSH_FROM`**,别复制旧的拼错版本
+  - 写过滤逻辑时**别用 `pushFrom()` 字符串过滤**,改用 `getClass().getSimpleName()`,绕开这个不一致
+- 新建 RecallStrategy 时只要 `@Component implements RecallStrategy`,Spring 会自动按 `getClass().getSimpleName()` 注册到 `RecallService` 的 `strategyMap`,然后再去 `getStrategies()` 里 `add` 一行就生效
+
+## Apollo 配置
+
+- 文件名约定:`apollo/rank.score.merge.weightv{NNN}.json` 对应 rank 类的 `@ApolloJsonValue("${rank.score.merge.weightv{NNN}:}")`
+- Key 命名约定:`xxxRov` / `xxxRos` / `xxxStr` 等,与 `mergeWeight.getOrDefault("xxx", 默认值)` 一致
+- **改了 rank 类的 `extractRecall` 列表后,Apollo JSON 要同步清理废弃 key**(不会报错,但是死配置)
+- 代码里 `getOrDefault(key, 默认值)` 提供兜底,所以 Apollo 没配也能跑
+
+## V564 实验当前状态(2026-05-20 改动后)
+
+- **Base 是 V563**(DNN 打分 `feeds_score_config_dnn_20260407.conf` + cn/dn 特征 + `userNetworkSeqFeature`),不是 V569
+- 相比 V563:
+  - **召回侧**:剔除 9 路(5 路特殊旧召回 via `extractOldSpecialRecall` + v1 + priori_province 系列 3 路),新增 `province_rovn`
+  - **排序侧**:`provinceRov:5` 权重默认值(可在 Apollo JSON 覆盖)
+- 召回侧的剔除通过 `RecallService.java` 里 `if (isHit564Exp)` 块的 `removeIf` 实现,要回滚整块删除即可
+- 注意:V564 历史上曾经是 V569(XGB 系)的拷贝,2026-05-20 改为 V563 (DNN 系) 拷贝。如果以后看到 V564 用 XGB 配置出问题,多半是同步问题

+ 91 - 68
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV564.java

@@ -15,6 +15,7 @@ import com.tzld.piaoquan.recommend.server.service.recall.strategy.*;
 import com.tzld.piaoquan.recommend.server.service.score.ScorerUtils;
 import com.tzld.piaoquan.recommend.server.util.*;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -23,17 +24,19 @@ import org.springframework.stereotype.Service;
 import java.util.*;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
- * V564 实验:基于 V569,移除以下 8 路召回
- *   - recall_pool_region_h     (RegionHRecallStrategy)
- *   - recall_pool_24h          (RegionRelative24HRecallStrategy)
- *   - recall_pool_region_24h   (Region24HRecallStrategy)
- *   - rov_recall_24h_dup       (RegionRelative24HDupRecallStrategy)
- *   - rov_recall_h_h           (RegionHDupRecallStrategy)
- *   - priori_province_rovn     (PrioriProvinceRovnRecallStrategy)
- *   - priori_province_str      (PrioriProvinceStrRecallStrategy)
- *   - priori_province_ros      (PrioriProvinceRosRecallStrategy)
+ * V564 实验:基于 V563,改动召回组合
+ *   移除 9 路召回:
+ *     - 5 路特殊旧召回 (extractOldSpecialRecall: RegionH/Region24H/RegionHDup/RegionRelative24H/RegionRelative24HDup)
+ *     - v1                       (RegionRealtimeRecallStrategyV1)
+ *     - priori_province_rovn     (PrioriProvinceRovnRecallStrategy)
+ *     - priori_province_str      (PrioriProvinceStrRecallStrategy)
+ *     - priori_province_ros      (PrioriProvinceRosRecallStrategy)
+ *   新增 1 路召回:
+ *     - province_rovn            (ProvinceRovnRecallStrategy)
  */
 @Service
 @Slf4j
@@ -57,11 +60,13 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
         Set<Long> setVideo = new HashSet<>();
         setVideo.add(param.getHeadVid());
         List<Video> rovRecallRank = new ArrayList<>();
-        // V564: 移除 5 路特殊旧召回 (RegionH / RegionHDup / Region24H / RegionRelative24H / RegionRelative24HDup)
+        // V564: 移除 5 路特殊旧召回 (extractOldSpecialRecall)
+        // RecallUtils.extractOldSpecialRecall(mergeWeight.getOrDefault("oldSpecialN", (double) param.getSize()).intValue(), param, setVideo, rovRecallRank);
         //-------------------return相似召回------------------
         RecallUtils.extractRecall(mergeWeight.getOrDefault("v6", 5.0).intValue(), param, ReturnVideoRecallStrategy.PUSH_FORM, setVideo, rovRecallRank);
         //-------------------新地域召回------------------
-        RecallUtils.extractRecall(mergeWeight.getOrDefault("v1", 5.0).intValue(), param, RegionRealtimeRecallStrategyV1.PUSH_FORM, setVideo, rovRecallRank);
+        // V564: 移除 v1 新地域召回
+        // RecallUtils.extractRecall(mergeWeight.getOrDefault("v1", 5.0).intValue(), param, RegionRealtimeRecallStrategyV1.PUSH_FORM, setVideo, rovRecallRank);
         //-------------------scene cf rovn------------------
         RecallUtils.extractRecall(mergeWeight.getOrDefault("sceneCFRovn", 5.0).intValue(), param, SceneCFRovnRecallStrategy.PUSH_FORM, setVideo, rovRecallRank);
         //-------------------scene cf rosn------------------
@@ -78,13 +83,16 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
         RecallUtils.extractRecall(mergeWeight.getOrDefault("headCate2Rov", 5.0).intValue(), param, HeadCate2RovRecallStrategy.PUSH_FROM, setVideo, rovRecallRank);
         //-------------------city rovn------------------
         RecallUtils.extractRecall(mergeWeight.getOrDefault("cityRov", 5.0).intValue(), param, CityRovnRecallStrategy.PUSH_FROM, setVideo, rovRecallRank);
+        //-------------------province rovn------------------
+        RecallUtils.extractRecall(mergeWeight.getOrDefault("provinceRov", 5.0).intValue(), param, ProvinceRovnRecallStrategy.PUSH_FROM, setVideo, rovRecallRank);
         // V564: 移除 priori_province_rovn / priori_province_str / priori_province_ros
+        // RecallUtils.extractRecall(mergeWeight.getOrDefault("prioriProvinceRov", 3.0).intValue(), param, PrioriProvinceRovnRecallStrategy.PUSH_FROM, setVideo, rovRecallRank);
+        // RecallUtils.extractRecall(mergeWeight.getOrDefault("prioriProvinceStr", 1.0).intValue(), param, PrioriProvinceStrRecallStrategy.PUSH_FROM, setVideo, rovRecallRank);
+        // 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);
-        //--------------deconstruction keywords ros-------------
-        RecallUtils.extractRecall(mergeWeight.getOrDefault("deconstructionKeywordsRos", 5.0).intValue(), param, UserDeconstructionKeywordsRecallStrategy.PUSH_FORM, setVideo, rovRecallRank);
 
         // 记录召回源中的视频
         this.rankBeforePostProcessor(rovRecallRank);
@@ -98,8 +106,22 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
         // 1. 批量获取特征  省份参数要对齐  headvid  要传递过来!
         // k1:视频、k2:表、k3:特征、v:特征值
         Map<String, String> headVideoInfo = param.getHeadInfo();
+
+        // 用户的序列特征
+        Map<String, Map<String, String>> unionIdFeature = featureService.getUnionIdFeature(param.getUnionId());
+        Map<String, String> userNetworkSeqFeature = unionIdFeature.getOrDefault("alg_user_network_seq_feature", new HashMap<>());
+        List<String> actVidSeq = FeatureUtils.extractVidsFromUserNetworkSeqFeature(userNetworkSeqFeature, "a_v_s");
+        List<String> netVidSeq = FeatureUtils.extractVidsFromUserNetworkSeqFeature(userNetworkSeqFeature, "n_v_s");
+
         List<String> vids = CommonCollectionUtils.toListDistinct(rovRecallRank, v -> String.valueOf(v.getVideoId()));
-        Map<String, Map<String, Map<String, String>>> videoBaseInfoMap = featureService.getVideoBaseInfo("", vids);
+
+        List<String> allVids = Stream.of(actVidSeq, netVidSeq, vids)
+                .flatMap(Collection::stream)
+                .distinct()
+                .filter(StringUtils::isNotBlank)
+                .collect(Collectors.toList());
+
+        Map<String, Map<String, Map<String, String>>> videoBaseInfoMap = featureService.getVideoBaseInfo("", allVids);
         Map<String, Map<String, Map<String, String>>> videoBCData = featureService.getVideoStatistics(vids);
 
         FeatureService.Feature feature = featureService.getFeatureV4(param, headVideoInfo, videoBaseInfoMap, vids);
@@ -113,15 +135,20 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
         Map<String, Map<String, String>> userBehaviorVideoMap = param.getBehaviorVideos();
         Map<String, String> creativeInfo = param.getCreativeInfoFeature();
 
+        Map<String, String> featureMapToString = new HashMap<>();
+        FeatureV6.parseStringFeatureMap(featureMapToString, param);
+        FeatureV6.putVideoStringFeatures("h", headVideoInfo, featureMapToString);
+
         // 3. 特征处理
         List<RankItem> rankItems = CommonCollectionUtils.toList(rovRecallRank, RankItem::new);
         Map<String, Float> userFeatureMap = getUserFeature(currentMs, param, creativeInfo, headVideoInfo, userProfile, featureOriginUser);
         batchGetVideoFeature(currentMs, userProfile, creativeInfo, headVideoInfo, videoBaseInfoMap,
-                newC7Map, newC8Map, featureOriginUser, userBehaviorVideoMap, featureOriginVideo, rankItems);
+                newC7Map, newC8Map, featureOriginUser, userBehaviorVideoMap, featureOriginVideo, featureMapToString, userFeatureMap, rankItems);
+
 
         // 4. 排序模型计算
         Map<String, Float> sceneFeatureMap = new HashMap<>(0);
-        List<RankItem> items = ScorerUtils.getScorerPipeline("feeds_score_config_str_and_ros_20260319.conf").scoring(sceneFeatureMap, userFeatureMap, userFeatureMap, rankItems);
+        List<RankItem> items = ScorerUtils.getScorerPipeline("feeds_score_config_dnn_20260407.conf").scoring(sceneFeatureMap, userFeatureMap, rankItems);
 
         // 5. 排序公式特征
         double xgbRovNegRate = mergeWeight.getOrDefault("xgbRovNegRate", 0.059);
@@ -143,9 +170,15 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
         double b0Ror1hW = mergeWeight.getOrDefault("b0_ror_1h_w", 0d);
         double b0Ror24hW = mergeWeight.getOrDefault("b0_ror_24h_w", 0d);
 
+        double cnRovn1hW = mergeWeight.getOrDefault("cn_rovn_1h_w", 0d);
+        double cnRovn24hW = mergeWeight.getOrDefault("cn_rovn_24h_w", 0d);
+
+        double dnRovn1hW = mergeWeight.getOrDefault("dn_rovn_1h_w", 0d);
+        double dnRovn24hW = mergeWeight.getOrDefault("dn_rovn_24h_w", 0d);
+
         Map<String, Map<String, String>> vid2MapFeature = this.getVideoRedisFeature(vids, "redis:vid_hasreturn_vor:");
 
-        // 获取权重
+
         Map<String, String> contextInfo = getContextInfo(param);
 
         List<Video> result = new ArrayList<>();
@@ -159,8 +192,9 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
             double hasReturnRovScore = Double.parseDouble(vid2MapFeature.getOrDefault(item.getVideoId() + "", new HashMap<>()).getOrDefault("rov", "0"));
             item.getScoresMap().put("hasReturnRovScore", hasReturnRovScore);
 
-            double norXGBScore = item.getScoresMap().getOrDefault("NorXGBScore", 0d);
-            double newNorXGBScore = norPowerCalibration(xgbNorPowerWeight, xgbNorPowerExp, norXGBScore);
+            double norDNNScore = item.getScoresMap().getOrDefault("NorDNNScore", 0d);
+            double newNorDNNScore = norPowerCalibration(xgbNorPowerWeight, xgbNorPowerExp, norDNNScore);
+            item.getScoresMap().put("newNorDNNScore", newNorDNNScore);
             item.getScoresMap().put("rosAdd", rosAdd);
             item.getScoresMap().put("rosW", rosW);
 
@@ -170,6 +204,7 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
             item.getScoresMap().put("vorW", vorW);
 
             Map<String, String> bcData = videoBCData.getOrDefault(String.valueOf(item.getVideoId()), new HashMap<>()).getOrDefault("alg_vid_feature_b_c_data", new HashMap<>());
+            Map<String, String> cdNData = videoBCData.getOrDefault(String.valueOf(item.getVideoId()), new HashMap<>()).getOrDefault("alg_vid_feature_cn_dn_data", new HashMap<>());
 
             double c1Rovn1h = Double.parseDouble(bcData.getOrDefault("c1_rovn_1h", "0"));
             double c1Rovn24h = Double.parseDouble(bcData.getOrDefault("c1_rovn_24h", "0"));
@@ -189,6 +224,7 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
             item.getScoresMap().put("b0Str24hW", b0Str24hW);
             item.getScoresMap().put("b0Str24h", b0Str24h);
 
+
             double b0Ror1h = Double.parseDouble(bcData.getOrDefault("b_ror1_1h", "0"));
             double b0Ror24h = Double.parseDouble(bcData.getOrDefault("b_ror1_24h", "0"));
             double b0RorScore = b0Ror1hW * b0Ror1h + b0Ror24hW * b0Ror24h;
@@ -198,7 +234,25 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
             item.getScoresMap().put("b0Ror24hW", b0Ror24hW);
             item.getScoresMap().put("b0Ror24h", b0Ror24h);
 
-            score = fmRov * (rosAdd + rosW * newNorXGBScore) * (vorAdd + vorW * vor) + c1RovnScore + b0StrScore + b0RorScore;
+            double cnRovn1h = Double.parseDouble(cdNData.getOrDefault("cn_rovn_1h", "0"));
+            double cnRovn24h = Double.parseDouble(cdNData.getOrDefault("cn_rovn_24h", "0"));
+            double cnRovnScore = cnRovn1hW * cnRovn1h + cnRovn24hW * cnRovn24h;
+            item.getScoresMap().put("cnRovnScore", cnRovnScore);
+            item.getScoresMap().put("cnRovn1hW", cnRovn1hW);
+            item.getScoresMap().put("cnRovn1h", cnRovn1h);
+            item.getScoresMap().put("cnRovn24hW", cnRovn24hW);
+            item.getScoresMap().put("cnRovn24h", cnRovn24h);
+
+            double dnRovn1h = Double.parseDouble(cdNData.getOrDefault("dn_rovn_1h", "0"));
+            double dnRovn24h = Double.parseDouble(cdNData.getOrDefault("dn_rovn_24h", "0"));
+            double dnRovnScore = dnRovn1hW * dnRovn1h + dnRovn24hW * dnRovn24h;
+            item.getScoresMap().put("dnRovnScore", dnRovnScore);
+            item.getScoresMap().put("dnRovn1hW", dnRovn1hW);
+            item.getScoresMap().put("dnRovn1h", dnRovn1h);
+            item.getScoresMap().put("dnRovn24hW", dnRovn24hW);
+            item.getScoresMap().put("dnRovn24h", dnRovn24h);
+
+            score = fmRov * (rosAdd + rosW * newNorDNNScore) * (vorAdd + vorW * vor) + c1RovnScore + b0StrScore + b0RorScore + cnRovnScore + dnRovnScore;
 
             Video video = item.getVideo();
             video.setScore(score);
@@ -232,7 +286,7 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
             if (MapUtils.isNotEmpty(contextInfo)) {
                 video.getMetaFeatureMap().put("context", contextInfo);
             }
-            if (Objects.nonNull(video.getRankVideoInfoMap()) && video.getRankVideoInfoMap().containsKey(video.getVideoId())){
+            if (Objects.nonNull(video.getRankVideoInfoMap()) && video.getRankVideoInfoMap().containsKey(video.getVideoId())) {
                 video.getRankVideoInfoMap().get(video.getVideoId()).setScore(score);
                 video.getRankVideoInfoMap().get(video.getVideoId()).setScoresMap(video.getScoresMap());
             }
@@ -319,15 +373,28 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
                                       Map<String, Map<String, String>> userOriginInfo,
                                       Map<String, Map<String, String>> historyVideoMap,
                                       Map<String, Map<String, Map<String, String>>> videoOriginInfo,
+                                      Map<String, String> featureMapToString,
+                                      Map<String, Float> userFeatureMap,
                                       List<RankItem> rankItems) {
-        if (null != rankItems && !rankItems.isEmpty()) {
+        if (CollectionUtils.isNotEmpty(rankItems)) {
             List<Future<Integer>> futures = new ArrayList<>();
             for (RankItem item : rankItems) {
                 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, creativeInfo, headInfo, rankInfo, c7Map, c8Map, userOriginInfo, historyVideoMap, videoOriginInfo);
-                    item.norFeatureMap = item.featureMap;
+                    Map<String, Float> featureMap = new HashMap<>(userFeatureMap);
+                    Map<String, Float> videoFeature = getVideoFeature(currentMs, vid, userProfile, creativeInfo, headInfo, rankInfo, c7Map, c8Map, userOriginInfo, historyVideoMap, videoOriginInfo);
+                    featureMap.putAll(videoFeature);
+                    item.featureMap = featureMap;
+
+                    Map<String, String> userNetworkSeqFeature = userOriginInfo.getOrDefault("alg_user_network_seq_feature", new HashMap<>());
+
+                    Map<String, String> featureMapString = new HashMap<>(featureMapToString);
+                    FeatureV6.putVideoStringFeatures("r", rankInfo, featureMapString);
+                    featureMapString.put("r@vid", "r_vid_" + vid);
+                    FeatureV6.putProfileVideoCrossStringFeature(currentMs, userProfile, historyVideoMap, featureMapString);
+                    FeatureV6.putUserNetworkSeqFeature(featureMapString, userNetworkSeqFeature, videoBaseInfoMap);
+                    item.featureMapString = featureMapString;
                     return 1;
                 });
                 futures.add(future);
@@ -399,48 +466,4 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
         }
         return newScore;
     }
-
-    private Map<String, Double> findSimCateScore(String headCate2, int length) {
-        if (StringUtils.isBlank(headCate2)) {
-            return new HashMap<>();
-        }
-
-        String redisKey = String.format("alg_recsys_good_cate_pair_list:%s", headCate2);
-        String cate2Value = redisTemplate.opsForValue().get(redisKey);
-        if (StringUtils.isEmpty(cate2Value)) {
-            return new HashMap<>();
-        }
-
-        return this.parsePair(cate2Value, length);
-    }
-
-    private Map<String, Double> parsePair(String value, int length) {
-        if (StringUtils.isBlank(value)) {
-            return new HashMap<>();
-        }
-
-        String[] split = value.split("\t");
-        if (split.length != 2) {
-            return new HashMap<>();
-        }
-
-        String[] valueList = split[0].trim().split(",");
-        String[] scoreList = split[1].trim().split(",");
-        if (valueList.length != scoreList.length) {
-            return new HashMap<>();
-        }
-
-        int minLength = Math.min(length, valueList.length);
-        Map<String, Double> resultMap = new HashMap<>();
-        for (int i = 0; i < minLength; i++) {
-            resultMap.put(valueList[i].trim(), Double.parseDouble(scoreList[i].trim()));
-        }
-
-        return resultMap;
-    }
-
-    private String findVideoMergeCate2(Map<String, Map<String, Map<String, String>>> featureOriginVideo, String vid) {
-        Map<String, String> videoInfo = featureOriginVideo.getOrDefault(vid, new HashMap<>()).getOrDefault("alg_vid_feature_basic_info", new HashMap<>());
-        return videoInfo.get("merge_second_level_cate");
-    }
 }

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

@@ -153,6 +153,24 @@ public class RecallService implements ApplicationContextAware {
             strategies.add(strategyMap.get(YearReturnCate2RecallStrategy.class.getSimpleName()));
         }
 
+        boolean isHit564Exp = experimentService.judgeHitExp(param.getAppType(), param.getRootSessionId(), abExpCodes, "564");
+        if (isHit564Exp) {
+            strategies.add(strategyMap.get(ProvinceRovnRecallStrategy.class.getSimpleName()));
+            // V564: rank 侧不再 extract 以下 9 路召回,这里直接剔除避免无效 Redis 调用
+            Set<String> v564RemoveSet = new HashSet<>(Arrays.asList(
+                    RegionRealtimeRecallStrategyV1.class.getSimpleName(),
+                    RegionHRecallStrategy.class.getSimpleName(),
+                    Region24HRecallStrategy.class.getSimpleName(),
+                    RegionHDupRecallStrategy.class.getSimpleName(),
+                    RegionRelative24HRecallStrategy.class.getSimpleName(),
+                    RegionRelative24HDupRecallStrategy.class.getSimpleName(),
+                    PrioriProvinceRovnRecallStrategy.class.getSimpleName(),
+                    PrioriProvinceStrRecallStrategy.class.getSimpleName(),
+                    PrioriProvinceRosRecallStrategy.class.getSimpleName()
+            ));
+            strategies.removeIf(s -> s != null && v564RemoveSet.contains(s.getClass().getSimpleName()));
+        }
+
         // 命中用户黑名单不走流量池
         // 命中安全测试风险地域不走流量池
         if (!param.isRiskUser() && !param.isTestingRiskRegion()) {

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

@@ -0,0 +1,102 @@
+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 ProvinceRovnRecallStrategy 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 = "province_rovn";
+    public static final String redisKeyPrefix = "province_rovn_recall";
+
+    @Override
+    public String pushFrom() {
+        return PUSH_FROM;
+    }
+
+    @Override
+    public List<Video> recall(RecallParam param) {
+        List<Video> videosResult = new ArrayList<>();
+        try {
+            String province = param.getProvince().replaceAll("省$", "");
+            String redisKey = String.format("%s:%s", redisKeyPrefix, province);
+            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 (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);
+                    });
+                }
+            }
+        }
+    }
+}