丁云鹏 hai 11 meses
pai
achega
50ff8d6bde

+ 5 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/RecommendService.java

@@ -10,6 +10,7 @@ import com.tzld.longarticle.recommend.server.service.rank.RankService;
 import com.tzld.longarticle.recommend.server.service.recall.RecallParam;
 import com.tzld.longarticle.recommend.server.service.recall.RecallResult;
 import com.tzld.longarticle.recommend.server.service.recall.RecallService;
+import com.tzld.longarticle.recommend.server.util.JSONUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.BeanUtils;
@@ -36,9 +37,12 @@ public class RecommendService {
     public RecommendResponse recommend(RecommendRequest request) {
 
         RecommendParam param = genRecommendParam(request);
-
+        log.info("genRecommendParam {}", JSONUtils.toJson(param));
         RecallResult recallResult = recallService.recall(convertToRecallParam(param));
+        log.info("recallResult {}", JSONUtils.toJson(recallResult));
+
         RankResult rankResult = rankService.rank(convertToRankParam(param, recallResult));
+        log.info("rankResult {}", JSONUtils.toJson(rankResult));
 
         List<Content> contentList = rankResult.getContents();
         List<Content> filterContentList = new ArrayList<>();

+ 4 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/FilterService.java

@@ -4,6 +4,8 @@ import com.tzld.longarticle.recommend.server.common.ThreadPoolFactory;
 import com.tzld.longarticle.recommend.server.model.Content;
 import com.tzld.longarticle.recommend.server.service.ServiceBeanFactory;
 import com.tzld.longarticle.recommend.server.service.filter.strategy.*;
+import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
+import com.tzld.longarticle.recommend.server.util.JSONUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.stereotype.Service;
@@ -29,6 +31,8 @@ public class FilterService {
         FilterResult result = new FilterResult();
 
         List<FilterStrategy> strategies = getStrategies(param);
+        log.info("FilterStrategy {}", JSONUtils.toJson(CommonCollectionUtils.toList(strategies,
+                s -> s.getClass().getSimpleName())));
         CountDownLatch cdl = new CountDownLatch(strategies.size());
         List<Future<FilterResult>> futures = new ArrayList<>();
         for (final FilterStrategy strategy : strategies) {

+ 9 - 6
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/rank/RankService.java

@@ -6,11 +6,11 @@ import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigSer
 import com.tzld.longarticle.recommend.server.service.score.ScoreParam;
 import com.tzld.longarticle.recommend.server.service.score.ScoreResult;
 import com.tzld.longarticle.recommend.server.service.score.ScoreService;
-import com.tzld.longarticle.recommend.server.service.score.ScoreStrategy;
 import com.tzld.longarticle.recommend.server.service.score.strategy.ContentPoolStrategy;
 import com.tzld.longarticle.recommend.server.service.score.strategy.SimilarityStrategy;
 import com.tzld.longarticle.recommend.server.service.score.strategy.ViewCountStrategy;
 import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
+import com.tzld.longarticle.recommend.server.util.JSONUtils;
 import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
@@ -34,14 +34,17 @@ public class RankService {
 
     public RankResult rank(RankParam param) {
 
+        log.info("RankParam {}", JSONUtils.toJson(param));
         ScoreResult scoreResult = scoreService.score(convertToScoreParam(param));
-        Map<String, Map<Class<? extends ScoreStrategy>, Double>> scoreMap = scoreResult.getScoreMap();
+        log.info("ScoreResult {}", JSONUtils.toJson(scoreResult));
+
+        Map<String, Map<String, Double>> scoreMap = scoreResult.getScoreMap();
 
         List<RankItem> items = CommonCollectionUtils.toList(param.getContents(), c -> {
-            Map<Class<? extends ScoreStrategy>, Double> map = scoreMap.get(c.getId());
-            double score = 1 * map.getOrDefault(SimilarityStrategy.class, 0.0)
-                    + 10 * map.getOrDefault(ViewCountStrategy.class, 0.0)
-                    + 100 * map.getOrDefault(ContentPoolStrategy.class, 0.0);
+            Map<String, Double> map = scoreMap.get(c.getId());
+            double score = 1 * map.getOrDefault(SimilarityStrategy.class.getSimpleName(), 0.0)
+                    + 10 * map.getOrDefault(ViewCountStrategy.class.getSimpleName(), 0.0)
+                    + 100 * map.getOrDefault(ContentPoolStrategy.class.getSimpleName(), 0.0);
 
             RankItem item = new RankItem();
             item.setContent(c);

+ 5 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recall/RecallService.java

@@ -2,6 +2,8 @@ package com.tzld.longarticle.recommend.server.service.recall;
 
 import com.tzld.longarticle.recommend.server.common.ThreadPoolFactory;
 import com.tzld.longarticle.recommend.server.service.recall.strategy.DefaultRecallStrategy;
+import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
+import com.tzld.longarticle.recommend.server.util.JSONUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeansException;
 import org.springframework.context.ApplicationContext;
@@ -39,7 +41,10 @@ public class RecallService implements ApplicationContextAware {
     }
 
     public RecallResult recall(RecallParam param) {
+        log.info("RecallParam {}", JSONUtils.toJson(param));
         List<RecallStrategy> strategies = getRecallStrategy(param);
+        log.info("RecallStrategy {}", JSONUtils.toJson(CommonCollectionUtils.toList(strategies,
+                s -> s.getClass().getSimpleName())));
         CountDownLatch cdl = new CountDownLatch(strategies.size());
         List<Future<RecallResult.RecallData>> recallResultFutures = new ArrayList<>();
         for (final RecallStrategy strategy : strategies) {

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

@@ -13,7 +13,11 @@ import lombok.Setter;
 @AllArgsConstructor
 @NoArgsConstructor
 public class Score {
-    private Class<? extends ScoreStrategy> strategy;
+    private String strategy;
     private String contentId;
     private double score;
+
+    public void setStrategy(ScoreStrategy strategy) {
+        this.strategy = strategy.getClass().getSimpleName();
+    }
 }

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

@@ -15,5 +15,5 @@ import java.util.Map;
 @AllArgsConstructor
 @NoArgsConstructor
 public class ScoreResult {
-    private Map<String, Map<Class<? extends ScoreStrategy>, Double>> scoreMap;
+    private Map<String, Map<String, Double>> scoreMap;
 }

+ 7 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/ScoreService.java

@@ -4,6 +4,8 @@ package com.tzld.longarticle.recommend.server.service.score;
 import com.tzld.longarticle.recommend.server.common.ThreadPoolFactory;
 import com.tzld.longarticle.recommend.server.service.score.strategy.ContentPoolStrategy;
 import com.tzld.longarticle.recommend.server.service.score.strategy.SimilarityStrategy;
+import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
+import com.tzld.longarticle.recommend.server.util.JSONUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeansException;
 import org.springframework.context.ApplicationContext;
@@ -41,7 +43,10 @@ public class ScoreService implements ApplicationContextAware {
     }
 
     public ScoreResult score(ScoreParam param) {
+        log.info("ScoreParam {}", JSONUtils.toJson(param));
         List<ScoreStrategy> strategies = getScoreStrategy(param);
+        log.info("ScoreStrategy {}", JSONUtils.toJson(CommonCollectionUtils.toList(strategies,
+                s -> s.getClass().getSimpleName())));
         CountDownLatch cdl = new CountDownLatch(strategies.size());
         List<Future<List<Score>>> futures = new ArrayList<>();
         for (final ScoreStrategy strategy : strategies) {
@@ -59,12 +64,12 @@ public class ScoreService implements ApplicationContextAware {
             return null;
         }
 
-        Map<String, Map<Class<? extends ScoreStrategy>, Double>> scoreMap = new HashMap<>();
+        Map<String, Map<String, Double>> scoreMap = new HashMap<>();
         for (Future<List<Score>> f : futures) {
             try {
                 List<Score> data = f.get();
                 for (Score score : data) {
-                    Map<Class<? extends ScoreStrategy>, Double> map
+                    Map<String, Double> map
                             = scoreMap.computeIfAbsent(score.getContentId(), k -> new HashMap<>());
                     map.put(score.getStrategy(), score.getScore());
                 }

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

@@ -41,7 +41,7 @@ public class ContentPoolStrategy implements ScoreStrategy {
             score.setContentId(c.getId());
             double val = contentPoolScore.getOrDefault(c.getContentPoolType(), 0.0);
             score.setScore(NormalizationUtils.minMax(val, min, max));
-            score.setStrategy(this.getClass());
+            score.setStrategy(this);
             return score;
         });
         return scores;

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

@@ -43,7 +43,7 @@ public class SimilarityStrategy implements ScoreStrategy {
             score.setContentId(c.getId());
             double val = scoreMap.get(c.getId()) == null ? 0.0 : scoreMap.get(c.getId());
             score.setScore(NormalizationUtils.minMax(val, min, max));
-            score.setStrategy(this.getClass());
+            score.setStrategy(this);
             return score;
         });
         return scores;

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

@@ -38,7 +38,7 @@ public class ViewCountStrategy implements ScoreStrategy {
             score.setContentId(c.getId());
             double viewCount = c.getCrawlerViewCount() == null ? 0.0 : c.getCrawlerViewCount();
             score.setScore(NormalizationUtils.minMax(viewCount, min, max));
-            score.setStrategy(this.getClass());
+            score.setStrategy(this);
             return score;
         });
         return scores;

+ 3 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/RecommendV2Controller.java → long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/RecommendController.java

@@ -4,6 +4,7 @@ import com.tzld.longarticle.recommend.server.model.RecommendRequest;
 import com.tzld.longarticle.recommend.server.model.RecommendResponse;
 import com.tzld.longarticle.recommend.server.service.RecommendService;
 import com.tzld.longarticle.recommend.server.util.JSONUtils;
+import com.tzld.longarticle.recommend.server.util.TraceUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -15,12 +16,13 @@ import org.springframework.web.bind.annotation.RestController;
  */
 @RestController
 @Slf4j
-public class RecommendV2Controller {
+public class RecommendController {
     @Autowired
     private RecommendService recommendService;
 
     @RequestMapping("/recommend")
     public String homepageRecommend(@RequestBody RecommendRequest httpRequest) {
+
         RecommendResponse response = recommendService.recommend(httpRequest);
 
         return JSONUtils.toJson(response);