Bladeren bron

渠道ROV召回

jch 1 maand geleden
bovenliggende
commit
63eb5b0f20

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

@@ -10,6 +10,7 @@ import com.tzld.piaoquan.recommend.server.service.rank.extractor.ExtractorUtils;
 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.CommonCollectionUtils;
+import com.tzld.piaoquan.recommend.server.util.FeatureUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.math3.util.Pair;
@@ -19,6 +20,7 @@ import org.springframework.stereotype.Service;
 import java.util.*;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
 import java.util.stream.Collectors;
 
 @Service
@@ -59,28 +61,31 @@ public class RankStrategy4RegionMergeModelV568 extends RankStrategy4RegionMergeM
         v6 = v6.subList(0, Math.min(mergeWeight.getOrDefault("v6", 5.0).intValue(), v6.size()));
         rovRecallRank.addAll(v6);
         setVideo.addAll(v6.stream().map(Video::getVideoId).collect(Collectors.toSet()));
-        //-------------------新地域召回------------------
-        List<Video> v1 = extractAndSort(param, RegionRealtimeRecallStrategyV1.PUSH_FORM);
-        v1 = v1.stream().filter(r -> !setVideo.contains(r.getVideoId())).collect(Collectors.toList());
-        v1 = v1.subList(0, Math.min(mergeWeight.getOrDefault("v1", 5.0).intValue(), v1.size()));
-        rovRecallRank.addAll(v1);
-        setVideo.addAll(v1.stream().map(Video::getVideoId).collect(Collectors.toSet()));
-        //-------------------scene cf rovn------------------
-        List<Video> sceneCFRovn = extractAndSort(param, SceneCFRovnRecallStrategy.PUSH_FORM);
-        sceneCFRovn = sceneCFRovn.stream().filter(r -> !setVideo.contains(r.getVideoId())).collect(Collectors.toList());
-        sceneCFRovn = sceneCFRovn.subList(0, Math.min(mergeWeight.getOrDefault("sceneCFRovn", 5.0).intValue(), sceneCFRovn.size()));
-        rovRecallRank.addAll(sceneCFRovn);
-        setVideo.addAll(sceneCFRovn.stream().map(Video::getVideoId).collect(Collectors.toSet()));
-        //-------------------scene cf rosn------------------
-        List<Video> sceneCFRosn = extractAndSort(param, SceneCFRosnRecallStrategy.PUSH_FORM);
-        sceneCFRosn = sceneCFRosn.stream().filter(r -> !setVideo.contains(r.getVideoId())).collect(Collectors.toList());
-        sceneCFRosn = sceneCFRosn.subList(0, Math.min(mergeWeight.getOrDefault("sceneCFRosn", 5.0).intValue(), sceneCFRosn.size()));
-        rovRecallRank.addAll(sceneCFRosn);
-        setVideo.addAll(sceneCFRosn.stream().map(Video::getVideoId).collect(Collectors.toSet()));
 
-        // channel rov
-        int channelROVN = mergeWeight.getOrDefault("channelROVN", 5.0).intValue();
-        addRecall(param, channelROVN, ChannelROVRecallStrategy.PUSH_FORM, setVideo, rovRecallRank);
+        Matcher matcher = FeatureUtils.getChannelMatcher(param.getRootSourceId());
+        if (null != matcher && matcher.find() && FeatureUtils.firstLevel(param.getUserShareDepth())) {
+            int channelROVN = mergeWeight.getOrDefault("channelROVN", 5.0).intValue();
+            addRecall(param, channelROVN, ChannelROVRecallStrategy.PUSH_FORM, setVideo, rovRecallRank);
+        } else {
+            //-------------------新地域召回------------------
+            List<Video> v1 = extractAndSort(param, RegionRealtimeRecallStrategyV1.PUSH_FORM);
+            v1 = v1.stream().filter(r -> !setVideo.contains(r.getVideoId())).collect(Collectors.toList());
+            v1 = v1.subList(0, Math.min(mergeWeight.getOrDefault("v1", 5.0).intValue(), v1.size()));
+            rovRecallRank.addAll(v1);
+            setVideo.addAll(v1.stream().map(Video::getVideoId).collect(Collectors.toSet()));
+            //-------------------scene cf rovn------------------
+            List<Video> sceneCFRovn = extractAndSort(param, SceneCFRovnRecallStrategy.PUSH_FORM);
+            sceneCFRovn = sceneCFRovn.stream().filter(r -> !setVideo.contains(r.getVideoId())).collect(Collectors.toList());
+            sceneCFRovn = sceneCFRovn.subList(0, Math.min(mergeWeight.getOrDefault("sceneCFRovn", 5.0).intValue(), sceneCFRovn.size()));
+            rovRecallRank.addAll(sceneCFRovn);
+            setVideo.addAll(sceneCFRovn.stream().map(Video::getVideoId).collect(Collectors.toSet()));
+            //-------------------scene cf rosn------------------
+            List<Video> sceneCFRosn = extractAndSort(param, SceneCFRosnRecallStrategy.PUSH_FORM);
+            sceneCFRosn = sceneCFRosn.stream().filter(r -> !setVideo.contains(r.getVideoId())).collect(Collectors.toList());
+            sceneCFRosn = sceneCFRosn.subList(0, Math.min(mergeWeight.getOrDefault("sceneCFRosn", 5.0).intValue(), sceneCFRosn.size()));
+            rovRecallRank.addAll(sceneCFRosn);
+            setVideo.addAll(sceneCFRosn.stream().map(Video::getVideoId).collect(Collectors.toSet()));
+        }
 
         //-------------------排-------------------
         //-------------------序-------------------

