Authored by hugufei

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

package com.yoho.search.service.scorer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.elasticsearch.index.query.QueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.yoho.search.core.personalized.BigDataRedisService;
import com.yoho.search.models.FirstShelveTimeScore;
import com.yoho.search.service.base.SearchDynamicConfigService;
import com.yoho.search.service.base.SearchRequestParams;
import com.yoho.search.service.helper.SearchCommonHelper;
import com.yoho.search.service.scorer.impl.AddScoreSknScorer;
import com.yoho.search.service.scorer.impl.BreakSizeProductScorer;
import com.yoho.search.service.scorer.impl.FeatureFactorScorer;
import com.yoho.search.service.scorer.impl.FirstProductSknScorer;
import com.yoho.search.service.scorer.impl.FirstShelveTimeScorer;
import com.yoho.search.service.scorer.impl.GlobalProductScorer;
import com.yoho.search.service.scorer.impl.NewArriveHeatDescScorer;
import com.yoho.search.service.scorer.impl.ProblemProductScorer;
import com.yoho.search.service.scorer.impl.RandomScorer;
import com.yoho.search.service.scorer.impl.UserChannelSearchScorer;
import com.yoho.search.service.scorer.impl.*;
import org.elasticsearch.index.query.QueryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Component
public class SearchScorerFactory {
private static final Logger logger = LoggerFactory.getLogger(SearchScorerFactory.class);
@Autowired
private BigDataRedisService bigDataRedisService;
@Autowired
... ... @@ -44,9 +38,15 @@ public class SearchScorerFactory {
// 获取【断码商品】的打分器
public IScorer getBreakSizeProductScorer(Map<String, String> paramMap) {
List<String> userFavoriteSizes = bigDataRedisService.getUserFavoriteSizes(paramMap.getOrDefault("uid", "0"));
IScorer breakSizeProductScorer = new BreakSizeProductScorer(userFavoriteSizes);
return breakSizeProductScorer;
try {
List<String> userFavoriteSizes = bigDataRedisService.getUserFavoriteSizes(paramMap.getOrDefault("uid", "0"));
IScorer breakSizeProductScorer = new BreakSizeProductScorer(userFavoriteSizes);
return breakSizeProductScorer;
}catch (Exception e){
logger.error(e.getMessage());
return null;
}
}
// 获取【问题商品】的打分器
... ... @@ -61,12 +61,17 @@ public class SearchScorerFactory {
// 获取【模糊搜索页针对频道】的打分器
public IScorer getChannelSearchScorer(Map<String, String> paramMap) {
if (!searchCommonHelper.isNeedDeScoreForChannel(paramMap)) {
try {
if (!searchCommonHelper.isNeedDeScoreForChannel(paramMap)) {
return null;
}
float physicalChannelWeight = (float) dynamicConfig.getDeScorePhysicalChannelWeight();
Map<String, Float> userGenderFloat = bigDataRedisService.getUserGenderFeature(paramMap.getOrDefault("uid", "0"));
return new UserChannelSearchScorer(paramMap, userGenderFloat, physicalChannelWeight);
}catch (Exception e){
logger.error(e.getMessage());
return null;
}
float physicalChannelWeight = (float) dynamicConfig.getDeScorePhysicalChannelWeight();
Map<String, Float> userGenderFloat = bigDataRedisService.getUserGenderFeature(paramMap.getOrDefault("uid", "0"));
return new UserChannelSearchScorer(paramMap, userGenderFloat, physicalChannelWeight);
}
// 获取【firstProductSkn】的打分器
... ... @@ -101,9 +106,4 @@ public class SearchScorerFactory {
return new FeatureFactorScorer(scoreFilter, featureFactors, featureVersion);
}
// 获取【随机函数】的打分器
public IScorer getRandomScorer(String seed) {
return new RandomScorer(seed);
}
}
... ...
package com.yoho.search.service.scorer.personal;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.common.cache.CacheType;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.core.personalized.BigDataRedisService;
import com.yoho.search.core.personalized.PersonalizedSearch;
import com.yoho.search.service.base.SearchDynamicConfigService;
import com.yoho.search.service.service.IProductCountService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
@Service
public class PersonalVectorFeatureSearch {
private static final Logger logger = LoggerFactory.getLogger(PersonalVectorFeatureSearch.class);
private static final Double BASE_CONSTANT = 1.0D;
private static final Double FACTOR_CONSTANT = 0.8D;
@Autowired
private SearchDynamicConfigService searchDynamicConfigService;
@Autowired
private IProductCountService productCountService;
@Autowired
private BigDataRedisService bigDataRedisService;
@SearchCacheAble(cacheInMinute = 10, cacheName = "PERSIONAL_VECTOR", returnClass = PersonalizedSearch.class, cacheType = CacheType.SEARCH_REDIS, includeParams = { "uid" })
... ... @@ -49,6 +49,7 @@ public class PersonalVectorFeatureSearch {
}
return new PersonalizedSearch(uid, vectorFeatureVersion, userVectorFeature);
} catch (Exception e) {
logger.error(e.getMessage(),e);
return null;
}
}
... ...