Ver código fonte

homepage recommend

丁云鹏 1 ano atrás
pai
commit
49ba3b254e

+ 2 - 16
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/RecommendService.java

@@ -82,21 +82,7 @@ public class RecommendService {
         log.info("genHomepageRecommendParam : {}", JSONUtils.toJson(param));
 
 
-        List<Video> videos;
-        String ab_code = param.getAb_code();
-        if (ab_code.equals("60054") || ab_code.equals("60056") || ab_code.equals("60067")
-                || ab_code.equals("60068") || ab_code.equals("60066") || ab_code.equals("60069")
-                || ab_code.equals("60070") || ab_code.equals("60071") || ab_code.equals("60072")
-                || ab_code.equals("60073") || ab_code.equals("60074") || ab_code.equals("60075")
-                || ab_code.equals("60076") || ab_code.equals("60077") || ab_code.equals("60078")
-                || ab_code.equals("60079") || ab_code.equals("60080") || ab_code.equals("60081")
-                || ab_code.equals("60082") || ab_code.equals("60083") || ab_code.equals("60084")
-                || ab_code.equals("60085") || ab_code.equals("60086")) {
-            videos = videoRecommendOld(request, param);
-        } else {
-            videos = videoRecommendNew(request, param);
-        }
-
+        List<Video> videos = videoRecommend(request, param);
         List<Video> result = new ArrayList<>();
         int i = 0;
         for (Video v : videos) {
@@ -109,7 +95,7 @@ public class RecommendService {
         return null;
     }
 
-    private List<Video> videoRecommendNew(HomepageRecommendRequest request, HomepageRecommendParam param) {
+    private List<Video> videoRecommend(HomepageRecommendRequest request, HomepageRecommendParam param) {
         // TODO
         RecallParam recallParam = new RecallParam();
         RecallResult recallResult = recallService.recall(recallParam);

+ 1 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/RankParam.java

@@ -13,4 +13,5 @@ public class RankParam {
     private int topK;
     private String rankKeyPrefix;
     private double flowPoolP;
+    private String abCode;
 }

+ 47 - 13
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/RankService.java

@@ -1,6 +1,7 @@
 package com.tzld.piaoquan.recommend.server.service.rank;
 
 import com.tzld.piaoquan.recommend.server.model.Video;
+import com.tzld.piaoquan.recommend.server.service.recall.strategy.*;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.RandomUtils;
 import org.apache.commons.lang3.math.NumberUtils;
@@ -26,19 +27,7 @@ public class RankService {
         }
 
         // rank rov recall
-        List<String> videoIdKeys = param.getRecallResult().getRovPoolRecall().stream()
-                .map(t -> param.getRankKeyPrefix() + t.getVideoId())
-                .collect(Collectors.toList());
-        List<Video> rov_recall_rank = param.getRecallResult().getRovPoolRecall().stream()
-                .collect(Collectors.toList());
-        List<String> video_scores = redisTemplate.opsForValue().multiGet(videoIdKeys);
-        if (CollectionUtils.isNotEmpty(video_scores)
-                && video_scores.size() == rov_recall_rank.size()) {
-            for (int i = 0; i < video_scores.size(); i++) {
-                rov_recall_rank.get(i).setRovScore(NumberUtils.toDouble(video_scores.get(i), 0.0));
-            }
-            Collections.sort(rov_recall_rank, Comparator.comparingDouble(o -> -o.getRovScore()));
-        }
+        List<Video> rov_recall_rank = rovRecallRank(param);
 
         // rank flow pool recall
         List<Video> flow_recall_rank = param.getRecallResult().getFlowPoolRecall().stream()
@@ -128,4 +117,49 @@ public class RankService {
         }
         return new RankResult(datas);
     }
+
+    private List<Video> rovRecallRank(RankParam param) {
+        if (param.getAbCode().equals("60054")
+                || param.getAbCode().equals("60068")
+                || param.getAbCode().equals("60081")
+                || param.getAbCode().equals("60084")) {
+
+            List<String> videoIdKeys = param.getRecallResult().getRovPoolRecall().stream()
+                    .map(t -> param.getRankKeyPrefix() + t.getVideoId())
+                    .collect(Collectors.toList());
+            List<Video> rov_recall_rank = param.getRecallResult().getRovPoolRecall().stream()
+                    .collect(Collectors.toList());
+            List<String> video_scores = redisTemplate.opsForValue().multiGet(videoIdKeys);
+            if (CollectionUtils.isNotEmpty(video_scores)
+                    && video_scores.size() == rov_recall_rank.size()) {
+                for (int i = 0; i < video_scores.size(); i++) {
+                    rov_recall_rank.get(i).setRovScore(NumberUtils.toDouble(video_scores.get(i), 0.0));
+                }
+                Collections.sort(rov_recall_rank, Comparator.comparingDouble(o -> -o.getRovScore()));
+            }
+            return rov_recall_rank;
+        } else {
+            List<Video> rov_recall_rank = new ArrayList<>();
+            rov_recall_rank.addAll(extractRovPoolAndSort(param, RegionHRecallStrategy.PUSH_FORM));
+            rov_recall_rank.addAll(extractRovPoolAndSort(param, Region24HRecallStrategy.PUSH_FORM));
+            rov_recall_rank.addAll(extractRovPoolAndSort(param, RegionRelative24HRecallStrategy.PUSH_FORM));
+            rov_recall_rank.addAll(extractRovPoolAndSort(param, RegionRelative24HDupRecallStrategy.PUSH_FORM));
+            rov_recall_rank.addAll(extractRovPoolAndSort(param, RegionRelative48HRecallStrategy.PUSH_FORM));
+            rov_recall_rank.addAll(extractRovPoolAndSort(param, RegionRelative48HDupRecallStrategy.PUSH_FORM));
+            return rov_recall_rank;
+        }
+    }
+
+    private List<Video> extractRovPoolAndSort(RankParam param, String pushForm) {
+        if (param == null
+                || param.getRecallResult() == null
+                || CollectionUtils.isEmpty(param.getRecallResult().getRovPoolRecall())) {
+            return Collections.emptyList();
+        }
+        return param.getRecallResult().getRovPoolRecall().stream()
+                .filter(o -> o.getPushFrom().equals(pushForm))
+                .sorted(Comparator.comparingDouble(o -> -o.getRovScore()))
+                .collect(Collectors.toList());
+    }
+
 }

+ 10 - 10
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/SpecialRegionRecallStrategy.java

@@ -3,10 +3,10 @@ package com.tzld.piaoquan.recommend.server.service.recall;
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import com.tzld.piaoquan.recommend.server.model.Video;
-import com.tzld.piaoquan.recommend.server.service.recall.strategy.Dup224HRegionRecallStrategy;
-import com.tzld.piaoquan.recommend.server.service.recall.strategy.Dup324HRegionRecallStrategy;
-import com.tzld.piaoquan.recommend.server.service.recall.strategy.Region24HRegionRecallStrategy;
-import com.tzld.piaoquan.recommend.server.service.recall.strategy.RegionHRegionRecallStrategy;
+import com.tzld.piaoquan.recommend.server.service.recall.strategy.RegionRelative24HRecallStrategy;
+import com.tzld.piaoquan.recommend.server.service.recall.strategy.RegionRelative24HDupRecallStrategy;
+import com.tzld.piaoquan.recommend.server.service.recall.strategy.Region24HRecallStrategy;
+import com.tzld.piaoquan.recommend.server.service.recall.strategy.RegionHRecallStrategy;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -73,13 +73,13 @@ public class SpecialRegionRecallStrategy implements ApplicationContextAware, Rec
 
         List<RecallStrategy> strategies = new ArrayList<>();
         if (regionCode.equals("-1")) {
-            strategies.add(strategyMap.get(Dup224HRegionRecallStrategy.class.getSimpleName()));
-            strategies.add(strategyMap.get(Dup324HRegionRecallStrategy.class.getSimpleName()));
+            strategies.add(strategyMap.get(RegionRelative24HRecallStrategy.class.getSimpleName()));
+            strategies.add(strategyMap.get(RegionRelative24HDupRecallStrategy.class.getSimpleName()));
         } else {
-            strategies.add(strategyMap.get(RegionHRegionRecallStrategy.class.getSimpleName()));
-            strategies.add(strategyMap.get(Region24HRegionRecallStrategy.class.getSimpleName()));
-            strategies.add(strategyMap.get(Dup224HRegionRecallStrategy.class.getSimpleName()));
-            strategies.add(strategyMap.get(Dup324HRegionRecallStrategy.class.getSimpleName()));
+            strategies.add(strategyMap.get(RegionHRecallStrategy.class.getSimpleName()));
+            strategies.add(strategyMap.get(Region24HRecallStrategy.class.getSimpleName()));
+            strategies.add(strategyMap.get(RegionRelative24HRecallStrategy.class.getSimpleName()));
+            strategies.add(strategyMap.get(RegionRelative24HDupRecallStrategy.class.getSimpleName()));
         }
 
         // execute

+ 4 - 2
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/Region24HRegionRecallStrategy.java → recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/Region24HRecallStrategy.java

@@ -9,7 +9,9 @@ import org.springframework.stereotype.Service;
  * @author dyp
  */
 @Service
-public class Region24HRegionRecallStrategy extends AbstractRegionRecallStrategy {
+public class Region24HRecallStrategy extends AbstractRegionRecallStrategy {
+    public static final String PUSH_FORM = "recall_pool_region_24h";
+
     @Override
     protected String recordKey(RecallParam param) {
         return String.format("recall:last:record:region:dup1:24h:%s:%s", param.getAppType(), param.getMid());
@@ -27,6 +29,6 @@ public class Region24HRegionRecallStrategy extends AbstractRegionRecallStrategy
 
     @Override
     protected String pushFrom() {
-        return "recall_pool_region_24h";
+        return PUSH_FORM;
     }
 }

+ 4 - 2
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/RegionHRegionRecallStrategy.java → recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/RegionHRecallStrategy.java

@@ -5,10 +5,12 @@ import org.springframework.stereotype.Service;
 
 /**
  * 分地域
+ *
  * @author dyp
  */
 @Service
-public class RegionHRegionRecallStrategy extends AbstractRegionRecallStrategy {
+public class RegionHRecallStrategy extends AbstractRegionRecallStrategy {
+    public static final String PUSH_FORM = "recall_pool_region_h";
 
     @Override
     protected String recordKey(RecallParam param) {
@@ -27,6 +29,6 @@ public class RegionHRegionRecallStrategy extends AbstractRegionRecallStrategy {
 
     @Override
     protected String pushFrom() {
-        return "recall_pool_region_h";
+        return PUSH_FORM;
     }
 }

+ 3 - 2
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/Dup324HRegionRecallStrategy.java → recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/RegionRelative24HDupRecallStrategy.java

@@ -9,7 +9,8 @@ import org.springframework.stereotype.Service;
  * @author dyp
  */
 @Service
-public class Dup324HRegionRecallStrategy extends AbstractRegionRecallStrategy {
+public class RegionRelative24HDupRecallStrategy extends AbstractRegionRecallStrategy {
+    public static final String PUSH_FORM = "rov_recall_24h_dup";
     @Override
     protected String recordKey(RecallParam param) {
         return String.format("recall:last:record:region:dup3:24h:%s:%s", param.getAppType(), param.getMid());
@@ -27,6 +28,6 @@ public class Dup324HRegionRecallStrategy extends AbstractRegionRecallStrategy {
 
     @Override
     protected String pushFrom() {
-        return "rov_recall_24h_dup";
+        return PUSH_FORM;
     }
 }

+ 4 - 2
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/Dup224HRegionRecallStrategy.java → recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/RegionRelative24HRecallStrategy.java

@@ -9,7 +9,9 @@ import org.springframework.stereotype.Service;
  * @author dyp
  */
 @Service
-public class Dup224HRegionRecallStrategy extends AbstractRegionRecallStrategy {
+public class RegionRelative24HRecallStrategy extends AbstractRegionRecallStrategy {
+    public static final String PUSH_FORM = "recall_pool_24h";
+
     @Override
     protected String recordKey(RecallParam param) {
         return String.format("recall:last:record:region:dup2:24h:%s:%s", param.getAppType(), param.getMid());
@@ -27,6 +29,6 @@ public class Dup224HRegionRecallStrategy extends AbstractRegionRecallStrategy {
 
     @Override
     protected String pushFrom() {
-        return "recall_pool_24h";
+        return PUSH_FORM;
     }
 }

+ 4 - 2
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/Dup348HRegionRecallStrategy.java → recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/RegionRelative48HDupRecallStrategy.java

@@ -9,7 +9,9 @@ import org.springframework.stereotype.Service;
  * @author dyp
  */
 @Service
-public class Dup348HRegionRecallStrategy extends AbstractRegionRecallStrategy {
+public class RegionRelative48HDupRecallStrategy extends AbstractRegionRecallStrategy {
+    public static final String PUSH_FORM = "rov_recall_48h_dup";
+
     @Override
     protected String recordKey(RecallParam param) {
         return String.format("recall:last:record:region:dup3:48h:%s:%s", param.getAppType(), param.getMid());
@@ -27,6 +29,6 @@ public class Dup348HRegionRecallStrategy extends AbstractRegionRecallStrategy {
 
     @Override
     protected String pushFrom() {
-        return "rov_recall_48h_dup";
+        return PUSH_FORM;
     }
 }

+ 4 - 2
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/Dup248HRegionRecallStrategy.java → recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/RegionRelative48HRecallStrategy.java

@@ -9,7 +9,9 @@ import org.springframework.stereotype.Service;
  * @author dyp
  */
 @Service
-public class Dup248HRegionRecallStrategy extends AbstractRegionRecallStrategy {
+public class RegionRelative48HRecallStrategy extends AbstractRegionRecallStrategy {
+    public static final String PUSH_FORM = "recall_pool_48h";
+
     @Override
     protected String recordKey(RecallParam param) {
         return String.format("recall:last:record:region:dup2:48h:%s:%s", param.getAppType(), param.getMid());
@@ -27,6 +29,6 @@ public class Dup248HRegionRecallStrategy extends AbstractRegionRecallStrategy {
 
     @Override
     protected String pushFrom() {
-        return "recall_pool_48h";
+        return PUSH_FORM;
     }
 }