Browse Source

strategyIndexScoreWeightConfig

wangyunpeng 9 months ago
parent
commit
47917c36f6

+ 31 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/StrategyIndexScoreWeightService.java

@@ -0,0 +1,31 @@
+package com.tzld.longarticle.recommend.server.service;
+
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+
+@Component
+@Slf4j
+public class StrategyIndexScoreWeightService {
+
+    @ApolloJsonValue("${strategyIndexScoreWeightConfig:{}}")
+    private Map<String, Map<String, Map<String, Double>>> strategyIndexScoreWeightMap;
+
+    public double getWeight(String strategy, Integer index, String score) {
+        Map<String, Map<String, Double>> indexMap = strategyIndexScoreWeightMap.get(strategy);
+        if (indexMap == null) {
+            return 1.0;
+        }
+        Map<String, Double> scoreMap = indexMap.get(String.valueOf(index));
+        if (scoreMap == null) {
+            return 1.0;
+        }
+        Double weight = scoreMap.get(score);
+        if (weight == null) {
+            return 1.0;
+        }
+        return weight;
+    }
+}

+ 22 - 7
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/rank/strategy/RankV11Strategy.java

@@ -1,8 +1,9 @@
 package com.tzld.longarticle.recommend.server.service.rank.strategy;
 
 
-import com.tzld.longarticle.recommend.server.model.Content;
+import com.tzld.longarticle.recommend.server.model.dto.Content;
 import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigService;
+import com.tzld.longarticle.recommend.server.service.StrategyIndexScoreWeightService;
 import com.tzld.longarticle.recommend.server.service.rank.RankItem;
 import com.tzld.longarticle.recommend.server.service.rank.RankParam;
 import com.tzld.longarticle.recommend.server.service.rank.RankResult;
