Browse Source

关键词过滤拆分

wangyunpeng 4 months ago
parent
commit
43d8247b23

+ 6 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/filter/strategy/KeywordStrategy.java

@@ -18,6 +18,8 @@ public class KeywordStrategy implements FilterStrategy {
 
     @ApolloJsonValue("${keywords:[]}")
     private static List<String> keywords;
+    @ApolloJsonValue("${sensitive.ban.keywords:[]}")
+    private static List<String> sensitiveBanKeywords;
 
     @Override
     public FilterResult filter(FilterParam param) {
@@ -26,8 +28,11 @@ public class KeywordStrategy implements FilterStrategy {
         List<String> result = new ArrayList<>();
         List<Content> contents = param.getContents();
         List<Content> filterContents = new ArrayList<>();
+        List<String> banKeywords = new ArrayList<>();
+        banKeywords.addAll(keywords);
+        banKeywords.addAll(sensitiveBanKeywords);
         for (Content content : contents) {
-            for (String keyword : keywords) {
+            for (String keyword : banKeywords) {
                 if (content.getTitle().contains(keyword)) {
                     content.setFilterReason("关键词过滤");
                     filterContents.add(content);