wangyunpeng 13 часов назад
Родитель
Сommit
ca7a18308e

+ 5 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/RankItem.java

@@ -15,9 +15,11 @@ public class RankItem {
     private double score;
 
     public double getScore(String strategy) {
-        return scoreMap.get(strategy) == null
-                ? 0.0
-                : scoreMap.get(strategy);
+        Double value = scoreMap == null ? null : scoreMap.get(strategy);
+        if (value == null || Double.isNaN(value) || Double.isInfinite(value)) {
+            return 0.0;
+        }
+        return value;
     }
 
 }

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

@@ -762,7 +762,8 @@ public class RecallService implements ApplicationContextAware {
                 t0FissionByReadAvgSum += article.getT0FissionByReadAvg();
                 t0FissionByReadAvgCorrelationSum += article.getT0FissionByReadAvg() * correlation;
             }
-            if (Objects.nonNull(article.getAvgOpenRate()) && article.getAvgOpenRate() > 0) {
+            if (Objects.nonNull(article.getAvgOpenRate()) && article.getAvgOpenRate() > 0
+                    && Objects.nonNull(article.getViewCount()) && article.getViewCount() > 0) {
                 openRateAvgRate += (sumFirstLevel * 1.0 / article.getViewCount()) / article.getAvgOpenRate();
             }
             int hour = DateUtils.getHourByTimestamp(article.getPublishTimestamp());

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

@@ -84,9 +84,15 @@ public class ScoreService implements ApplicationContextAware {
             try {
                 List<Score> data = f.get();
                 for (Score score : data) {
+                    Double scoreValue = score.getScore();
+                    if (scoreValue == null || Double.isNaN(scoreValue) || Double.isInfinite(scoreValue)) {
+                        log.warn("Invalid score detected: strategy={}, contentId={}, score={}",
+                                score.getStrategy(), score.getContentId(), scoreValue);
+                        continue;
+                    }
                     Map<String, Double> map
                             = scoreMap.computeIfAbsent(score.getContentId(), k -> new HashMap<>());
-                    map.put(score.getStrategy(), score.getScore());
+                    map.put(score.getStrategy(), scoreValue);
                 }
             } catch (Exception e) {
                 log.error("future get error ", e);

+ 3 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/score/strategy/I2IRecommendStrategy.java

@@ -48,6 +48,9 @@ public class I2IRecommendStrategy implements ScoreStrategy {
                     if (TitleSimilarCheckUtil.isSimilar(content.getTitle(), i2IRecommend.getRecommendTitle(),
                             TitleSimilarCheckUtil.ARTICLE_PROMOTION_THRESHOLD)) {
                         Double recommendScore = i2IRecommend.getRecommendScore();
+                        if (recommendScore == null || recommendScore <= 0) {
+                            break;
+                        }
                         // ① log 压缩(解决你的极端长尾)
                         double eps = 1e-6;
                         double logScore = Math.log(recommendScore + eps);

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

@@ -100,6 +100,9 @@ public class SimilarityStrategy implements ScoreStrategy {
             Score score = new Score();
             score.setContentId(c.getId());
             double val = scoreMap.get(c.getId()) == null ? 0.0 : scoreMap.get(c.getId());
+            if (Double.isNaN(val) || Double.isInfinite(val)) {
+                val = 0.0;
+            }
             score.setScore(val);
             score.setStrategy(this);
             return score;