@@ -32,6 +33,8 @@ public class RankV11Strategy implements RankStrategy {
     private ScoreService scoreService;
     @Autowired
     private AccountContentPoolConfigService accountContentPoolConfigService;
+    @Autowired
+    private StrategyIndexScoreWeightService weightService;
 
     public RankResult rank(RankParam param) {
         List<Content> result = new ArrayList<>();
@@ -49,19 +52,31 @@ public class RankV11Strategy implements RankStrategy {
             item.setScoreMap(scoreMap.get(c.getId()));
             double score;
             if (contentPools[0].equals(item.getContent().getContentPoolType())) {
-                score = item.getScore(HisFissionAvgReadRateRateStrategy.class.getSimpleName());
-                score += item.getScore(SimilarityStrategy.class.getSimpleName());
+                score = item.getScore(HisFissionAvgReadRateRateStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 1,
+                        HisFissionAvgReadRateRateStrategy.class.getSimpleName());
+                score += item.getScore(SimilarityStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 1,
+                        SimilarityStrategy.class.getSimpleName());
             } else if (contentPools[1].equals(item.getContent().getContentPoolType())) {
-                score = item.getScore(SimilarityStrategy.class.getSimpleName())
+                score = (item.getScore(SimilarityStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 2,
+                        SimilarityStrategy.class.getSimpleName()))
                         + item.getScore(CategoryStrategy.class.getSimpleName())
                         + item.getScore(FlowCtlDecreaseStrategy.class.getSimpleName());
                 if (item.getScore(PublishTimesStrategy.class.getSimpleName()) >= 0) {
-                    score += item.getScore(ViewCountRateStrategy.class.getSimpleName());
+                    score += item.getScore(ViewCountRateStrategy.class.getSimpleName())
+                            * weightService.getWeight(param.getStrategy(), 2,
+                            ViewCountRateStrategy.class.getSimpleName());
                 }
             } else {
-                score = item.getScore(SimilarityStrategy.class.getSimpleName())
+                score = (item.getScore(SimilarityStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 3,
+                        SimilarityStrategy.class.getSimpleName()))
                         + item.getScore(CategoryStrategy.class.getSimpleName())
-                        + item.getScore(AccountPreDistributeStrategy.class.getSimpleName())
+                        + (item.getScore(AccountPreDistributeStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 3,
+                        AccountPreDistributeStrategy.class.getSimpleName()))
                         + item.getScore(PublishTimesStrategy.class.getSimpleName())
                         + item.getScore(FlowCtlDecreaseStrategy.class.getSimpleName());
             }

+ 22 - 7
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/rank/strategy/RankV12Strategy.java

@@ -1,8 +1,9 @@
 package com.tzld.longarticle.recommend.server.service.rank.strategy;
 
 
-import com.tzld.longarticle.recommend.server.model.Content;
+import com.tzld.longarticle.recommend.server.model.dto.Content;
 import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigService;
+import com.tzld.longarticle.recommend.server.service.StrategyIndexScoreWeightService;
 import com.tzld.longarticle.recommend.server.service.rank.RankItem;
 import com.tzld.longarticle.recommend.server.service.rank.RankParam;
 import com.tzld.longarticle.recommend.server.service.rank.RankResult;
@@ -32,6 +33,8 @@ public class RankV12Strategy implements RankStrategy {
     private ScoreService scoreService;
     @Autowired
     private AccountContentPoolConfigService accountContentPoolConfigService;
+    @Autowired
+    private StrategyIndexScoreWeightService weightService;
 
     public RankResult rank(RankParam param) {
         List<Content> result = new ArrayList<>();
@@ -49,19 +52,31 @@ public class RankV12Strategy implements RankStrategy {
             item.setScoreMap(scoreMap.get(c.getId()));
             double score;
             if (contentPools[0].equals(item.getContent().getContentPoolType())) {
-                score = item.getScore(HisFissionDeWeightAvgReadSumRateStrategy.class.getSimpleName());
-                score += item.getScore(SimilarityStrategy.class.getSimpleName());
+                score = item.getScore(HisFissionDeWeightAvgReadSumRateStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 1,
+                        HisFissionDeWeightAvgReadSumRateStrategy.class.getSimpleName());
+                score += item.getScore(SimilarityStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 1,
+                        SimilarityStrategy.class.getSimpleName());
             } else if (contentPools[1].equals(item.getContent().getContentPoolType())) {
-                score = item.getScore(SimilarityStrategy.class.getSimpleName())
+                score = (item.getScore(SimilarityStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 2,
+                        SimilarityStrategy.class.getSimpleName()))
                         + item.getScore(CategoryStrategy.class.getSimpleName())
                         + item.getScore(FlowCtlDecreaseStrategy.class.getSimpleName());
                 if (item.getScore(PublishTimesStrategy.class.getSimpleName()) >= 0) {
-                    score += item.getScore(ViewCountRateStrategy.class.getSimpleName());
+                    score += item.getScore(ViewCountRateStrategy.class.getSimpleName())
+                            * weightService.getWeight(param.getStrategy(), 2,
+                            ViewCountRateStrategy.class.getSimpleName());
                 }
             } else {
-                score = item.getScore(SimilarityStrategy.class.getSimpleName())
+                score = (item.getScore(SimilarityStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 3,
+                        SimilarityStrategy.class.getSimpleName()))
                         + item.getScore(CategoryStrategy.class.getSimpleName())
-                        + item.getScore(AccountPreDistributeStrategy.class.getSimpleName())
+                        + (item.getScore(AccountPreDistributeStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 3,
+                        AccountPreDistributeStrategy.class.getSimpleName()))
                         + item.getScore(PublishTimesStrategy.class.getSimpleName())
                         + item.getScore(FlowCtlDecreaseStrategy.class.getSimpleName());
             }

+ 1 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/strategy/HisFissionDeWeightAvgReadSumRateStrategy.java

@@ -1,6 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.score.strategy;
 
-import com.tzld.longarticle.recommend.server.model.Content;
+import com.tzld.longarticle.recommend.server.model.dto.Content;
 import com.tzld.longarticle.recommend.server.service.AccountIndexAvgViewCountService;
 import com.tzld.longarticle.recommend.server.service.score.Score;
 import com.tzld.longarticle.recommend.server.service.score.ScoreParam;