Browse Source

去重逻辑按内容池顺序去重 不记录日志

wangyunpeng 11 months ago
parent
commit
ddd91c73d3

+ 42 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/enums/ContentPoolEnum.java

@@ -0,0 +1,42 @@
+package com.tzld.longarticle.recommend.server.common.enums;
+
+import lombok.Getter;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+@Getter
+public enum ContentPoolEnum {
+    autoArticlePoolLevel1("autoArticlePoolLevel1", "内容池1层"),
+    autoArticlePoolLevel2("autoArticlePoolLevel2", "内容池2层"),
+    autoArticlePoolLevel3("autoArticlePoolLevel3", "冷启层"),
+
+    ;
+
+
+    private final String contentPool;
+    private final String description;
+
+    ContentPoolEnum(String contentPool, String description) {
+        this.contentPool = contentPool;
+        this.description = description;
+    }
+
+    public static ContentPoolEnum from(String contentPool) {
+        for (ContentPoolEnum poolEnum : ContentPoolEnum.values()) {
+            if (Objects.equals(poolEnum.contentPool, contentPool)) {
+                return poolEnum;
+            }
+        }
+        return autoArticlePoolLevel3;
+    }
+
+    public static List<String> getOrderContentPool() {
+        List<String> result = new ArrayList<>();
+        result.add(autoArticlePoolLevel1.getContentPool());
+        result.add(autoArticlePoolLevel2.getContentPool());
+        result.add(autoArticlePoolLevel3.getContentPool());
+        return result;
+    }
+}

+ 2 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/RecommendRequest.java

@@ -4,8 +4,6 @@ import lombok.Getter;
 import lombok.NoArgsConstructor;
 import lombok.Setter;
 
-import java.util.List;
-
 /**
  * @author dyp
  */
@@ -20,5 +18,7 @@ public class RecommendRequest {
     private String strategy;
     private Integer publishNum;
     private String planId;
+    // true 不记录日志
+    private boolean excludeLog = false;
 }
 

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

@@ -18,5 +18,7 @@ public class RecommendParam {
     private String strategy;
     private Integer publishNum;
     private String planId;
+    // true 不记录日志
+    private boolean excludeLog = false;
 }
 

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

@@ -148,7 +148,7 @@ public class RecommendService {
      * @param rankResult
      */
     private void saveSortLog(RecommendParam param, RankResult rankResult) {
-        if (!"prod".equals(env)) {
+        if (!"prod".equals(env) || param.isExcludeLog()) {
             return;
         }
         PublishContentSortLog log = new PublishContentSortLog();

+ 10 - 6
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/rank/strategy/DefaultRankStrategy.java

@@ -1,6 +1,7 @@
 package com.tzld.longarticle.recommend.server.service.rank.strategy;
 
 
+import com.tzld.longarticle.recommend.server.common.enums.ContentPoolEnum;
 import com.tzld.longarticle.recommend.server.model.Content;
 import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigService;
 import com.tzld.longarticle.recommend.server.service.rank.RankItem;
@@ -133,12 +134,15 @@ public class DefaultRankStrategy implements RankStrategy {
         List<String> titles = new ArrayList<>();
         List<Content> result = new ArrayList<>();
         // 遍历所有列表
-        for (Content c : contents) {
-            if (similarity(c.getTitle(), titles)) {
-                continue;
-            } else {
-                result.add(c);
-                titles.add(c.getTitle());
+        for (String contentPool : ContentPoolEnum.getOrderContentPool()) {
+            for (Content c : contents) {
+                if (!contentPool.equals(c.getContentPoolType())) {
+                    continue;
+                }
+                if (!similarity(c.getTitle(), titles)) {
+                    result.add(c);
+                    titles.add(c.getTitle());
+                }
             }
         }
 

+ 10 - 6
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/rank/strategy/RankV3Strategy.java

@@ -1,6 +1,7 @@
 package com.tzld.longarticle.recommend.server.service.rank.strategy;
 
 
+import com.tzld.longarticle.recommend.server.common.enums.ContentPoolEnum;
 import com.tzld.longarticle.recommend.server.model.Content;
 import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigService;
 import com.tzld.longarticle.recommend.server.service.rank.RankItem;
@@ -163,12 +164,15 @@ public class RankV3Strategy implements RankStrategy {
         List<String> titles = new ArrayList<>();
         List<Content> result = new ArrayList<>();
         // 遍历所有列表
-        for (Content c : contents) {
-            if (similarity(c.getTitle(), titles)) {
-                continue;
-            } else {
-                result.add(c);
-                titles.add(c.getTitle());
+        for (String contentPool : ContentPoolEnum.getOrderContentPool()) {
+            for (Content c : contents) {
+                if (!contentPool.equals(c.getContentPoolType())) {
+                    continue;
+                }
+                if (!similarity(c.getTitle(), titles)) {
+                    result.add(c);
+                    titles.add(c.getTitle());
+                }
             }
         }