+ 18 - 24
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/ChannelROVRecallStrategy.java

@@ -17,7 +17,6 @@ import org.springframework.stereotype.Component;
 
 import java.util.*;
 import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 @Component
@@ -30,13 +29,11 @@ public class ChannelROVRecallStrategy implements RecallStrategy {
     @Qualifier("redisTemplate")
     public RedisTemplate<String, String> redisTemplate;
 
-    private static final String channelRegex = "(longArticles_|dyyjs_|touliu_tencent_|touliu_tencentgzh_|touliu_tencentGzhArticle_|GzhTouLiu_Articles_gh)";
-    private static final Pattern channelPattern = Pattern.compile(channelRegex);
-
-    public static final String PUSH_FORM = "recall_strategy_channel";
-    public static final String redisKeyPrefix = "channel_recall";
     public static final String channelGroupPrefix = "alg_recsys_user_channel_group";
 
+    public static final String PUSH_FORM = "recall_strategy_channel_rovn";
+    public static final String redisKeyPrefix = "channel_rovn_recall";
+
     @Override
     public String pushFrom() {
         return PUSH_FORM;
@@ -105,25 +102,22 @@ public class ChannelROVRecallStrategy implements RecallStrategy {
         }
     }
 
-
     private String getChannelName(String s) {
-        if (null != s && !s.isEmpty()) {
-            Matcher matcher = channelPattern.matcher(s);
-            if (matcher.find()) {
-                switch (matcher.group(0)) {
-                    case "longArticles_":
-                        return getChannelType(s);
-                    case "dyyjs_":
-                        return "公众号代运营-即转";
-                    case "touliu_tencent_":
-                        return "小程序投流";
-                    case "touliu_tencentgzh_":
-                    case "touliu_tencentGzhArticle_":
-                    case "GzhTouLiu_Articles_gh":
-                        return "公众号投流";
-                    default:
-                        return "";
-                }
+        Matcher matcher = FeatureUtils.getChannelMatcher(s);
+        if (null != matcher && matcher.find()) {
+            switch (matcher.group(0)) {
+                case "longArticles_":
+                    return getChannelType(s);
+                case "dyyjs_":
+                    return "公众号代运营-即转";
+                case "touliu_tencent_":
+                    return "小程序投流";
+                case "touliu_tencentgzh_":
+                case "touliu_tencentGzhArticle_":
+                case "GzhTouLiu_Articles_gh":
+                    return "公众号投流";
+                default:
+                    return "";
             }
         }
         return "";

+ 9 - 10
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/util/FeatureUtils.java

@@ -17,11 +17,11 @@ public class FeatureUtils {
     private static final String goodMorningRegex = "(早安|早上好|早晨好|上午好)";
     private static final String goodAfternoonRegex = "(午安|中午好|下午好)";
     private static final String goodEveningRegex = "(晚安|晚上好)";
-    private static final String lowFissionChannelRegex = "(longArticles_|dyyjs_|daitou_tencentgzh|DaiTou_gh)";
+    private static final String channelRegex = "(longArticles_|dyyjs_|touliu_tencent_|touliu_tencentgzh_|touliu_tencentGzhArticle_|GzhTouLiu_Articles_gh)";
     private static final Pattern goodMorningPattern = Pattern.compile(goodMorningRegex);
     private static final Pattern goodAfternoonPattern = Pattern.compile(goodAfternoonRegex);
     private static final Pattern goodEveningPattern = Pattern.compile(goodEveningRegex);
-    private static final Pattern lowFissionChannelPattern = Pattern.compile(lowFissionChannelRegex);
+    private static final Pattern channelPattern = Pattern.compile(channelRegex);
 
     static {
         cate1MAP.put("情感", 1);
@@ -149,15 +149,14 @@ public class FeatureUtils {
         return value > 1E-8;
     }
 
-    public static boolean lowFissionChannel(String s) {
-        if (null != s && !s.isEmpty()) {
-            Matcher morning = lowFissionChannelPattern.matcher(s);
-            return morning.find();
-        }
-        return false;
-    }
-
     public static boolean firstLevel(Integer userShareDepth) {
         return null != userShareDepth && 0 == userShareDepth;
     }
+
+    public static Matcher getChannelMatcher(String s) {
+        if (null != s && !s.isEmpty()) {
+            return channelPattern.matcher(s);
+        }
+        return null;
+    }
 }