Merge branch 'master' into zj_groupshop
Showing
9 changed files
with
18 additions
and
148 deletions
@@ -21,7 +21,7 @@ import org.springframework.stereotype.Component; | @@ -21,7 +21,7 @@ import org.springframework.stereotype.Component; | ||
21 | import org.springframework.util.Assert; | 21 | import org.springframework.util.Assert; |
22 | 22 | ||
23 | import com.yoho.search.base.utils.SearchPageIdDefine; | 23 | import com.yoho.search.base.utils.SearchPageIdDefine; |
24 | -import com.yoho.search.core.personalized.PersonalizedSearch; | 24 | +import com.yoho.search.core.personalized.models.PersonalizedSearch; |
25 | import com.yoho.search.models.FirstShelveTimeScore; | 25 | import com.yoho.search.models.FirstShelveTimeScore; |
26 | import com.yoho.search.service.scorer.YohoFilterFunctionBuilders; | 26 | import com.yoho.search.service.scorer.YohoFilterFunctionBuilders; |
27 | import com.yoho.search.common.SearchDynamicConfigService; | 27 | import com.yoho.search.common.SearchDynamicConfigService; |
@@ -2,7 +2,7 @@ package com.yoho.search.service.recall.beans.builder; | @@ -2,7 +2,7 @@ package com.yoho.search.service.recall.beans.builder; | ||
2 | 2 | ||
3 | import com.yoho.search.base.utils.CollectionUtils; | 3 | import com.yoho.search.base.utils.CollectionUtils; |
4 | import com.yoho.search.base.utils.Transfer; | 4 | import com.yoho.search.base.utils.Transfer; |
5 | -import com.yoho.search.core.personalized.PersonalizedSearch; | 5 | +import com.yoho.search.core.personalized.models.PersonalizedSearch; |
6 | import com.yoho.search.core.personalized.models.SortPriceAreas; | 6 | import com.yoho.search.core.personalized.models.SortPriceAreas; |
7 | import com.yoho.search.service.recall.beans.persional.ProductFeatureFactorComponent; | 7 | import com.yoho.search.service.recall.beans.persional.ProductFeatureFactorComponent; |
8 | import com.yoho.search.service.recall.config.RecallConfigConstants; | 8 | import com.yoho.search.service.recall.config.RecallConfigConstants; |
1 | package com.yoho.search.service.recall.beans.persional; | 1 | package com.yoho.search.service.recall.beans.persional; |
2 | 2 | ||
3 | import com.yoho.search.base.helper.Word2VectorCalculator; | 3 | import com.yoho.search.base.helper.Word2VectorCalculator; |
4 | -import com.yoho.search.core.personalized.PersonalizedSearch; | 4 | +import com.yoho.search.core.personalized.models.PersonalizedSearch; |
5 | import com.yoho.search.service.recall.models.personal.UserFeatureFactor; | 5 | import com.yoho.search.service.recall.models.personal.UserFeatureFactor; |
6 | import org.apache.commons.lang.StringUtils; | 6 | import org.apache.commons.lang.StringUtils; |
7 | import org.slf4j.Logger; | 7 | import org.slf4j.Logger; |
1 | package com.yoho.search.service.recall.beans.persional; | 1 | package com.yoho.search.service.recall.beans.persional; |
2 | 2 | ||
3 | -import com.alibaba.fastjson.JSON; | ||
4 | -import com.alibaba.fastjson.JSONObject; | ||
5 | -import com.yoho.core.rest.client.ServiceCaller; | ||
6 | -import com.yoho.search.core.personalized.models.*; | 3 | +import com.yoho.search.core.personalized.models.UserPersonalFactorRspNew; |
4 | +import com.yoho.search.core.personalized.service.BidataServiceCaller; | ||
7 | import org.slf4j.Logger; | 5 | import org.slf4j.Logger; |
8 | import org.slf4j.LoggerFactory; | 6 | import org.slf4j.LoggerFactory; |
9 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -16,11 +14,9 @@ import java.util.List; | @@ -16,11 +14,9 @@ import java.util.List; | ||
16 | public class UserPersionalFactorComponent { | 14 | public class UserPersionalFactorComponent { |
17 | 15 | ||
18 | private static final Logger RECALL_NEW_LOGGER = LoggerFactory.getLogger("RECALL"); | 16 | private static final Logger RECALL_NEW_LOGGER = LoggerFactory.getLogger("RECALL"); |
19 | - private static final String SERVICE_NAME = "bigdata.searchPersonalFactors"; | ||
20 | - private static final int timeOut = 100; | ||
21 | 17 | ||
22 | @Autowired | 18 | @Autowired |
23 | - private ServiceCaller serviceCaller; | 19 | + private BidataServiceCaller bidataServiceCaller; |
24 | 20 | ||
25 | /** | 21 | /** |
26 | * 获取用户的个性化因子 | 22 | * 获取用户的个性化因子 |
@@ -31,10 +27,7 @@ public class UserPersionalFactorComponent { | @@ -31,10 +27,7 @@ public class UserPersionalFactorComponent { | ||
31 | */ | 27 | */ |
32 | public UserPersonalFactorRspNew queryUserPersionalFactor(int uid, String udid, List<Integer> misortIds) { | 28 | public UserPersonalFactorRspNew queryUserPersionalFactor(int uid, String udid, List<Integer> misortIds) { |
33 | try { | 29 | try { |
34 | - UserPersonalFactorReq userPersionalFactorReq = new UserPersonalFactorReq(uid, udid, misortIds); | ||
35 | - JSONObject result = serviceCaller.call(SERVICE_NAME, userPersionalFactorReq, JSONObject.class, timeOut); | ||
36 | - JSONObject userPersonalFactorRspJSon = result.getJSONObject("data"); | ||
37 | - UserPersonalFactorRspNew rsp = JSON.toJavaObject(userPersonalFactorRspJSon, UserPersonalFactorRspNew.class); | 30 | + UserPersonalFactorRspNew rsp = bidataServiceCaller.queryUserPersionalFactor(uid, udid, misortIds); |
38 | if (rsp == null) { | 31 | if (rsp == null) { |
39 | rsp = new UserPersonalFactorRspNew(); | 32 | rsp = new UserPersonalFactorRspNew(); |
40 | } | 33 | } |
1 | package com.yoho.search.service.recall.models.personal; | 1 | package com.yoho.search.service.recall.models.personal; |
2 | 2 | ||
3 | -import com.yoho.search.core.personalized.PersonalizedSearch; | 3 | +import com.yoho.search.core.personalized.models.PersonalizedSearch; |
4 | 4 | ||
5 | import java.util.ArrayList; | 5 | import java.util.ArrayList; |
6 | import java.util.List; | 6 | import java.util.List; |
@@ -3,7 +3,7 @@ package com.yoho.search.service.scorer.personal; | @@ -3,7 +3,7 @@ package com.yoho.search.service.scorer.personal; | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | import com.yoho.search.cache.CacheType; | 4 | import com.yoho.search.cache.CacheType; |
5 | import com.yoho.search.aop.cache.SearchCacheAble; | 5 | import com.yoho.search.aop.cache.SearchCacheAble; |
6 | -import com.yoho.search.core.personalized.BigDataRedisService; | 6 | +import com.yoho.search.core.personalized.service.BidataServiceCaller; |
7 | import org.slf4j.Logger; | 7 | import org.slf4j.Logger; |
8 | import org.slf4j.LoggerFactory; | 8 | import org.slf4j.LoggerFactory; |
9 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -17,14 +17,14 @@ public class PersonalGenderFeatureSearch { | @@ -17,14 +17,14 @@ public class PersonalGenderFeatureSearch { | ||
17 | private static final Logger logger = LoggerFactory.getLogger(PersonalGenderFeatureSearch.class); | 17 | private static final Logger logger = LoggerFactory.getLogger(PersonalGenderFeatureSearch.class); |
18 | 18 | ||
19 | @Autowired | 19 | @Autowired |
20 | - private BigDataRedisService bigDataRedisService; | 20 | + private BidataServiceCaller bidataServiceCaller; |
21 | 21 | ||
22 | @SearchCacheAble(cacheInMinute = 30, cacheName = "USER_GENDER_FEATURE", returnClass = JSONObject.class, cacheType = CacheType.SEARCH_REDIS, includeParams = {"uid"}) | 22 | @SearchCacheAble(cacheInMinute = 30, cacheName = "USER_GENDER_FEATURE", returnClass = JSONObject.class, cacheType = CacheType.SEARCH_REDIS, includeParams = {"uid"}) |
23 | public JSONObject queryUserGenderFeature(Map<String, String> paramMap) { | 23 | public JSONObject queryUserGenderFeature(Map<String, String> paramMap) { |
24 | try { | 24 | try { |
25 | JSONObject jsonObject = new JSONObject(); | 25 | JSONObject jsonObject = new JSONObject(); |
26 | - Map<String, Float> userGenderFloat = bigDataRedisService.getUserGenderFeature(paramMap.getOrDefault("uid", "0")); | ||
27 | - if(userGenderFloat!=null){ | 26 | + Map<String, Float> userGenderFloat = bidataServiceCaller.getUserGenderFeature(paramMap.getOrDefault("uid", "0")); |
27 | + if (userGenderFloat != null) { | ||
28 | jsonObject.putAll(userGenderFloat); | 28 | jsonObject.putAll(userGenderFloat); |
29 | } | 29 | } |
30 | return jsonObject; | 30 | return jsonObject; |
1 | package com.yoho.search.service.scorer.personal; | 1 | package com.yoho.search.service.scorer.personal; |
2 | 2 | ||
3 | -import com.yoho.search.base.utils.DateUtil; | ||
4 | -import com.yoho.search.cache.CacheType; | ||
5 | import com.yoho.search.aop.cache.SearchCacheAble; | 3 | import com.yoho.search.aop.cache.SearchCacheAble; |
6 | -import com.yoho.search.core.personalized.BigDataRedisService; | ||
7 | -import com.yoho.search.core.personalized.PersonalizedSearch; | ||
8 | -import com.yoho.search.core.personalized.version.PersonalVersionManager; | 4 | +import com.yoho.search.cache.CacheType; |
5 | +import com.yoho.search.core.personalized.models.PersonalizedSearch; | ||
6 | +import com.yoho.search.core.personalized.service.BidataServiceCaller; | ||
7 | +import com.yoho.search.core.personalized.service.PersonalVersionManager; | ||
9 | import org.apache.commons.lang3.StringUtils; | 8 | import org.apache.commons.lang3.StringUtils; |
10 | import org.slf4j.Logger; | 9 | import org.slf4j.Logger; |
11 | import org.slf4j.LoggerFactory; | 10 | import org.slf4j.LoggerFactory; |
12 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
13 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
14 | 13 | ||
15 | -import java.util.Calendar; | ||
16 | -import java.util.HashMap; | ||
17 | import java.util.Map; | 14 | import java.util.Map; |
18 | 15 | ||
19 | @Service | 16 | @Service |
@@ -21,13 +18,10 @@ public class PersonalVectorFeatureSearch { | @@ -21,13 +18,10 @@ public class PersonalVectorFeatureSearch { | ||
21 | 18 | ||
22 | private static final Logger logger = LoggerFactory.getLogger(PersonalVectorFeatureSearch.class); | 19 | private static final Logger logger = LoggerFactory.getLogger(PersonalVectorFeatureSearch.class); |
23 | 20 | ||
24 | - private static final Double BASE_CONSTANT = 1.0D; | ||
25 | - private static final Double FACTOR_CONSTANT = 0.8D; | ||
26 | - | ||
27 | @Autowired | 21 | @Autowired |
28 | private PersonalVersionManager personalVersionManager; | 22 | private PersonalVersionManager personalVersionManager; |
29 | @Autowired | 23 | @Autowired |
30 | - private BigDataRedisService bigDataRedisService; | 24 | + private BidataServiceCaller bidataServiceCaller; |
31 | 25 | ||
32 | @SearchCacheAble(cacheInMinute = 30, cacheName = "PERSIONAL_VECTOR", returnClass = PersonalizedSearch.class, cacheType = CacheType.SEARCH_REDIS, includeParams = { "uid" }) | 26 | @SearchCacheAble(cacheInMinute = 30, cacheName = "PERSIONAL_VECTOR", returnClass = PersonalizedSearch.class, cacheType = CacheType.SEARCH_REDIS, includeParams = { "uid" }) |
33 | public PersonalizedSearch getPersonalizedSearch(Map<String, String> paramMap) { | 27 | public PersonalizedSearch getPersonalizedSearch(Map<String, String> paramMap) { |
@@ -43,7 +37,7 @@ public class PersonalVectorFeatureSearch { | @@ -43,7 +37,7 @@ public class PersonalVectorFeatureSearch { | ||
43 | return null; | 37 | return null; |
44 | } | 38 | } |
45 | // 3. 获取用户的特征向量 | 39 | // 3. 获取用户的特征向量 |
46 | - String userVectorFeature = bigDataRedisService.getUserVectorFeature(uid, vectorFeatureVersion); | 40 | + String userVectorFeature = bidataServiceCaller.getUserVectorFeature(uid, vectorFeatureVersion); |
47 | if (StringUtils.isEmpty(userVectorFeature)) { | 41 | if (StringUtils.isEmpty(userVectorFeature)) { |
48 | return null; | 42 | return null; |
49 | } | 43 | } |
@@ -53,99 +47,5 @@ public class PersonalVectorFeatureSearch { | @@ -53,99 +47,5 @@ public class PersonalVectorFeatureSearch { | ||
53 | return null; | 47 | return null; |
54 | } | 48 | } |
55 | } | 49 | } |
56 | - | ||
57 | - /** | ||
58 | - * 根据UID和SKN列表获取特征相关性评分,该方法用于测试和问题定位 | ||
59 | - * | ||
60 | - * @param uid | ||
61 | - * 用户标识 | ||
62 | - * @param productVectorFeatureMap | ||
63 | - * 商品特征map | ||
64 | - * @return 相关性计算结果 | ||
65 | - */ | ||
66 | - public Map<String, Object> calVectorFeature(String uid, String version, Map<String, String> productVectorFeatureMap) { | ||
67 | - Map<String, Object> scoreMap = new HashMap<>(); | ||
68 | - if (productVectorFeatureMap == null || productVectorFeatureMap.isEmpty()) { | ||
69 | - scoreMap.put("productVectorFeatureMap", "empty"); | ||
70 | - return scoreMap; | ||
71 | - } | ||
72 | - | ||
73 | - String vectorFeatureVersion = StringUtils.isNotEmpty(version) ? version : personalVersionManager.getCurrentVersionInZk(); | ||
74 | - scoreMap.put("vectorFeatureVersion", vectorFeatureVersion); | ||
75 | - if (StringUtils.isEmpty(vectorFeatureVersion) || "-1".equals(vectorFeatureVersion)) { | ||
76 | - return scoreMap; | ||
77 | - } | ||
78 | - | ||
79 | - // 2. 获取用户的特征向量 | ||
80 | - String userVectorFeature = bigDataRedisService.getUserVectorFeature(uid, vectorFeatureVersion); | ||
81 | - scoreMap.put("userVectorFeature", userVectorFeature); | ||
82 | - if (StringUtils.isEmpty(userVectorFeature)) { | ||
83 | - return scoreMap; | ||
84 | - } | ||
85 | - | ||
86 | - String[] userFeatureFactorArr = userVectorFeature.split(","); | ||
87 | - double tempUserFeatureVectorNorm = 0.0D; | ||
88 | - int dimensionOfFactors = userFeatureFactorArr.length; | ||
89 | - double[] userFeatureFactors = new double[dimensionOfFactors]; | ||
90 | - double temp; | ||
91 | - for (int index = 0; index < dimensionOfFactors; index++) { | ||
92 | - temp = Double.parseDouble(userFeatureFactorArr[index].trim()); | ||
93 | - userFeatureFactors[index] = temp; | ||
94 | - tempUserFeatureVectorNorm += temp * temp; | ||
95 | - } | ||
96 | - | ||
97 | - final double userFeatureVectorNorm = tempUserFeatureVectorNorm; | ||
98 | - scoreMap.put("userFeatureVectorNorm", userFeatureVectorNorm); | ||
99 | - scoreMap.put("dimensionOfFactors", dimensionOfFactors); | ||
100 | - | ||
101 | - // 3. 计算相关性得分 | ||
102 | - productVectorFeatureMap.forEach((skn, vector) -> { | ||
103 | - Map<String, Object> content = new HashMap<String, Object>(); | ||
104 | - content.put("vector", vector); | ||
105 | - content.put("score", calculateScore(vector, vectorFeatureVersion, userFeatureFactors, userFeatureVectorNorm)); | ||
106 | - scoreMap.put(skn, content); | ||
107 | - }); | ||
108 | - | ||
109 | - return scoreMap; | ||
110 | - } | ||
111 | - | ||
112 | - public double calculateScore(String productFeatureFactor, String vectorFeatureVersion, double[] userFeatureFactors, double userFeatureVectorNorm) { | ||
113 | - if (productFeatureFactor == null || productFeatureFactor.trim().isEmpty()) { | ||
114 | - return BASE_CONSTANT; | ||
115 | - } | ||
116 | - | ||
117 | - String versionPrefix = vectorFeatureVersion + "|"; | ||
118 | - if (!productFeatureFactor.trim().startsWith(versionPrefix)) { | ||
119 | - return BASE_CONSTANT; | ||
120 | - } | ||
121 | - | ||
122 | - String[] productFeatureFactorArr = productFeatureFactor.trim().substring(versionPrefix.length()).split(","); | ||
123 | - if (productFeatureFactorArr == null || productFeatureFactorArr.length != userFeatureFactors.length) { | ||
124 | - return BASE_CONSTANT; | ||
125 | - } | ||
126 | - | ||
127 | - double prodFeatureVectorNorm = 0.0D; | ||
128 | - double productiveSum = 0.0D; | ||
129 | - double tempProdFactor; | ||
130 | - for (int i = 0; i < userFeatureFactors.length; i++) { | ||
131 | - tempProdFactor = Double.parseDouble(productFeatureFactorArr[i].trim()); | ||
132 | - productiveSum += tempProdFactor * userFeatureFactors[i]; | ||
133 | - prodFeatureVectorNorm += tempProdFactor * tempProdFactor; | ||
134 | - } | ||
135 | - | ||
136 | - if (prodFeatureVectorNorm == 0) { | ||
137 | - return BASE_CONSTANT; | ||
138 | - } | ||
139 | - | ||
140 | - double cosScore = productiveSum / (Math.sqrt(prodFeatureVectorNorm) * Math.sqrt(userFeatureVectorNorm)); | ||
141 | - double finalScore = BASE_CONSTANT + FACTOR_CONSTANT * cosScore; | ||
142 | - return finalScore; | ||
143 | - } | ||
144 | - | ||
145 | - public static void main(String[] args) { | ||
146 | - Calendar now = Calendar.getInstance(); | ||
147 | - now.add(Calendar.YEAR, -1); | ||
148 | - System.out.println(DateUtil.getFirstTimeSecond(now.getTime())); | ||
149 | - } | ||
150 | 50 | ||
151 | } | 51 | } |
@@ -17,15 +17,3 @@ redis: | @@ -17,15 +17,3 @@ redis: | ||
17 | readOnly: | 17 | readOnly: |
18 | - 192.168.102.216:6379 | 18 | - 192.168.102.216:6379 |
19 | primary: no | 19 | primary: no |
20 | - | ||
21 | - yohoSearchBigDataRedis: | ||
22 | - cluster: false | ||
23 | - sync: false | ||
24 | - auth: | ||
25 | - timeout: 1000 | ||
26 | - servers: | ||
27 | - - 192.168.102.216:6379 | ||
28 | - readOnly: | ||
29 | - - 192.168.102.216:6379 | ||
30 | - primary: no | ||
31 | - |
@@ -18,14 +18,3 @@ redis: | @@ -18,14 +18,3 @@ redis: | ||
18 | - ${search.redis.address}:${search.redis.port} | 18 | - ${search.redis.address}:${search.redis.port} |
19 | primary: no | 19 | primary: no |
20 | 20 | ||
21 | - yohoSearchBigDataRedis: | ||
22 | - cluster: false | ||
23 | - sync: false | ||
24 | - auth: ${bigDataRedis-search.proxy.auth} | ||
25 | - timeout: 1000 | ||
26 | - servers: | ||
27 | - - ${bigDataRedis-search.proxy.address}:${bigDataRedis-search.proxy.port} | ||
28 | - readOnly: | ||
29 | - - ${bigDataRedis-search.proxy.address}:${bigDataRedis-search.proxy.port} | ||
30 | - primary: no | ||
31 | - |
-
Please register or login to post a comment