瀏覽代碼

Merge branch 'feature_20260622_zhaohaipeng_feature_optimize_adaptive' of algorithm/recommend-server into master

zhaohaipeng 1 周之前
父節點
當前提交
d029e4ecc6

+ 1 - 0
.gitignore

@@ -62,3 +62,4 @@ recommend-server/logs
 LOG_PATH_IS_UNDEFINED
 datalog
 word2vec.bin
+recommend-server-service/recommend-server/logs

+ 13 - 5
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/FeatureService.java

@@ -17,6 +17,7 @@ import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
@@ -28,6 +29,9 @@ import java.util.*;
 @Slf4j
 public class FeatureService {
 
+    @Value("${feature.service.optimize.switch}")
+    private Boolean featureServiceOptimizeSwtich;
+
     @Autowired
     private FeatureV2RemoteService remoteService;
 
@@ -410,18 +414,22 @@ public class FeatureService {
                 Map<String, String> colMap = JSONUtils.fromJson(value, new TypeToken<Map<String, String>>() {
                 }, Collections.emptyMap());
 
-                String featureStr = colMap.get("feature");
+                Map<String, String> featureMap = new HashMap<>();
+                if (Boolean.TRUE.equals(featureServiceOptimizeSwtich)) {
+                    featureMap = colMap;
+                } else {
+                    featureMap = JSONUtils.fromJson(colMap.get("feature"), new TypeToken<Map<String, String>>() {
+                    }, Collections.emptyMap());
+                }
                 switch (prefix) {
                     case "v":
                         String vid = uk[2];
                         Map<String, Map<String, String>> tableFeatureMap = feature.getVideoFeature().getOrDefault(vid, new HashMap<>());
-                        tableFeatureMap.put(table, JSONUtils.fromJson(featureStr, new TypeToken<Map<String, String>>() {
-                        }, Collections.emptyMap()));
+                        tableFeatureMap.put(table, featureMap);
                         feature.getVideoFeature().put(vid, tableFeatureMap);
                         break;
                     case "u":
-                        feature.getUserFeature().put(table, JSONUtils.fromJson(featureStr, new TypeToken<Map<String, String>>() {
-                        }, Collections.emptyMap()));
+                        feature.getUserFeature().put(table, featureMap);
                         break;
                     default:
                         break;

+ 22 - 0
recommend-server-service/src/test/java/com/tzld/piaoquan/recommend/server/service/FeatureServiceTest.java

@@ -0,0 +1,22 @@
+package com.tzld.piaoquan.recommend.server.service;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+public class FeatureServiceTest {
+
+    @Autowired
+    private FeatureService featureService;
+
+    @Test
+    public void featureV3OptimizeTest() {
+
+        // List<FeatureKeyProto> protos = new ArrayList<>();
+        // protos.add(featureService.genWithKeyMap("alg_videoid_feature", "10035427", ImmutableMap.of("videoid", "68781839")));
+        //
+        // System.out.println(featureService.getFeatureByProto(protos));
+    }
+
+}