Browse Source

新增账号指定参考账号计算相似度

wangyunpeng 7 months ago
parent
commit
ffc3053ecc

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

@@ -57,7 +57,6 @@ public class NLPRemoteService {
         String url = scoreListUrl;
         JSONObject bodyParam = new JSONObject();
         bodyParam.put("gh_id_list", Collections.singletonList(ghId));
-        bodyParam.put("account_nickname_list", Collections.singletonList(accountName));
         bodyParam.put("text_list", titleList);
         bodyParam.put("interest_type", accountScoreInterestTypeMap.getOrDefault(accountName, "avg"));
         bodyParam.put("sim_type", accountScoreSimTypeMap.getOrDefault(accountName, "mean"));

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

@@ -1,6 +1,9 @@
 package com.tzld.longarticle.recommend.server.service.recommend.score.strategy;
 
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
+import com.tzld.longarticle.recommend.server.common.enums.recommend.ArticleTypeEnum;
 import com.tzld.longarticle.recommend.server.remote.NLPRemoteService;
+import com.tzld.longarticle.recommend.server.repository.crawler.ArticleRepository;
 import com.tzld.longarticle.recommend.server.service.recommend.score.Score;
 import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreParam;
 import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreStrategy;
@@ -23,6 +26,11 @@ public class SimilarityStrategy implements ScoreStrategy {
 
     @Autowired
     private NLPRemoteService nlpRemoteService;
+    @Autowired
+    private ArticleRepository articleRepository;
+
+    @ApolloJsonValue("${account.score.sim.replace:{}}")
+    private Map<String, String> accountSimScoreReplaceMap;
 
     @Override
     public List<Score> score(ScoreParam param) {
@@ -31,7 +39,15 @@ public class SimilarityStrategy implements ScoreStrategy {
         if (CollectionUtils.isEmpty(param.getContents())) {
             return Collections.emptyList();
         }
-        Map<String, Double> scoreMap = nlpRemoteService.score(param.getGhId(), param.getAccountName(), param.getContents());
+        String ghId = param.getGhId();
+        if (accountSimScoreReplaceMap.containsKey(ghId)) {
+            int historyCount = articleRepository.countByGhIdAndTypeAndItemIndex(ghId,
+                    ArticleTypeEnum.QUNFA.getVal(), 1);
+            if (historyCount < 10) {
+                ghId = accountSimScoreReplaceMap.get(ghId);
+            }
+        }
+        Map<String, Double> scoreMap = nlpRemoteService.score(ghId, param.getAccountName(), param.getContents());
 
 //        double min = scoreMap.values().stream()
 //                .min(Double::compareTo)