Authored by hugufei

Merge branch 'recall_config' into 0510

package com.yoho.search.service.scorer;
import com.alibaba.fastjson.JSONObject;
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.*;
import com.yoho.search.service.scorer.personal.PersonalGenderFeatureSearch;
import org.elasticsearch.index.query.QueryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -22,7 +24,7 @@ public class SearchScorerFactory {
private static final Logger logger = LoggerFactory.getLogger(SearchScorerFactory.class);
@Autowired
private BigDataRedisService bigDataRedisService;
private PersonalGenderFeatureSearch personalGenderFeatureSearch;
@Autowired
private SearchCommonHelper searchCommonHelper;
@Autowired
... ... @@ -36,18 +38,17 @@ public class SearchScorerFactory {
return new GlobalProductScorer();
}
// 获取【断码商品】的打分器
public IScorer getBreakSizeProductScorer(Map<String, String> paramMap) {
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;
}
}
// // 获取【断码商品】的打分器
// public IScorer getBreakSizeProductScorer(Map<String, String> paramMap) {
// 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;
// }
// }
// 获取【问题商品】的打分器
public IScorer getProblemProductScorer() {
... ... @@ -66,7 +67,7 @@ public class SearchScorerFactory {
return null;
}
float physicalChannelWeight = (float) dynamicConfig.getDeScorePhysicalChannelWeight();
Map<String, Float> userGenderFloat = bigDataRedisService.getUserGenderFeature(paramMap.getOrDefault("uid", "0"));
JSONObject userGenderFloat = personalGenderFeatureSearch.queryUserGenderFeature(paramMap);
return new UserChannelSearchScorer(paramMap, userGenderFloat, physicalChannelWeight);
}catch (Exception e){
logger.error(e.getMessage());
... ... @@ -115,7 +116,7 @@ public class SearchScorerFactory {
return new CsBrandKeyWordScorer(query);
}
// 获取CsBrandKeyWord的打分器
// 获取特殊店铺的打分器
public IScorer getSpecialShopScorer(List<Integer> shopIds,float weight) {
return new SpecialShopScorer(shopIds,weight);
}
... ...
... ... @@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
... ... @@ -18,10 +19,10 @@ import com.yoho.search.service.scorer.IScorer;
public class UserChannelSearchScorer implements IScorer {
private Map<String, String> paramMap;// 用户查询的关键词
private Map<String, Float> userGenderFloat;// 用户性别偏好
private JSONObject userGenderFloat;// 用户性别偏好
private float physicalChannelWeight;// 配置的默认权重
public UserChannelSearchScorer(Map<String, String> paramMap, Map<String, Float> userGenderFloat, float physicalChannelWeight) {
public UserChannelSearchScorer(Map<String, String> paramMap, JSONObject userGenderFloat, float physicalChannelWeight) {
super();
this.paramMap = paramMap;
this.userGenderFloat = userGenderFloat;
... ... @@ -94,7 +95,7 @@ public class UserChannelSearchScorer implements IScorer {
*/
private float getDescoreGenderWeight(float baseScore, String descoreGender) {
try {
Float userGenderWeight = userGenderFloat.get(descoreGender);
Float userGenderWeight = userGenderFloat.getFloat(descoreGender);
if (userGenderWeight == null) {
return baseScore;
}
... ...
package com.yoho.search.service.scorer.personal;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.common.cache.CacheType;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.core.personalized.BigDataRedisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
@Service
public class PersonalGenderFeatureSearch {
private static final Logger logger = LoggerFactory.getLogger(PersonalGenderFeatureSearch.class);
@Autowired
private BigDataRedisService bigDataRedisService;
@SearchCacheAble(cacheInMinute = 30, cacheName = "USER_GENDER_FEATURE", returnClass = JSONObject.class, cacheType = CacheType.SEARCH_REDIS, includeParams = {"uid"})
public JSONObject queryUserGenderFeature(Map<String, String> paramMap) {
try {
JSONObject jsonObject = new JSONObject();
Map<String, Float> userGenderFloat = bigDataRedisService.getUserGenderFeature(paramMap.getOrDefault("uid", "0"));
if(userGenderFloat!=null){
jsonObject.putAll(userGenderFloat);
}
return jsonObject;
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new JSONObject();
}
}
}
... ...
... ... @@ -30,7 +30,7 @@ public class PersonalVectorFeatureSearch {
@Autowired
private BigDataRedisService bigDataRedisService;
@SearchCacheAble(cacheInMinute = 10, cacheName = "PERSIONAL_VECTOR", returnClass = PersonalizedSearch.class, cacheType = CacheType.SEARCH_REDIS, includeParams = { "uid" })
@SearchCacheAble(cacheInMinute = 30, cacheName = "PERSIONAL_VECTOR", returnClass = PersonalizedSearch.class, cacheType = CacheType.SEARCH_REDIS, includeParams = { "uid" })
public PersonalizedSearch getPersonalizedSearch(Map<String, String> paramMap) {
try {
// 1、参数校验
... ...