Authored by hugufei

用户性别偏好添加缓存

1 package com.yoho.search.service.scorer; 1 package com.yoho.search.service.scorer;
2 2
  3 +import com.alibaba.fastjson.JSONObject;
3 import com.yoho.search.core.personalized.BigDataRedisService; 4 import com.yoho.search.core.personalized.BigDataRedisService;
4 import com.yoho.search.models.FirstShelveTimeScore; 5 import com.yoho.search.models.FirstShelveTimeScore;
5 import com.yoho.search.service.base.SearchDynamicConfigService; 6 import com.yoho.search.service.base.SearchDynamicConfigService;
6 import com.yoho.search.service.base.SearchRequestParams; 7 import com.yoho.search.service.base.SearchRequestParams;
7 import com.yoho.search.service.helper.SearchCommonHelper; 8 import com.yoho.search.service.helper.SearchCommonHelper;
8 import com.yoho.search.service.scorer.impl.*; 9 import com.yoho.search.service.scorer.impl.*;
  10 +import com.yoho.search.service.scorer.personal.PersonalGenderFeatureSearch;
9 import org.elasticsearch.index.query.QueryBuilder; 11 import org.elasticsearch.index.query.QueryBuilder;
10 import org.slf4j.Logger; 12 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory; 13 import org.slf4j.LoggerFactory;
@@ -22,7 +24,7 @@ public class SearchScorerFactory { @@ -22,7 +24,7 @@ public class SearchScorerFactory {
22 private static final Logger logger = LoggerFactory.getLogger(SearchScorerFactory.class); 24 private static final Logger logger = LoggerFactory.getLogger(SearchScorerFactory.class);
23 25
24 @Autowired 26 @Autowired
25 - private BigDataRedisService bigDataRedisService; 27 + private PersonalGenderFeatureSearch personalGenderFeatureSearch;
26 @Autowired 28 @Autowired
27 private SearchCommonHelper searchCommonHelper; 29 private SearchCommonHelper searchCommonHelper;
28 @Autowired 30 @Autowired
@@ -36,18 +38,17 @@ public class SearchScorerFactory { @@ -36,18 +38,17 @@ public class SearchScorerFactory {
36 return new GlobalProductScorer(); 38 return new GlobalProductScorer();
37 } 39 }
38 40
39 - // 获取【断码商品】的打分器  
40 - public IScorer getBreakSizeProductScorer(Map<String, String> paramMap) {  
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 - } 41 +// // 获取【断码商品】的打分器
  42 +// public IScorer getBreakSizeProductScorer(Map<String, String> paramMap) {
  43 +// try {
  44 +// List<String> userFavoriteSizes = bigDataRedisService.getUserFavoriteSizes(paramMap.getOrDefault("uid", "0"));
  45 +// IScorer breakSizeProductScorer = new BreakSizeProductScorer(userFavoriteSizes);
  46 +// return breakSizeProductScorer;
  47 +// }catch (Exception e){
  48 +// logger.error(e.getMessage());
  49 +// return null;
  50 +// }
  51 +// }
51 52
52 // 获取【问题商品】的打分器 53 // 获取【问题商品】的打分器
53 public IScorer getProblemProductScorer() { 54 public IScorer getProblemProductScorer() {
@@ -66,7 +67,7 @@ public class SearchScorerFactory { @@ -66,7 +67,7 @@ public class SearchScorerFactory {
66 return null; 67 return null;
67 } 68 }
68 float physicalChannelWeight = (float) dynamicConfig.getDeScorePhysicalChannelWeight(); 69 float physicalChannelWeight = (float) dynamicConfig.getDeScorePhysicalChannelWeight();
69 - Map<String, Float> userGenderFloat = bigDataRedisService.getUserGenderFeature(paramMap.getOrDefault("uid", "0")); 70 + JSONObject userGenderFloat = personalGenderFeatureSearch.queryUserGenderFeature(paramMap);
70 return new UserChannelSearchScorer(paramMap, userGenderFloat, physicalChannelWeight); 71 return new UserChannelSearchScorer(paramMap, userGenderFloat, physicalChannelWeight);
71 }catch (Exception e){ 72 }catch (Exception e){
72 logger.error(e.getMessage()); 73 logger.error(e.getMessage());
@@ -115,7 +116,7 @@ public class SearchScorerFactory { @@ -115,7 +116,7 @@ public class SearchScorerFactory {
115 return new CsBrandKeyWordScorer(query); 116 return new CsBrandKeyWordScorer(query);
116 } 117 }
117 118
118 - // 获取CsBrandKeyWord的打分器 119 + // 获取特殊店铺的打分器
119 public IScorer getSpecialShopScorer(List<Integer> shopIds,float weight) { 120 public IScorer getSpecialShopScorer(List<Integer> shopIds,float weight) {
120 return new SpecialShopScorer(shopIds,weight); 121 return new SpecialShopScorer(shopIds,weight);
121 } 122 }
@@ -4,6 +4,7 @@ import java.util.ArrayList; @@ -4,6 +4,7 @@ import java.util.ArrayList;
4 import java.util.List; 4 import java.util.List;
5 import java.util.Map; 5 import java.util.Map;
6 6
  7 +import com.alibaba.fastjson.JSONObject;
7 import org.apache.commons.lang.StringUtils; 8 import org.apache.commons.lang.StringUtils;
8 import org.elasticsearch.index.query.BoolQueryBuilder; 9 import org.elasticsearch.index.query.BoolQueryBuilder;
9 import org.elasticsearch.index.query.QueryBuilders; 10 import org.elasticsearch.index.query.QueryBuilders;
@@ -18,10 +19,10 @@ import com.yoho.search.service.scorer.IScorer; @@ -18,10 +19,10 @@ import com.yoho.search.service.scorer.IScorer;
18 public class UserChannelSearchScorer implements IScorer { 19 public class UserChannelSearchScorer implements IScorer {
19 20
20 private Map<String, String> paramMap;// 用户查询的关键词 21 private Map<String, String> paramMap;// 用户查询的关键词
21 - private Map<String, Float> userGenderFloat;// 用户性别偏好 22 + private JSONObject userGenderFloat;// 用户性别偏好
22 private float physicalChannelWeight;// 配置的默认权重 23 private float physicalChannelWeight;// 配置的默认权重
23 24
24 - public UserChannelSearchScorer(Map<String, String> paramMap, Map<String, Float> userGenderFloat, float physicalChannelWeight) { 25 + public UserChannelSearchScorer(Map<String, String> paramMap, JSONObject userGenderFloat, float physicalChannelWeight) {
25 super(); 26 super();
26 this.paramMap = paramMap; 27 this.paramMap = paramMap;
27 this.userGenderFloat = userGenderFloat; 28 this.userGenderFloat = userGenderFloat;
@@ -94,7 +95,7 @@ public class UserChannelSearchScorer implements IScorer { @@ -94,7 +95,7 @@ public class UserChannelSearchScorer implements IScorer {
94 */ 95 */
95 private float getDescoreGenderWeight(float baseScore, String descoreGender) { 96 private float getDescoreGenderWeight(float baseScore, String descoreGender) {
96 try { 97 try {
97 - Float userGenderWeight = userGenderFloat.get(descoreGender); 98 + Float userGenderWeight = userGenderFloat.getFloat(descoreGender);
98 if (userGenderWeight == null) { 99 if (userGenderWeight == null) {
99 return baseScore; 100 return baseScore;
100 } 101 }
  1 +package com.yoho.search.service.scorer.personal;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.yoho.search.common.cache.CacheType;
  5 +import com.yoho.search.common.cache.aop.SearchCacheAble;
  6 +import com.yoho.search.core.personalized.BigDataRedisService;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Service;
  11 +
  12 +import java.util.Map;
  13 +
  14 +@Service
  15 +public class PersonalGenderFeatureSearch {
  16 +
  17 + private static final Logger logger = LoggerFactory.getLogger(PersonalGenderFeatureSearch.class);
  18 +
  19 + @Autowired
  20 + private BigDataRedisService bigDataRedisService;
  21 +
  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) {
  24 + try {
  25 + Map<String, Float> userGenderFloat = bigDataRedisService.getUserGenderFeature(paramMap.getOrDefault("uid", "0"));
  26 + JSONObject jsonObject = new JSONObject();
  27 + jsonObject.putAll(userGenderFloat);
  28 + return jsonObject;
  29 + } catch (Exception e) {
  30 + logger.error(e.getMessage(), e);
  31 + return new JSONObject();
  32 + }
  33 + }
  34 +}