Authored by hugufei

调大数据接口调失败不能影响业务

1 package com.yoho.search.service.scorer; 1 package com.yoho.search.service.scorer;
2 2
3 -import java.util.ArrayList;  
4 -import java.util.List;  
5 -import java.util.Map;  
6 -  
7 -import org.elasticsearch.index.query.QueryBuilder;  
8 -import org.springframework.beans.factory.annotation.Autowired;  
9 -import org.springframework.stereotype.Component;  
10 -  
11 import com.yoho.search.core.personalized.BigDataRedisService; 3 import com.yoho.search.core.personalized.BigDataRedisService;
12 import com.yoho.search.models.FirstShelveTimeScore; 4 import com.yoho.search.models.FirstShelveTimeScore;
13 import com.yoho.search.service.base.SearchDynamicConfigService; 5 import com.yoho.search.service.base.SearchDynamicConfigService;
14 import com.yoho.search.service.base.SearchRequestParams; 6 import com.yoho.search.service.base.SearchRequestParams;
15 import com.yoho.search.service.helper.SearchCommonHelper; 7 import com.yoho.search.service.helper.SearchCommonHelper;
16 -import com.yoho.search.service.scorer.impl.AddScoreSknScorer;  
17 -import com.yoho.search.service.scorer.impl.BreakSizeProductScorer;  
18 -import com.yoho.search.service.scorer.impl.FeatureFactorScorer;  
19 -import com.yoho.search.service.scorer.impl.FirstProductSknScorer;  
20 -import com.yoho.search.service.scorer.impl.FirstShelveTimeScorer;  
21 -import com.yoho.search.service.scorer.impl.GlobalProductScorer;  
22 -import com.yoho.search.service.scorer.impl.NewArriveHeatDescScorer;  
23 -import com.yoho.search.service.scorer.impl.ProblemProductScorer;  
24 -import com.yoho.search.service.scorer.impl.RandomScorer;  
25 -import com.yoho.search.service.scorer.impl.UserChannelSearchScorer; 8 +import com.yoho.search.service.scorer.impl.*;
  9 +import org.elasticsearch.index.query.QueryBuilder;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.stereotype.Component;
  14 +
  15 +import java.util.ArrayList;
  16 +import java.util.List;
  17 +import java.util.Map;
26 18
27 @Component 19 @Component
28 public class SearchScorerFactory { 20 public class SearchScorerFactory {
29 21
  22 + private static final Logger logger = LoggerFactory.getLogger(SearchScorerFactory.class);
  23 +
30 @Autowired 24 @Autowired
31 private BigDataRedisService bigDataRedisService; 25 private BigDataRedisService bigDataRedisService;
32 @Autowired 26 @Autowired
@@ -44,9 +38,15 @@ public class SearchScorerFactory { @@ -44,9 +38,15 @@ public class SearchScorerFactory {
44 38
45 // 获取【断码商品】的打分器 39 // 获取【断码商品】的打分器
46 public IScorer getBreakSizeProductScorer(Map<String, String> paramMap) { 40 public IScorer getBreakSizeProductScorer(Map<String, String> paramMap) {
47 - List<String> userFavoriteSizes = bigDataRedisService.getUserFavoriteSizes(paramMap.getOrDefault("uid", "0"));  
48 - IScorer breakSizeProductScorer = new BreakSizeProductScorer(userFavoriteSizes);  
49 - return breakSizeProductScorer; 41 + try {
  42 + List<String> userFavoriteSizes = bigDataRedisService.getUserFavoriteSizes(paramMap.getOrDefault("uid", "0"));
  43 + IScorer breakSizeProductScorer = new BreakSizeProductScorer(userFavoriteSizes);
  44 + return breakSizeProductScorer;
  45 + }catch (Exception e){
  46 + logger.error(e.getMessage());
  47 + return null;
  48 + }
  49 +
50 } 50 }
51 51
52 // 获取【问题商品】的打分器 52 // 获取【问题商品】的打分器
@@ -61,12 +61,17 @@ public class SearchScorerFactory { @@ -61,12 +61,17 @@ public class SearchScorerFactory {
61 61
62 // 获取【模糊搜索页针对频道】的打分器 62 // 获取【模糊搜索页针对频道】的打分器
63 public IScorer getChannelSearchScorer(Map<String, String> paramMap) { 63 public IScorer getChannelSearchScorer(Map<String, String> paramMap) {
64 - if (!searchCommonHelper.isNeedDeScoreForChannel(paramMap)) { 64 + try {
  65 + if (!searchCommonHelper.isNeedDeScoreForChannel(paramMap)) {
  66 + return null;
  67 + }
  68 + float physicalChannelWeight = (float) dynamicConfig.getDeScorePhysicalChannelWeight();
  69 + Map<String, Float> userGenderFloat = bigDataRedisService.getUserGenderFeature(paramMap.getOrDefault("uid", "0"));
  70 + return new UserChannelSearchScorer(paramMap, userGenderFloat, physicalChannelWeight);
  71 + }catch (Exception e){
  72 + logger.error(e.getMessage());
65 return null; 73 return null;
66 } 74 }
67 - float physicalChannelWeight = (float) dynamicConfig.getDeScorePhysicalChannelWeight();  
68 - Map<String, Float> userGenderFloat = bigDataRedisService.getUserGenderFeature(paramMap.getOrDefault("uid", "0"));  
69 - return new UserChannelSearchScorer(paramMap, userGenderFloat, physicalChannelWeight);  
70 } 75 }
71 76
72 // 获取【firstProductSkn】的打分器 77 // 获取【firstProductSkn】的打分器
@@ -101,9 +106,4 @@ public class SearchScorerFactory { @@ -101,9 +106,4 @@ public class SearchScorerFactory {
101 return new FeatureFactorScorer(scoreFilter, featureFactors, featureVersion); 106 return new FeatureFactorScorer(scoreFilter, featureFactors, featureVersion);
102 } 107 }
103 108
104 - // 获取【随机函数】的打分器  
105 - public IScorer getRandomScorer(String seed) {  
106 - return new RandomScorer(seed);  
107 - }  
108 -  
109 } 109 }
1 package com.yoho.search.service.scorer.personal; 1 package com.yoho.search.service.scorer.personal;
2 2
3 -import java.util.Calendar;  
4 -import java.util.HashMap;  
5 -import java.util.Map;  
6 -  
7 -import org.apache.commons.lang3.StringUtils;  
8 -import org.springframework.beans.factory.annotation.Autowired;  
9 -import org.springframework.stereotype.Service;  
10 -  
11 import com.yoho.search.base.utils.DateUtil; 3 import com.yoho.search.base.utils.DateUtil;
12 import com.yoho.search.common.cache.CacheType; 4 import com.yoho.search.common.cache.CacheType;
13 import com.yoho.search.common.cache.aop.SearchCacheAble; 5 import com.yoho.search.common.cache.aop.SearchCacheAble;
14 import com.yoho.search.core.personalized.BigDataRedisService; 6 import com.yoho.search.core.personalized.BigDataRedisService;
15 import com.yoho.search.core.personalized.PersonalizedSearch; 7 import com.yoho.search.core.personalized.PersonalizedSearch;
16 import com.yoho.search.service.base.SearchDynamicConfigService; 8 import com.yoho.search.service.base.SearchDynamicConfigService;
17 -import com.yoho.search.service.service.IProductCountService; 9 +import org.apache.commons.lang3.StringUtils;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.stereotype.Service;
  14 +
  15 +import java.util.Calendar;
  16 +import java.util.HashMap;
  17 +import java.util.Map;
18 18
19 @Service 19 @Service
20 public class PersonalVectorFeatureSearch { 20 public class PersonalVectorFeatureSearch {
21 21
  22 + private static final Logger logger = LoggerFactory.getLogger(PersonalVectorFeatureSearch.class);
  23 +
22 private static final Double BASE_CONSTANT = 1.0D; 24 private static final Double BASE_CONSTANT = 1.0D;
23 private static final Double FACTOR_CONSTANT = 0.8D; 25 private static final Double FACTOR_CONSTANT = 0.8D;
24 26
25 @Autowired 27 @Autowired
26 private SearchDynamicConfigService searchDynamicConfigService; 28 private SearchDynamicConfigService searchDynamicConfigService;
27 @Autowired 29 @Autowired
28 - private IProductCountService productCountService;  
29 - @Autowired  
30 private BigDataRedisService bigDataRedisService; 30 private BigDataRedisService bigDataRedisService;
31 31
32 @SearchCacheAble(cacheInMinute = 10, cacheName = "PERSIONAL_VECTOR", returnClass = PersonalizedSearch.class, cacheType = CacheType.SEARCH_REDIS, includeParams = { "uid" }) 32 @SearchCacheAble(cacheInMinute = 10, cacheName = "PERSIONAL_VECTOR", returnClass = PersonalizedSearch.class, cacheType = CacheType.SEARCH_REDIS, includeParams = { "uid" })
@@ -49,6 +49,7 @@ public class PersonalVectorFeatureSearch { @@ -49,6 +49,7 @@ public class PersonalVectorFeatureSearch {
49 } 49 }
50 return new PersonalizedSearch(uid, vectorFeatureVersion, userVectorFeature); 50 return new PersonalizedSearch(uid, vectorFeatureVersion, userVectorFeature);
51 } catch (Exception e) { 51 } catch (Exception e) {
  52 + logger.error(e.getMessage(),e);
52 return null; 53 return null;
53 } 54 }
54 } 55 }