Merge branch 'master' into wn_customize_tag
Showing
30 changed files
with
724 additions
and
365 deletions
@@ -158,4 +158,11 @@ public class SearchDynamicConfigService { | @@ -158,4 +158,11 @@ public class SearchDynamicConfigService { | ||
158 | return configReader.getBoolean("search.tbl.use.new.index", true); | 158 | return configReader.getBoolean("search.tbl.use.new.index", true); |
159 | } | 159 | } |
160 | 160 | ||
161 | + /** | ||
162 | + * group_shop新实现 | ||
163 | + */ | ||
164 | + public boolean groupShopNew() { | ||
165 | + return configReader.getBoolean("search.shop.group.new", true); | ||
166 | + } | ||
167 | + | ||
161 | } | 168 | } |
1 | +package com.yoho.search.common.utils; | ||
2 | + | ||
3 | +import com.google.common.collect.Lists; | ||
4 | +import org.apache.commons.lang3.StringUtils; | ||
5 | +import org.slf4j.Logger; | ||
6 | +import org.slf4j.LoggerFactory; | ||
7 | + | ||
8 | +import java.util.ArrayList; | ||
9 | +import java.util.List; | ||
10 | + | ||
11 | +public class ImageUrlAssist { | ||
12 | + private static final String INIT_POSITION = "center"; | ||
13 | + | ||
14 | + | ||
15 | + private static final String INIT_BACKGROUND = "d2hpdGU="; | ||
16 | + | ||
17 | + | ||
18 | + private static final String INIT_SIZE = "source"; | ||
19 | + | ||
20 | + | ||
21 | + private static final Logger logger = LoggerFactory.getLogger(ImageUrlAssist.class); | ||
22 | + | ||
23 | + | ||
24 | + /** | ||
25 | + * 图片尺寸字符串的分隔符 | ||
26 | + */ | ||
27 | + private static final String SEPRATOR_SIZE = "x"; | ||
28 | + | ||
29 | + /** | ||
30 | + * 获取图片的完整路径 包含参数 | ||
31 | + * @param imageUrl 相对路径 | ||
32 | + * @param bucket | ||
33 | + * @param position | ||
34 | + * @param background | ||
35 | + * @return 图片的完整路径 | ||
36 | + */ | ||
37 | + public static String getAllProductPicUrl(Object imageUrl, String bucket, String position, String background) { | ||
38 | + if (!(imageUrl instanceof String) || StringUtils.isEmpty((String)imageUrl)) { | ||
39 | + return ""; | ||
40 | + } | ||
41 | + if (StringUtils.isEmpty(background)) { | ||
42 | + background = INIT_BACKGROUND; | ||
43 | + } | ||
44 | + if (StringUtils.isEmpty(position)) { | ||
45 | + position = INIT_POSITION; | ||
46 | + } | ||
47 | + return getUrl((String)imageUrl, bucket, null, null) + "?imageMogr2/thumbnail/{width}x{height}/background/" | ||
48 | + + background + "/position/" + position + "/quality/80"; | ||
49 | + } | ||
50 | + | ||
51 | + /** | ||
52 | + * 获取图片的路径,不含参数 | ||
53 | + * @param imageUrl | ||
54 | + * @param bucket | ||
55 | + * @return | ||
56 | + */ | ||
57 | + public static String getUrl(String imageUrl, String bucket, String source, Integer mode) { | ||
58 | + if (StringUtils.isEmpty(imageUrl)) { | ||
59 | + return ""; | ||
60 | + } | ||
61 | + source = StringUtils.isEmpty(source) ? INIT_SIZE : source; | ||
62 | + mode = null == mode ? 1 : mode; | ||
63 | + Integer width = null; | ||
64 | + Integer height = null; | ||
65 | + if (StringUtils.isEmpty(source) && !INIT_SIZE.equals(source)) { | ||
66 | + String[] split = source.split(SEPRATOR_SIZE); | ||
67 | + if (split.length == 2) { | ||
68 | + try { | ||
69 | + width = Integer.valueOf(split[0]); | ||
70 | + height = Integer.valueOf(split[1]); | ||
71 | + } catch (NumberFormatException e) { | ||
72 | + logger.warn("The source of goodsPic is not number. imageUrl is " + imageUrl + "; source : " + source, e); | ||
73 | + } | ||
74 | + } | ||
75 | + } | ||
76 | + String domain = getDomain(imageUrl); | ||
77 | + if (StringUtils.isEmpty(domain)) { | ||
78 | + return ""; | ||
79 | + } | ||
80 | + return getImgPrivateUrl(bucket + imageUrl, width, height, mode, domain); | ||
81 | + } | ||
82 | + | ||
83 | + /** | ||
84 | + * 获取私有的图片地址 | ||
85 | + * @param fileName | ||
86 | + * @param width | ||
87 | + * @param height | ||
88 | + * @param mode | ||
89 | + * @param domain | ||
90 | + * @return | ||
91 | + */ | ||
92 | + private static String getImgPrivateUrl(String fileName, Integer width, Integer height, Integer mode, String domain) { | ||
93 | + if (null == mode) { | ||
94 | + mode = 1; | ||
95 | + } | ||
96 | + | ||
97 | + if (StringUtils.isEmpty(domain)) { | ||
98 | + domain = "yhfair.qiniudn.com"; | ||
99 | + } | ||
100 | + | ||
101 | + return makeRequest("http://" + domain + "/" + fileName.replaceAll("%2F", "/"), mode, width, height, domain, null, null); | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
105 | + * 拼接图片的URL参数 | ||
106 | + * @param baseUrl | ||
107 | + * @param mode | ||
108 | + * @param width | ||
109 | + * @param height | ||
110 | + * @param domain | ||
111 | + * @param quality | ||
112 | + * @param format | ||
113 | + * @return | ||
114 | + */ | ||
115 | + private static String makeRequest(String baseUrl, Integer mode, Integer width, Integer height, String domain, | ||
116 | + String quality, String format) { | ||
117 | + StringBuilder sb = new StringBuilder(); | ||
118 | + if (null != mode) { | ||
119 | + sb.append(mode); | ||
120 | + } | ||
121 | + if (null != width) { | ||
122 | + sb.append("/w/").append(width); | ||
123 | + } | ||
124 | + if (null != height) { | ||
125 | + sb.append("/h/").append(height); | ||
126 | + } | ||
127 | + if (null != quality) { | ||
128 | + sb.append("/q/").append(quality); | ||
129 | + } | ||
130 | + if (null != format) { | ||
131 | + sb.append("/format/").append(format); | ||
132 | + } | ||
133 | + if (0 == sb.length()) { | ||
134 | + return baseUrl; | ||
135 | + } | ||
136 | + if (null == width || null == height) { | ||
137 | + return baseUrl; | ||
138 | + } | ||
139 | + return baseUrl + "?imageView/" + sb.toString(); | ||
140 | + } | ||
141 | + | ||
142 | + | ||
143 | + private static String getDomain(String imageUrl) { | ||
144 | + if (imageUrl.length() < 17) { | ||
145 | + return ""; | ||
146 | + } | ||
147 | + String node = imageUrl.substring(15, 17); | ||
148 | + List<String> domainList = getDomainList(node); | ||
149 | + if (domainList.isEmpty()) { | ||
150 | + return ""; | ||
151 | + } | ||
152 | + return domainList.get(Math.random() > 0.5 ? 1 : 0); | ||
153 | + } | ||
154 | + | ||
155 | + /** | ||
156 | + * 图片的节点服务器列表 | ||
157 | + * @param node | ||
158 | + * @return | ||
159 | + */ | ||
160 | + private static List<String> getDomainList(String node) { | ||
161 | + if ("01".equals(node)) { | ||
162 | + return Lists.newArrayList("img10.static.yhbimg.com", "img11.static.yhbimg.com"); | ||
163 | + }else if("02".equals(node)) { | ||
164 | + return Lists.newArrayList("img12.static.yhbimg.com", "img13.static.yhbimg.com"); | ||
165 | + } | ||
166 | + return new ArrayList<String>(0); | ||
167 | + } | ||
168 | +} |
@@ -5,6 +5,7 @@ import java.util.Map; | @@ -5,6 +5,7 @@ import java.util.Map; | ||
5 | import javax.servlet.http.HttpServletRequest; | 5 | import javax.servlet.http.HttpServletRequest; |
6 | 6 | ||
7 | import com.yoho.search.aop.downgrade.PersionalRateLimit; | 7 | import com.yoho.search.aop.downgrade.PersionalRateLimit; |
8 | +import com.yoho.search.common.SearchDynamicConfigService; | ||
8 | import com.yoho.search.service.scene.shopbrand.RecommendShopService; | 9 | import com.yoho.search.service.scene.shopbrand.RecommendShopService; |
9 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
10 | import org.springframework.stereotype.Controller; | 11 | import org.springframework.stereotype.Controller; |
@@ -32,7 +33,8 @@ public class ShopsController { | @@ -32,7 +33,8 @@ public class ShopsController { | ||
32 | private BrandWithShopsService brandWithShopsService; | 33 | private BrandWithShopsService brandWithShopsService; |
33 | @Autowired | 34 | @Autowired |
34 | private RecommendShopService recommendShopService; | 35 | private RecommendShopService recommendShopService; |
35 | - | 36 | + @Autowired |
37 | + private SearchDynamicConfigService searchDynamicConfigService; | ||
36 | /** | 38 | /** |
37 | * 按关键字搜出一个符合条件的品牌[待删除] | 39 | * 按关键字搜出一个符合条件的品牌[待删除] |
38 | * | 40 | * |
@@ -97,6 +99,9 @@ public class ShopsController { | @@ -97,6 +99,9 @@ public class ShopsController { | ||
97 | @ResponseBody | 99 | @ResponseBody |
98 | public SearchApiResult group_shops(HttpServletRequest request) { | 100 | public SearchApiResult group_shops(HttpServletRequest request) { |
99 | Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); | 101 | Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); |
102 | + if (searchDynamicConfigService.groupShopNew()) { | ||
103 | + return shopsService.groupShopsV2(paramMap); | ||
104 | + } | ||
100 | return shopsService.group_shops(paramMap); | 105 | return shopsService.group_shops(paramMap); |
101 | } | 106 | } |
102 | 107 |
1 | package com.yoho.search.service.aggregations; | 1 | package com.yoho.search.service.aggregations; |
2 | 2 | ||
3 | -import com.alibaba.fastjson.JSON; | ||
4 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
5 | -import com.alibaba.fastjson.TypeReference; | ||
6 | import com.yoho.error.event.SearchEvent; | 4 | import com.yoho.error.event.SearchEvent; |
7 | import com.yoho.search.base.utils.EventReportEnum; | 5 | import com.yoho.search.base.utils.EventReportEnum; |
8 | import com.yoho.search.base.utils.ISearchConstants; | 6 | import com.yoho.search.base.utils.ISearchConstants; |
@@ -12,17 +10,10 @@ import com.yoho.search.core.es.model.SearchParam; | @@ -12,17 +10,10 @@ import com.yoho.search.core.es.model.SearchParam; | ||
12 | import com.yoho.search.core.es.model.SearchResult; | 10 | import com.yoho.search.core.es.model.SearchResult; |
13 | import com.yoho.search.core.es.utils.IgnoreSomeException; | 11 | import com.yoho.search.core.es.utils.IgnoreSomeException; |
14 | import com.yoho.search.service.aggregations.impls.AggregationFactory; | 12 | import com.yoho.search.service.aggregations.impls.AggregationFactory; |
15 | -import com.yoho.search.service.scene.others.hongren.ShopProductCacheBean; | ||
16 | -import com.yoho.search.service.recall.models.common.ParamQueryFilter; | ||
17 | -import com.yoho.search.service.scene.others.hongren.ShopProductRequest; | ||
18 | -import com.yoho.search.service.scene.others.hongren.ShopProductResponse; | ||
19 | import com.yoho.search.common.SearchCommonService; | 13 | import com.yoho.search.common.SearchCommonService; |
20 | import com.yoho.search.common.SearchRequestParams; | 14 | import com.yoho.search.common.SearchRequestParams; |
21 | -import com.yoho.search.service.helper.SearchCommonHelper; | ||
22 | import com.yoho.search.service.helper.SearchParamHelper; | 15 | import com.yoho.search.service.helper.SearchParamHelper; |
23 | import com.yoho.search.cache.beans.AbstractCacheAbleService; | 16 | import com.yoho.search.cache.beans.AbstractCacheAbleService; |
24 | -import org.apache.commons.collections.CollectionUtils; | ||
25 | -import org.elasticsearch.index.query.BoolQueryBuilder; | ||
26 | import org.elasticsearch.search.aggregations.Aggregation; | 17 | import org.elasticsearch.search.aggregations.Aggregation; |
27 | import org.slf4j.Logger; | 18 | import org.slf4j.Logger; |
28 | import org.slf4j.LoggerFactory; | 19 | import org.slf4j.LoggerFactory; |
@@ -32,7 +23,6 @@ import org.springframework.context.ApplicationEventPublisherAware; | @@ -32,7 +23,6 @@ import org.springframework.context.ApplicationEventPublisherAware; | ||
32 | import org.springframework.stereotype.Service; | 23 | import org.springframework.stereotype.Service; |
33 | 24 | ||
34 | import java.util.*; | 25 | import java.util.*; |
35 | -import java.util.stream.Collectors; | ||
36 | 26 | ||
37 | @Service | 27 | @Service |
38 | public class AggregationsService extends AbstractCacheAbleService implements ApplicationEventPublisherAware { | 28 | public class AggregationsService extends AbstractCacheAbleService implements ApplicationEventPublisherAware { |
@@ -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; |
1 | +package com.yoho.search.service.helper; | ||
2 | + | ||
3 | +import com.yoho.search.base.utils.ProductIndexEsField; | ||
4 | +import org.apache.commons.collections.CollectionUtils; | ||
5 | +import org.apache.commons.collections.MapUtils; | ||
6 | +import org.apache.commons.lang.StringUtils; | ||
7 | +import org.slf4j.Logger; | ||
8 | +import org.slf4j.LoggerFactory; | ||
9 | +import org.springframework.stereotype.Component; | ||
10 | + | ||
11 | +import java.util.ArrayList; | ||
12 | +import java.util.HashMap; | ||
13 | +import java.util.List; | ||
14 | +import java.util.Map; | ||
15 | + | ||
16 | +/** | ||
17 | + * @author wangnan | ||
18 | + * @version 2018/5/31 | ||
19 | + */ | ||
20 | +@Component | ||
21 | +public class GoodsCoverHelper { | ||
22 | + | ||
23 | + private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
24 | + | ||
25 | + public void buildGoodsCover(Map<String, Object> map, Map<String, Object> productMap) { | ||
26 | + try { | ||
27 | + String isGlobal = MapUtils.getString(map, ProductIndexEsField.isGlobal, "N"); | ||
28 | + if ("Y".equals(isGlobal)) { | ||
29 | + productMap.put("cover_1", ""); | ||
30 | + productMap.put("cover_2", ""); | ||
31 | + return; | ||
32 | + } | ||
33 | + List<HashMap<String, Object>> goodsList = (List<HashMap<String, Object>>) MapUtils.getObject(map, ProductIndexEsField.goodsList, new ArrayList<>()); | ||
34 | + if (CollectionUtils.isEmpty(goodsList)) { | ||
35 | + return; | ||
36 | + } | ||
37 | + String imagesUrl = ""; | ||
38 | + String cover1 = ""; | ||
39 | + String cover2 = ""; | ||
40 | + for (HashMap<String, Object> goodsMap : goodsList) { | ||
41 | + // 如果此goods是is_default=Y的,用这个goods | ||
42 | + if ("Y".equals(MapUtils.getString(goodsMap, "is_default"))) { | ||
43 | + imagesUrl = MapUtils.getString(goodsMap, "images_url"); | ||
44 | + cover1 = MapUtils.getString(goodsMap, "cover_1"); | ||
45 | + cover2 = MapUtils.getString(goodsMap, "cover_2"); | ||
46 | + if (StringUtils.isNotBlank(imagesUrl)) { | ||
47 | + break; | ||
48 | + } | ||
49 | + } | ||
50 | + } | ||
51 | + cover1 = StringUtils.isNotBlank(cover1) ? cover1 : imagesUrl; | ||
52 | + cover2 = StringUtils.isNotBlank(cover2) ? cover2 : imagesUrl; | ||
53 | + productMap.put("cover_1", cover1); | ||
54 | + productMap.put("cover_2", cover2); | ||
55 | + | ||
56 | + //default_images灾备 | ||
57 | + if (StringUtils.isBlank(MapUtils.getString(productMap, "default_images"))) { | ||
58 | + String default_images = this.getImageNotNull(goodsList); | ||
59 | + productMap.put("default_images", default_images); | ||
60 | + } | ||
61 | + } catch (Exception e) { | ||
62 | + logger.error(e.getMessage(), e); | ||
63 | + productMap.put("cover_1", ""); | ||
64 | + productMap.put("cover_2", ""); | ||
65 | + } | ||
66 | + } | ||
67 | + | ||
68 | + private String getImageNotNull(List<HashMap<String, Object>> goodsList) { | ||
69 | + for (HashMap<String, Object> goodsMap : goodsList) { | ||
70 | + String imagesUrl = MapUtils.getString(goodsMap, "images_url"); | ||
71 | + if (StringUtils.isNotBlank(imagesUrl)) { | ||
72 | + return imagesUrl; | ||
73 | + } | ||
74 | + String cover1 = MapUtils.getString(goodsMap, "cover_1"); | ||
75 | + if (StringUtils.isNotBlank(cover1)) { | ||
76 | + return cover1; | ||
77 | + } | ||
78 | + String cover2 = MapUtils.getString(goodsMap, "cover_2"); | ||
79 | + if (StringUtils.isNotBlank(cover2)) { | ||
80 | + return cover2; | ||
81 | + } | ||
82 | + } | ||
83 | + return null; | ||
84 | + } | ||
85 | + | ||
86 | +} |
@@ -64,15 +64,20 @@ public class BigDataSimilarSknImgAliIndexBaseService { | @@ -64,15 +64,20 @@ public class BigDataSimilarSknImgAliIndexBaseService { | ||
64 | } | 64 | } |
65 | 65 | ||
66 | public List<String> getSimilarProductSknListInShop(String productSkn) { | 66 | public List<String> getSimilarProductSknListInShop(String productSkn) { |
67 | - SimilarSkn similarSkn = this.querySimilarSkn(productSkn); | ||
68 | - List<String> similarProductSknList = new ArrayList<>(); | ||
69 | - if (similarSkn != null && StringUtils.isNotBlank(similarSkn.getSameShopImgSimilarSkns())) { | ||
70 | - String[] productSknArray = similarSkn.getSameShopImgSimilarSkns().split(","); | ||
71 | - if (productSknArray.length > 0) { | ||
72 | - similarProductSknList = Arrays.asList(productSknArray); | 67 | + try { |
68 | + SimilarSkn similarSkn = this.querySimilarSkn(productSkn); | ||
69 | + List<String> similarProductSknList = new ArrayList<>(); | ||
70 | + if (similarSkn != null && StringUtils.isNotBlank(similarSkn.getSameShopImgSimilarSkns())) { | ||
71 | + String[] productSknArray = similarSkn.getSameShopImgSimilarSkns().split(","); | ||
72 | + if (productSknArray.length > 0) { | ||
73 | + similarProductSknList = Arrays.asList(productSknArray); | ||
74 | + } | ||
73 | } | 75 | } |
76 | + return similarProductSknList; | ||
77 | + }catch (Exception e){ | ||
78 | + logger.error(e.getMessage(), e); | ||
79 | + return new ArrayList<>(); | ||
74 | } | 80 | } |
75 | - return similarProductSknList; | ||
76 | } | 81 | } |
77 | 82 | ||
78 | 83 |
@@ -63,15 +63,10 @@ public class CustomizeTagBaseService { | @@ -63,15 +63,10 @@ public class CustomizeTagBaseService { | ||
63 | } | 63 | } |
64 | //2、获取poolId和customizeTag的map,缓存5分钟 | 64 | //2、获取poolId和customizeTag的map,缓存5分钟 |
65 | Map<String, List<CustomizeTag>> customizeTagMap = this.getCustomizeTagMapFromCache(); | 65 | Map<String, List<CustomizeTag>> customizeTagMap = this.getCustomizeTagMapFromCache(); |
66 | - if (customizeTagMap.isEmpty()) { | ||
67 | - return; | ||
68 | - } | 66 | + |
69 | //3、遍历product列表,插入customizeTag | 67 | //3、遍历product列表,插入customizeTag |
70 | for (Map<String, Object> productMap : productList) { | 68 | for (Map<String, Object> productMap : productList) { |
71 | String poolIds = MapUtils.getString(productMap, PRODUCTINDEX_FIELD_POOLIDS, ""); | 69 | String poolIds = MapUtils.getString(productMap, PRODUCTINDEX_FIELD_POOLIDS, ""); |
72 | - if (StringUtils.isEmpty(poolIds)) { | ||
73 | - continue; | ||
74 | - } | ||
75 | List<JSONObject> customizeTags = this.buildCustomizeTag(poolIds, customizeTagMap); | 70 | List<JSONObject> customizeTags = this.buildCustomizeTag(poolIds, customizeTagMap); |
76 | productMap.put("customize_tag_new", customizeTags); | 71 | productMap.put("customize_tag_new", customizeTags); |
77 | } | 72 | } |
@@ -94,6 +89,9 @@ public class CustomizeTagBaseService { | @@ -94,6 +89,9 @@ public class CustomizeTagBaseService { | ||
94 | * 根据poolIds生成自定义标签节点 | 89 | * 根据poolIds生成自定义标签节点 |
95 | */ | 90 | */ |
96 | private List<JSONObject> buildCustomizeTag(String poolIds, Map<String, List<CustomizeTag>> customizeTagBOMap) throws Exception { | 91 | private List<JSONObject> buildCustomizeTag(String poolIds, Map<String, List<CustomizeTag>> customizeTagBOMap) throws Exception { |
92 | + if (StringUtils.isEmpty(poolIds) || customizeTagBOMap==null || customizeTagBOMap.isEmpty()) { | ||
93 | + return new ArrayList<>(); | ||
94 | + } | ||
97 | String[] poolIdArray = poolIds.split(","); | 95 | String[] poolIdArray = poolIds.split(","); |
98 | if (poolIdArray.length == 0) { | 96 | if (poolIdArray.length == 0) { |
99 | return new ArrayList<>(); | 97 | return new ArrayList<>(); |
@@ -107,9 +105,6 @@ public class CustomizeTagBaseService { | @@ -107,9 +105,6 @@ public class CustomizeTagBaseService { | ||
107 | } | 105 | } |
108 | //按照开始时间排序 | 106 | //按照开始时间排序 |
109 | List<CustomizeTag> sortedCustomizeTagList = customizeTagBOS.stream().sorted(Comparator.comparingInt(CustomizeTag::getBeginTime).reversed()).collect(Collectors.toList()); | 107 | List<CustomizeTag> sortedCustomizeTagList = customizeTagBOS.stream().sorted(Comparator.comparingInt(CustomizeTag::getBeginTime).reversed()).collect(Collectors.toList()); |
110 | - if (CollectionUtils.isEmpty(sortedCustomizeTagList)) { | ||
111 | - continue; | ||
112 | - } | ||
113 | //取第一个 | 108 | //取第一个 |
114 | CustomizeTag customizeTag = sortedCustomizeTagList.get(0); | 109 | CustomizeTag customizeTag = sortedCustomizeTagList.get(0); |
115 | JSONObject tag = new JSONObject(); | 110 | JSONObject tag = new JSONObject(); |
@@ -134,6 +129,9 @@ public class CustomizeTagBaseService { | @@ -134,6 +129,9 @@ public class CustomizeTagBaseService { | ||
134 | } | 129 | } |
135 | for (CustomizeTag customizeTag : customizeTagList) { | 130 | for (CustomizeTag customizeTag : customizeTagList) { |
136 | String poolIds = customizeTag.getPoolId(); | 131 | String poolIds = customizeTag.getPoolId(); |
132 | + if (StringUtils.isEmpty(poolIds)) { | ||
133 | + continue; | ||
134 | + } | ||
137 | String[] poolIdsArray = poolIds.split(","); | 135 | String[] poolIdsArray = poolIds.split(","); |
138 | if (poolIdsArray == null) { | 136 | if (poolIdsArray == null) { |
139 | continue; | 137 | continue; |
@@ -2,10 +2,12 @@ package com.yoho.search.service.index; | @@ -2,10 +2,12 @@ package com.yoho.search.service.index; | ||
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONArray; | 3 | import com.alibaba.fastjson.JSONArray; |
4 | import com.yoho.search.base.utils.ProductIndexEsField; | 4 | import com.yoho.search.base.utils.ProductIndexEsField; |
5 | +import com.yoho.search.service.helper.GoodsCoverHelper; | ||
5 | import org.apache.commons.collections.MapUtils; | 6 | import org.apache.commons.collections.MapUtils; |
6 | import org.apache.commons.lang.StringUtils; | 7 | import org.apache.commons.lang.StringUtils; |
7 | import org.slf4j.Logger; | 8 | import org.slf4j.Logger; |
8 | import org.slf4j.LoggerFactory; | 9 | import org.slf4j.LoggerFactory; |
10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
9 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
10 | 12 | ||
11 | import javax.annotation.PostConstruct; | 13 | import javax.annotation.PostConstruct; |
@@ -19,6 +21,9 @@ public class ProductIndexBaseService { | @@ -19,6 +21,9 @@ public class ProductIndexBaseService { | ||
19 | 21 | ||
20 | private static final Logger logger = LoggerFactory.getLogger(ProductIndexBaseService.class); | 22 | private static final Logger logger = LoggerFactory.getLogger(ProductIndexBaseService.class); |
21 | 23 | ||
24 | + @Autowired | ||
25 | + private GoodsCoverHelper goodsCoverHelper; | ||
26 | + | ||
22 | 27 | ||
23 | // 获取从source中不返回的字段定义,用以节省带宽 | 28 | // 获取从source中不返回的字段定义,用以节省带宽 |
24 | private List<String> productIndexIncludeFields = new ArrayList<String>(); | 29 | private List<String> productIndexIncludeFields = new ArrayList<String>(); |
@@ -110,7 +115,6 @@ public class ProductIndexBaseService { | @@ -110,7 +115,6 @@ public class ProductIndexBaseService { | ||
110 | return results; | 115 | return results; |
111 | } | 116 | } |
112 | 117 | ||
113 | - @SuppressWarnings("unchecked") | ||
114 | public Map<String, Object> getProductMapFromEsSource(Map<String, Object> map) { | 118 | public Map<String, Object> getProductMapFromEsSource(Map<String, Object> map) { |
115 | Map<String, Object> productMap = new HashMap<String, Object>(); | 119 | Map<String, Object> productMap = new HashMap<String, Object>(); |
116 | 120 | ||
@@ -140,8 +144,10 @@ public class ProductIndexBaseService { | @@ -140,8 +144,10 @@ public class ProductIndexBaseService { | ||
140 | productMap.put("student_price", "Y".equalsIgnoreCase(isStudentPrice) ? MapUtils.getDoubleValue(map, ProductIndexEsField.studentPrice) : null); | 144 | productMap.put("student_price", "Y".equalsIgnoreCase(isStudentPrice) ? MapUtils.getDoubleValue(map, ProductIndexEsField.studentPrice) : null); |
141 | productMap.put("is_student_rebate", MapUtils.getString(map, ProductIndexEsField.isstudentrebate, "N")); | 145 | productMap.put("is_student_rebate", MapUtils.getString(map, ProductIndexEsField.isstudentrebate, "N")); |
142 | 146 | ||
143 | - productMap.put("default_images", MapUtils.getString(map, ProductIndexEsField.defaultImages, "")); | 147 | + // 把gateway逻辑抽过来,抽取cover1,cover2 |
144 | productMap.put("skn_default_img", MapUtils.getString(map, ProductIndexEsField.sknDefaultImg, "")); | 148 | productMap.put("skn_default_img", MapUtils.getString(map, ProductIndexEsField.sknDefaultImg, "")); |
149 | + productMap.put("default_images", MapUtils.getString(map, ProductIndexEsField.defaultImages, "")); | ||
150 | + goodsCoverHelper.buildGoodsCover(map, productMap); | ||
145 | 151 | ||
146 | productMap.put("edit_time", MapUtils.getIntValue(map, ProductIndexEsField.editTime)); | 152 | productMap.put("edit_time", MapUtils.getIntValue(map, ProductIndexEsField.editTime)); |
147 | productMap.put("shelve_time", MapUtils.getIntValue(map, ProductIndexEsField.shelveTime)); | 153 | productMap.put("shelve_time", MapUtils.getIntValue(map, ProductIndexEsField.shelveTime)); |
@@ -7,6 +7,7 @@ import java.util.Map; | @@ -7,6 +7,7 @@ import java.util.Map; | ||
7 | 7 | ||
8 | import javax.annotation.PostConstruct; | 8 | import javax.annotation.PostConstruct; |
9 | 9 | ||
10 | +import com.yoho.search.service.helper.GoodsCoverHelper; | ||
10 | import org.apache.commons.collections.MapUtils; | 11 | import org.apache.commons.collections.MapUtils; |
11 | import org.apache.commons.lang.StringUtils; | 12 | import org.apache.commons.lang.StringUtils; |
12 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -21,6 +22,8 @@ public class WebProductIndexBaseService { | @@ -21,6 +22,8 @@ public class WebProductIndexBaseService { | ||
21 | 22 | ||
22 | @Autowired | 23 | @Autowired |
23 | private ProductPricePlanIndexBaseService productPricePlanIndexBaseService; | 24 | private ProductPricePlanIndexBaseService productPricePlanIndexBaseService; |
25 | + @Autowired | ||
26 | + private GoodsCoverHelper goodsCoverHelper; | ||
24 | 27 | ||
25 | // 获取从source中不返回的字段定义,用以节省带宽 | 28 | // 获取从source中不返回的字段定义,用以节省带宽 |
26 | private List<String> productIndexIncludeFields = new ArrayList<String>(); | 29 | private List<String> productIndexIncludeFields = new ArrayList<String>(); |
@@ -100,8 +103,10 @@ public class WebProductIndexBaseService { | @@ -100,8 +103,10 @@ public class WebProductIndexBaseService { | ||
100 | productMap.put("vip3_price", MapUtils.getDoubleValue(map, ProductIndexEsField.vip3Price, 0)); | 103 | productMap.put("vip3_price", MapUtils.getDoubleValue(map, ProductIndexEsField.vip3Price, 0)); |
101 | productMap.put("vip_discount_type", MapUtils.getIntValue(map, ProductIndexEsField.vipDiscountType, 1)); | 104 | productMap.put("vip_discount_type", MapUtils.getIntValue(map, ProductIndexEsField.vipDiscountType, 1)); |
102 | 105 | ||
103 | - productMap.put("default_images", MapUtils.getString(map, ProductIndexEsField.defaultImages, "")); | 106 | + // 把gateway逻辑抽过来,抽取cover1,cover2 |
104 | productMap.put("first_shelve_time", MapUtils.getIntValue(map, ProductIndexEsField.firstShelveTime)); | 107 | productMap.put("first_shelve_time", MapUtils.getIntValue(map, ProductIndexEsField.firstShelveTime)); |
108 | + productMap.put("default_images", MapUtils.getString(map, ProductIndexEsField.defaultImages, "")); | ||
109 | + goodsCoverHelper.buildGoodsCover(map, productMap); | ||
105 | 110 | ||
106 | productMap.put("gender", MapUtils.getString(map, ProductIndexEsField.gender, "")); | 111 | productMap.put("gender", MapUtils.getString(map, ProductIndexEsField.gender, "")); |
107 | productMap.put("status", MapUtils.getIntValue(map, ProductIndexEsField.status, 0)); | 112 | productMap.put("status", MapUtils.getIntValue(map, ProductIndexEsField.status, 0)); |
@@ -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; |
@@ -21,7 +21,7 @@ import java.util.*; | @@ -21,7 +21,7 @@ import java.util.*; | ||
21 | import java.util.stream.Collectors; | 21 | import java.util.stream.Collectors; |
22 | 22 | ||
23 | @Component | 23 | @Component |
24 | -public class ShopProductCacheBean extends AbstractCacheBean<ShopProductRequest, ShopProductResponse, ShopProductRequestResponse> { | 24 | +public class HrShopProductCacheBean extends AbstractCacheBean<HrShopProductRequest, HrShopProductResponse, HrShopProductRequestResponse> { |
25 | 25 | ||
26 | @Autowired | 26 | @Autowired |
27 | private SearchCommonService searchCommonService; | 27 | private SearchCommonService searchCommonService; |
@@ -32,15 +32,15 @@ public class ShopProductCacheBean extends AbstractCacheBean<ShopProductRequest, | @@ -32,15 +32,15 @@ public class ShopProductCacheBean extends AbstractCacheBean<ShopProductRequest, | ||
32 | @Autowired | 32 | @Autowired |
33 | private ProductListHelper productListHelper; | 33 | private ProductListHelper productListHelper; |
34 | 34 | ||
35 | - public List<ShopProductResponse> getShopSknByShopId(List<ShopProductRequest> shopSknRequests, String hrShopIds) { | ||
36 | - List<ShopProductRequestResponse> shopSknRequestResponses = new ArrayList<>(); | ||
37 | - for (ShopProductRequest request : shopSknRequests) { | ||
38 | - shopSknRequestResponses.add(new ShopProductRequestResponse(request)); | 35 | + public List<HrShopProductResponse> getShopSknByShopId(List<HrShopProductRequest> shopSknRequests, String hrShopIds) { |
36 | + List<HrShopProductRequestResponse> shopSknRequestResponses = new ArrayList<>(); | ||
37 | + for (HrShopProductRequest request : shopSknRequests) { | ||
38 | + shopSknRequestResponses.add(new HrShopProductRequestResponse(request)); | ||
39 | } | 39 | } |
40 | //2、执行父类方法 | 40 | //2、执行父类方法 |
41 | this.bacthFillResponseWithCache(shopSknRequestResponses, shopSknRequestResponses.size()); | 41 | this.bacthFillResponseWithCache(shopSknRequestResponses, shopSknRequestResponses.size()); |
42 | - List<ShopProductResponse> shopProductResponses = shopSknRequestResponses.stream().map(ShopProductRequestResponse::getResponse).filter(Objects::nonNull).collect(Collectors.toList()); | ||
43 | - for (ShopProductResponse response : shopProductResponses) { | 42 | + List<HrShopProductResponse> shopProductResponses = shopSknRequestResponses.stream().map(HrShopProductRequestResponse::getResponse).filter(Objects::nonNull).collect(Collectors.toList()); |
43 | + for (HrShopProductResponse response : shopProductResponses) { | ||
44 | response.setHr_shop_id(hrShopIds); | 44 | response.setHr_shop_id(hrShopIds); |
45 | } | 45 | } |
46 | //3、返回结果 | 46 | //3、返回结果 |
@@ -53,13 +53,13 @@ public class ShopProductCacheBean extends AbstractCacheBean<ShopProductRequest, | @@ -53,13 +53,13 @@ public class ShopProductCacheBean extends AbstractCacheBean<ShopProductRequest, | ||
53 | } | 53 | } |
54 | 54 | ||
55 | @Override | 55 | @Override |
56 | - protected Map<ShopProductRequest, ShopProductResponse> queryMissCacheRequestResults(List<ShopProductRequestResponse> missCacheRequests) { | ||
57 | - Map<ShopProductRequest, ShopProductResponse> results = new HashMap<>(); | 56 | + protected Map<HrShopProductRequest, HrShopProductResponse> queryMissCacheRequestResults(List<HrShopProductRequestResponse> missCacheRequests) { |
57 | + Map<HrShopProductRequest, HrShopProductResponse> results = new HashMap<>(); | ||
58 | if (missCacheRequests == null || missCacheRequests.isEmpty()) { | 58 | if (missCacheRequests == null || missCacheRequests.isEmpty()) { |
59 | return results; | 59 | return results; |
60 | } | 60 | } |
61 | List<SearchParam> searchParams = new ArrayList<>(); | 61 | List<SearchParam> searchParams = new ArrayList<>(); |
62 | - for (ShopProductRequestResponse requestResponse : missCacheRequests) { | 62 | + for (HrShopProductRequestResponse requestResponse : missCacheRequests) { |
63 | searchParams.add(requestResponse.getRequest().searchParam()); | 63 | searchParams.add(requestResponse.getRequest().searchParam()); |
64 | } | 64 | } |
65 | //2、执行搜索 | 65 | //2、执行搜索 |
@@ -76,7 +76,7 @@ public class ShopProductCacheBean extends AbstractCacheBean<ShopProductRequest, | @@ -76,7 +76,7 @@ public class ShopProductCacheBean extends AbstractCacheBean<ShopProductRequest, | ||
76 | //获得变价计划 | 76 | //获得变价计划 |
77 | Map<String, List<Map<String, Object>>> shopProductListMap = new HashMap<>(); | 77 | Map<String, List<Map<String, Object>>> shopProductListMap = new HashMap<>(); |
78 | for (int i = 0; i < missCacheRequests.size(); i++) { | 78 | for (int i = 0; i < missCacheRequests.size(); i++) { |
79 | - ShopProductRequest request = missCacheRequests.get(i).getRequest(); | 79 | + HrShopProductRequest request = missCacheRequests.get(i).getRequest(); |
80 | SearchResult searchResult = searchResults.get(i); | 80 | SearchResult searchResult = searchResults.get(i); |
81 | if (request != null && searchResult != null) { | 81 | if (request != null && searchResult != null) { |
82 | shopProductListMap.put(request.getShopId().toString(), searchResult.getResultList()); | 82 | shopProductListMap.put(request.getShopId().toString(), searchResult.getResultList()); |
@@ -84,17 +84,17 @@ public class ShopProductCacheBean extends AbstractCacheBean<ShopProductRequest, | @@ -84,17 +84,17 @@ public class ShopProductCacheBean extends AbstractCacheBean<ShopProductRequest, | ||
84 | } | 84 | } |
85 | shopProductListMap = productListHelper.buildReturnInfoByEsSourceListMap(shopProductListMap); | 85 | shopProductListMap = productListHelper.buildReturnInfoByEsSourceListMap(shopProductListMap); |
86 | for (int i = 0; i < missCacheRequests.size(); i++) { | 86 | for (int i = 0; i < missCacheRequests.size(); i++) { |
87 | - ShopProductRequest request = missCacheRequests.get(i).getRequest(); | 87 | + HrShopProductRequest request = missCacheRequests.get(i).getRequest(); |
88 | List<Map<String, Object>> productList = shopProductListMap.get(request.getShopId().toString()); | 88 | List<Map<String, Object>> productList = shopProductListMap.get(request.getShopId().toString()); |
89 | - ShopProductResponse response = buildResponse(productList, brandMap, request); | 89 | + HrShopProductResponse response = buildResponse(productList, brandMap, request); |
90 | results.put(request, response); | 90 | results.put(request, response); |
91 | } | 91 | } |
92 | return results; | 92 | return results; |
93 | } | 93 | } |
94 | 94 | ||
95 | - private ShopProductResponse buildResponse(List<Map<String, Object>> productList, Map<String, Map<String, Object>> brandMap, ShopProductRequest request) { | ||
96 | - ShopProductResponse response = new ShopProductResponse(); | ||
97 | - List<ShopProductResponse.ShopProduct> shopProductList = new ArrayList<>(); | 95 | + private HrShopProductResponse buildResponse(List<Map<String, Object>> productList, Map<String, Map<String, Object>> brandMap, HrShopProductRequest request) { |
96 | + HrShopProductResponse response = new HrShopProductResponse(); | ||
97 | + List<HrShopProductResponse.ShopProduct> shopProductList = new ArrayList<>(); | ||
98 | response.setShop_id(request.getShopId()); | 98 | response.setShop_id(request.getShopId()); |
99 | response.setShop_product_list(shopProductList); | 99 | response.setShop_product_list(shopProductList); |
100 | 100 | ||
@@ -103,7 +103,7 @@ public class ShopProductCacheBean extends AbstractCacheBean<ShopProductRequest, | @@ -103,7 +103,7 @@ public class ShopProductCacheBean extends AbstractCacheBean<ShopProductRequest, | ||
103 | response.setShop_name(MapUtils.getString(product, "shop_name", "")); | 103 | response.setShop_name(MapUtils.getString(product, "shop_name", "")); |
104 | //1、构建结果 | 104 | //1、构建结果 |
105 | for (Map<String, Object> productInfo : productList) { | 105 | for (Map<String, Object> productInfo : productList) { |
106 | - ShopProductResponse.ShopProduct shopProduct = new ShopProductResponse.ShopProduct(); | 106 | + HrShopProductResponse.ShopProduct shopProduct = new HrShopProductResponse.ShopProduct(); |
107 | shopProduct.setProduct_skn(MapUtils.getInteger(productInfo, "product_skn", 0)); | 107 | shopProduct.setProduct_skn(MapUtils.getInteger(productInfo, "product_skn", 0)); |
108 | shopProduct.setProduct_name(MapUtils.getString(productInfo, "product_name", "")); | 108 | shopProduct.setProduct_name(MapUtils.getString(productInfo, "product_name", "")); |
109 | shopProduct.setGender(MapUtils.getString(productInfo, "gender", "1,3")); | 109 | shopProduct.setGender(MapUtils.getString(productInfo, "gender", "1,3")); |
@@ -15,13 +15,13 @@ import org.elasticsearch.search.sort.SortOrder; | @@ -15,13 +15,13 @@ import org.elasticsearch.search.sort.SortOrder; | ||
15 | import java.util.Arrays; | 15 | import java.util.Arrays; |
16 | import java.util.List; | 16 | import java.util.List; |
17 | 17 | ||
18 | -public class ShopProductRequest implements ICacheRequest { | 18 | +public class HrShopProductRequest implements ICacheRequest { |
19 | private static final List<String> includeFields = Arrays.asList(ProductIndexEsField.productSkn, ProductIndexEsField.productName, ProductIndexEsField.shopId, ProductIndexEsField.shopName, ProductIndexEsField.defaultImages, ProductIndexEsField.goodsList, ProductIndexEsField.salesPrice,ProductIndexEsField.gender, ProductIndexEsField.brandId); | 19 | private static final List<String> includeFields = Arrays.asList(ProductIndexEsField.productSkn, ProductIndexEsField.productName, ProductIndexEsField.shopId, ProductIndexEsField.shopName, ProductIndexEsField.defaultImages, ProductIndexEsField.goodsList, ProductIndexEsField.salesPrice,ProductIndexEsField.gender, ProductIndexEsField.brandId); |
20 | private ParamQueryFilter paramQueryFilter; | 20 | private ParamQueryFilter paramQueryFilter; |
21 | private Integer shopId; | 21 | private Integer shopId; |
22 | private RedisKeyBuilder redisKeyBuilder; | 22 | private RedisKeyBuilder redisKeyBuilder; |
23 | 23 | ||
24 | - public ShopProductRequest(ParamQueryFilter paramQueryFilter, Integer shopId) { | 24 | + public HrShopProductRequest(ParamQueryFilter paramQueryFilter, Integer shopId) { |
25 | this.paramQueryFilter = paramQueryFilter; | 25 | this.paramQueryFilter = paramQueryFilter; |
26 | this.shopId = shopId; | 26 | this.shopId = shopId; |
27 | this.redisKeyBuilder = genRedisKeyBuilder(); | 27 | this.redisKeyBuilder = genRedisKeyBuilder(); |
service/src/main/java/com/yoho/search/service/scene/others/hongren/HrShopProductRequestResponse.java
0 → 100644
1 | +package com.yoho.search.service.scene.others.hongren; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSON; | ||
4 | +import com.yoho.search.base.utils.Transfer; | ||
5 | +import com.yoho.search.cache.model.AbstractCacheRequestResponse; | ||
6 | + | ||
7 | +public class HrShopProductRequestResponse extends AbstractCacheRequestResponse<HrShopProductRequest, HrShopProductResponse> { | ||
8 | + | ||
9 | + public HrShopProductRequestResponse(HrShopProductRequest request) { | ||
10 | + super(request); | ||
11 | + } | ||
12 | + | ||
13 | + @Override | ||
14 | + public Transfer<String, HrShopProductResponse> getToResponseTransfer() { | ||
15 | + return (v) -> JSON.parseObject(v, HrShopProductResponse.class); | ||
16 | + } | ||
17 | + | ||
18 | + @Override | ||
19 | + public Transfer<HrShopProductResponse, String> getFromResponseTransfer() { | ||
20 | + return (v) -> JSON.toJSONString(v); | ||
21 | + } | ||
22 | +} |
@@ -2,7 +2,7 @@ package com.yoho.search.service.scene.others.hongren; | @@ -2,7 +2,7 @@ package com.yoho.search.service.scene.others.hongren; | ||
2 | 2 | ||
3 | import java.util.List; | 3 | import java.util.List; |
4 | 4 | ||
5 | -public class ShopProductResponse { | 5 | +public class HrShopProductResponse { |
6 | private String hr_shop_id; | 6 | private String hr_shop_id; |
7 | private Integer shop_id; | 7 | private Integer shop_id; |
8 | private String shop_name; | 8 | private String shop_name; |
@@ -43,7 +43,7 @@ public class SearchHongRenService extends BaseSceneService { | @@ -43,7 +43,7 @@ public class SearchHongRenService extends BaseSceneService { | ||
43 | @Autowired | 43 | @Autowired |
44 | private AggregationFactory aggregationFactory; | 44 | private AggregationFactory aggregationFactory; |
45 | @Autowired | 45 | @Autowired |
46 | - private ShopProductCacheBean shopSknCacheBean; | 46 | + private HrShopProductCacheBean shopSknCacheBean; |
47 | 47 | ||
48 | public SearchApiResult shopList(Map<String, String> paramMap) { | 48 | public SearchApiResult shopList(Map<String, String> paramMap) { |
49 | int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum")); | 49 | int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum")); |
@@ -116,11 +116,11 @@ public class SearchHongRenService extends BaseSceneService { | @@ -116,11 +116,11 @@ public class SearchHongRenService extends BaseSceneService { | ||
116 | List<Integer> subShopIds = com.yoho.search.base.utils.CollectionUtils.safeSubList(shopIds, pageSize * (page - 1), pageSize * page); | 116 | List<Integer> subShopIds = com.yoho.search.base.utils.CollectionUtils.safeSubList(shopIds, pageSize * (page - 1), pageSize * page); |
117 | 117 | ||
118 | if (CollectionUtils.isNotEmpty(subShopIds)) { | 118 | if (CollectionUtils.isNotEmpty(subShopIds)) { |
119 | - List<ShopProductRequest> shopProductRequests = subShopIds.stream().map(shopId -> { | ||
120 | - return new ShopProductRequest(new ParamQueryFilter(searchParam.getQuery(), (BoolQueryBuilder)searchParam.getFiter()), shopId); | 119 | + List<HrShopProductRequest> shopProductRequests = subShopIds.stream().map(shopId -> { |
120 | + return new HrShopProductRequest(new ParamQueryFilter(searchParam.getQuery(), (BoolQueryBuilder)searchParam.getFiter()), shopId); | ||
121 | }).collect(Collectors.toList()); | 121 | }).collect(Collectors.toList()); |
122 | String hrShopIds = paramMap.get(SearchRequestParams.PARAM_SEARCH_HR_SHOP); | 122 | String hrShopIds = paramMap.get(SearchRequestParams.PARAM_SEARCH_HR_SHOP); |
123 | - List<ShopProductResponse> responseList = shopSknCacheBean.getShopSknByShopId(shopProductRequests, hrShopIds); | 123 | + List<HrShopProductResponse> responseList = shopSknCacheBean.getShopSknByShopId(shopProductRequests, hrShopIds); |
124 | dataMap.put("shop_product_list", responseList); | 124 | dataMap.put("shop_product_list", responseList); |
125 | } | 125 | } |
126 | } | 126 | } |
1 | package com.yoho.search.service.scene.searchlike; | 1 | package com.yoho.search.service.scene.searchlike; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | -import com.yoho.search.aop.cache.SearchCacheAble; | ||
5 | import com.yoho.search.base.utils.CollectionUtils; | 4 | import com.yoho.search.base.utils.CollectionUtils; |
6 | import com.yoho.search.base.utils.ProductIndexEsField; | 5 | import com.yoho.search.base.utils.ProductIndexEsField; |
6 | +import com.yoho.search.aop.cache.SearchCacheAble; | ||
7 | import com.yoho.search.common.SearchRequestParams; | 7 | import com.yoho.search.common.SearchRequestParams; |
8 | import com.yoho.search.core.es.model.SearchParam; | 8 | import com.yoho.search.core.es.model.SearchParam; |
9 | import com.yoho.search.models.SearchApiResult; | 9 | import com.yoho.search.models.SearchApiResult; |
10 | + | ||
10 | import com.yoho.search.service.helper.ProductListHelper; | 11 | import com.yoho.search.service.helper.ProductListHelper; |
11 | -import com.yoho.search.service.index.BigDataSimilarSknImgAliIndexBaseService; | ||
12 | import com.yoho.search.service.index.ProductIndexBaseService; | 12 | import com.yoho.search.service.index.ProductIndexBaseService; |
13 | import org.apache.commons.lang.StringUtils; | 13 | import org.apache.commons.lang.StringUtils; |
14 | import org.elasticsearch.index.query.BoolQueryBuilder; | 14 | import org.elasticsearch.index.query.BoolQueryBuilder; |
@@ -29,152 +29,114 @@ import java.util.Map; | @@ -29,152 +29,114 @@ import java.util.Map; | ||
29 | 29 | ||
30 | /** | 30 | /** |
31 | * 店铺内找相似 | 31 | * 店铺内找相似 |
32 | - * | 32 | + * |
33 | * @author gufei.hu | 33 | * @author gufei.hu |
34 | */ | 34 | */ |
35 | @Service | 35 | @Service |
36 | public class SearchLikeInShopService { | 36 | public class SearchLikeInShopService { |
37 | 37 | ||
38 | - private static final Logger logger = LoggerFactory.getLogger(SearchLikeInShopService.class); | ||
39 | - | ||
40 | - @Autowired | ||
41 | - private SearchLikeHelper searchLikeHelper; | ||
42 | - @Autowired | ||
43 | - private ProductIndexBaseService productIndexBaseService; | ||
44 | - @Autowired | ||
45 | - private ProductListHelper productListHelper; | ||
46 | - @Autowired | ||
47 | - private BigDataSimilarSknImgAliIndexBaseService bigDataSimilarSknImgAliIndexBaseService; | ||
48 | - | ||
49 | - /** | ||
50 | - * 店铺内推荐 | ||
51 | - */ | ||
52 | - @SearchCacheAble(cacheInMinute = 600, cacheName = "SEARCH_LIKE_IN_SHOP", includeParams = {"product_skn"}) | ||
53 | - public SearchApiResult searchLikeInShop(Map<String, String> paramMap) { | ||
54 | - try { | ||
55 | - // 1、获取参数 | ||
56 | - String productSkn = paramMap.get(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN); | ||
57 | - if (StringUtils.isBlank(productSkn)) { | ||
58 | - return new SearchApiResult().setCode(400).setMessage("请输入SKN"); | ||
59 | - } | ||
60 | - // 2、检测分页参数【默认30条】 | ||
61 | - int viewNum = 30; | ||
62 | - // 3、获取当前查询的SKN的基本信息 | ||
63 | - JSONObject productInfoInEs = searchLikeHelper.getProductInfoInEs(productSkn); | ||
64 | - if (productInfoInEs == null) { | ||
65 | - return new SearchApiResult().setCode(400).setMessage("SKN不存在"); | ||
66 | - } | ||
67 | - // 4、设置SearchParams | ||
68 | - List<SearchParam> searchParams = new ArrayList<>(); | ||
69 | - //4.1图片相似skn | ||
70 | - List<String> similarProductSknList = bigDataSimilarSknImgAliIndexBaseService.getSimilarProductSknListInShop(productSkn); | ||
71 | - if (similarProductSknList != null && !similarProductSknList.isEmpty()) { | ||
72 | - searchParams.add(this.builderSearchParamForSimilarImg(productInfoInEs, similarProductSknList, viewNum)); | ||
73 | - } | ||
74 | - //4.2文字相似skn | ||
75 | - searchParams.add(this.builderSearchParam(productInfoInEs, Arrays.asList(productSkn), viewNum)); | ||
76 | - // 5、获取搜索结果[截取条数] | ||
77 | - List<Map<String, Object>> tempProductList = new ArrayList<>(); | ||
78 | - //只包含文字相似 | ||
79 | - if (searchParams.size() == 1) { | ||
80 | - tempProductList = searchLikeHelper.queryProductList(searchParams); | ||
81 | - } else { | ||
82 | - //包含图片+文字相似 | ||
83 | - tempProductList = searchLikeHelper.queryProductListWithSimilarImg(searchParams, similarProductSknList); | ||
84 | - } | ||
85 | - if (tempProductList.size() > viewNum) { | ||
86 | - tempProductList = CollectionUtils.safeSubList(tempProductList, 0, viewNum); | ||
87 | - } | ||
88 | - //6、保留偶数 | ||
89 | - if (tempProductList.size() % 2 > 0) { | ||
90 | - tempProductList = CollectionUtils.safeSubList(tempProductList, 0, tempProductList.size() - 1); | ||
91 | - } | ||
92 | - // 7、构造返回结果 | ||
93 | - List<Map<String, Object>> productListResults = new ArrayList<>(); | ||
94 | - if (!tempProductList.isEmpty()) { | ||
95 | - productListResults = productListHelper.buildReturnInfoByEsSourceList(tempProductList); | ||
96 | - } | ||
97 | - JSONObject result = new JSONObject(); | ||
98 | - result.put("product_info", searchLikeHelper.genProductInfoResult(productInfoInEs)); | ||
99 | - result.put("product_list", productListResults); | ||
100 | - return new SearchApiResult().setData(result); | ||
101 | - } catch (Exception e) { | ||
102 | - logger.error(e.getMessage(), e); | ||
103 | - return new SearchApiResult().setData(null).setMessage("searchLikeInShop Exception").setCode(500); | ||
104 | - } | ||
105 | - } | 38 | + private static final Logger logger = LoggerFactory.getLogger(SearchLikeInShopService.class); |
106 | 39 | ||
107 | - private SearchParam builderSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize) { | ||
108 | - // 1、设置SearchParam | ||
109 | - SearchParam searchParam = new SearchParam(); | ||
110 | - // 2)设置query和filter | ||
111 | - searchParam.setQuery(this.builderQueryBuilder(productInfoInEs, "20%")); | ||
112 | - searchParam.setFiter(this.builderFilterBuilder(productInfoInEs, productSkns)); | ||
113 | - // 3、设置排序规则[按打分排序] | ||
114 | - List<SortBuilder<?>> sortBuilders = new ArrayList<SortBuilder<?>>(); | ||
115 | - sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC)); | ||
116 | - searchParam.setSortBuilders(sortBuilders); | ||
117 | - // 4、设置分页参数 | ||
118 | - searchParam.setOffset(0); | ||
119 | - searchParam.setSize(pageSize); | ||
120 | - // 5)设置返回的参数【节省带宽】 | ||
121 | - List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields(); | ||
122 | - searchParam.setIncludeFields(includeFields); | ||
123 | - return searchParam; | ||
124 | - } | 40 | + @Autowired |
41 | + private SearchLikeHelper searchLikeHelper; | ||
42 | + @Autowired | ||
43 | + private ProductIndexBaseService productIndexBaseService; | ||
44 | + @Autowired | ||
45 | + private ProductListHelper productListHelper; | ||
46 | + | ||
47 | + /** | ||
48 | + * 店铺内推荐 | ||
49 | + * | ||
50 | + * @param paramMap | ||
51 | + * @return | ||
52 | + */ | ||
53 | + @SearchCacheAble(cacheInMinute = 600, cacheName = "SEARCH_LIKE_IN_SHOP_NEW", includeParams = { "product_skn"}) | ||
54 | + public SearchApiResult searchLikeInShop(Map<String, String> paramMap) { | ||
55 | + try { | ||
56 | + // 1、获取参数 | ||
57 | + String productSkn = paramMap.get(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN); | ||
58 | + if (StringUtils.isBlank(productSkn)) { | ||
59 | + return new SearchApiResult().setCode(400).setMessage("请输入SKN"); | ||
60 | + } | ||
61 | + // 2、检测分页参数【默认30条】 | ||
62 | + int viewNum = 30; | ||
63 | + // 3、获取当前查询的SKN的基本信息 | ||
64 | + JSONObject productInfoInEs = searchLikeHelper.getProductInfoInEs(productSkn); | ||
65 | + if (productInfoInEs == null) { | ||
66 | + return new SearchApiResult().setCode(400).setMessage("SKN不存在"); | ||
67 | + } | ||
68 | + // 4、设置SearchParams | ||
69 | + List<SearchParam> searchParams = new ArrayList<SearchParam>(); | ||
70 | + searchParams.add(this.builderSearchParam(productInfoInEs, Arrays.asList(productSkn), viewNum)); | ||
71 | + // 5、获取搜索结果[截取条数] | ||
72 | + List<Map<String, Object>> tempProductList = searchLikeHelper.queryProductList(searchParams); | ||
73 | + if (tempProductList.size() > viewNum) { | ||
74 | + tempProductList = CollectionUtils.safeSubList(tempProductList,0, viewNum); | ||
75 | + } | ||
76 | + //6、保留偶数 | ||
77 | + if (tempProductList.size() % 2 > 0) { | ||
78 | + tempProductList = CollectionUtils.safeSubList(tempProductList, 0, tempProductList.size() - 1); | ||
79 | + } | ||
80 | + // 7、构造返回结果 | ||
81 | + List<Map<String, Object>> productListResults = new ArrayList<Map<String, Object>>(); | ||
82 | + if (!tempProductList.isEmpty()) { | ||
83 | + productListResults = productListHelper.buildReturnInfoByEsSourceList(tempProductList); | ||
84 | + } | ||
85 | + JSONObject result = new JSONObject(); | ||
86 | + result.put("product_info", searchLikeHelper.genProductInfoResult(productInfoInEs)); | ||
87 | + result.put("product_list", productListResults); | ||
88 | + return new SearchApiResult().setData(result); | ||
89 | + } catch (Exception e) { | ||
90 | + logger.error(e.getMessage(), e); | ||
91 | + return new SearchApiResult().setData(null).setMessage("searchLikeInShop Exception").setCode(500); | ||
92 | + } | ||
93 | + } | ||
125 | 94 | ||
126 | - private QueryBuilder builderFilterBuilder(JSONObject productInfoInEs, List<String> notProductSkns) { | ||
127 | - String isGlobalInEs = productInfoInEs.getString(ProductIndexEsField.isGlobal); | ||
128 | - boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs); | ||
129 | - BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(notProductSkns, isGlobal); | ||
130 | - // 1)设置此SKN相关的性别过滤条件 | ||
131 | - String gender = productInfoInEs.getString(ProductIndexEsField.gender); | ||
132 | - List<String> genderList = searchLikeHelper.getGenderInfo(gender); | ||
133 | - if (genderList != null && !genderList.isEmpty()) { | ||
134 | - boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.gender, genderList)); | ||
135 | - } | ||
136 | - // 2)设置品牌或店铺信息 | ||
137 | - Integer brandId = productInfoInEs.getInteger(ProductIndexEsField.brandId); | ||
138 | - Integer shopId = productInfoInEs.getInteger(ProductIndexEsField.shopId); | ||
139 | - if (searchLikeHelper.isLegalInteger(shopId)) { | ||
140 | - boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.shopId, shopId)); | ||
141 | - } else if (searchLikeHelper.isLegalInteger(brandId)) { | ||
142 | - boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.brandId, brandId)); | ||
143 | - } | ||
144 | - return boolFilter; | ||
145 | - } | 95 | + private SearchParam builderSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize) { |
96 | + // 1、设置SearchParam | ||
97 | + SearchParam searchParam = new SearchParam(); | ||
98 | + // 2)设置query和filter | ||
99 | + searchParam.setQuery(this.builderQueryBuilder(productInfoInEs, "20%")); | ||
100 | + searchParam.setFiter(this.builderFilterBuilder(productInfoInEs, productSkns)); | ||
101 | + // 3、设置排序规则[按打分排序] | ||
102 | + List<SortBuilder<?>> sortBuilders = new ArrayList<SortBuilder<?>>(); | ||
103 | + sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC)); | ||
104 | + searchParam.setSortBuilders(sortBuilders); | ||
105 | + // 4、设置分页参数 | ||
106 | + searchParam.setOffset(0); | ||
107 | + searchParam.setSize(pageSize); | ||
108 | + // 5)设置返回的参数【节省带宽】 | ||
109 | + List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields(); | ||
110 | + searchParam.setIncludeFields(includeFields); | ||
111 | + return searchParam; | ||
112 | + } | ||
146 | 113 | ||
147 | - private QueryBuilder builderQueryBuilder(JSONObject productInfoInEs, String minimumShouldMatch) { | ||
148 | - String queryString = searchLikeHelper.genYohoQueryStringWithBrandName(productInfoInEs); | ||
149 | - String productFeatureFactor = productInfoInEs.getString(ProductIndexEsField.productFeatureFactor); | ||
150 | - QueryBuilder queryBuilder = searchLikeHelper.genSearchLikeQueryBuilder(queryString, minimumShouldMatch, productFeatureFactor); | ||
151 | - return queryBuilder; | ||
152 | - } | 114 | + private QueryBuilder builderFilterBuilder(JSONObject productInfoInEs, List<String> notProductSkns) { |
115 | + String isGlobalInEs = productInfoInEs.getString(ProductIndexEsField.isGlobal); | ||
116 | + boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs); | ||
117 | + BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(notProductSkns, isGlobal); | ||
118 | + // 1)设置此SKN相关的性别过滤条件 | ||
119 | + String gender = productInfoInEs.getString(ProductIndexEsField.gender); | ||
120 | + List<String> genderList = searchLikeHelper.getGenderInfo(gender); | ||
121 | + if (genderList != null && !genderList.isEmpty()) { | ||
122 | + boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.gender, genderList)); | ||
123 | + } | ||
124 | + // 2)设置品牌或店铺信息 | ||
125 | + Integer brandId = productInfoInEs.getInteger(ProductIndexEsField.brandId); | ||
126 | + Integer shopId = productInfoInEs.getInteger(ProductIndexEsField.shopId); | ||
127 | + if (searchLikeHelper.isLegalInteger(shopId)) { | ||
128 | + boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.shopId, shopId)); | ||
129 | + } else if (searchLikeHelper.isLegalInteger(brandId)) { | ||
130 | + boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.brandId, brandId)); | ||
131 | + } | ||
132 | + return boolFilter; | ||
133 | + } | ||
153 | 134 | ||
154 | - /** | ||
155 | - * 根据阿里相似图片的skn构建SearchParam去查productindex | ||
156 | - */ | ||
157 | - private SearchParam builderSearchParamForSimilarImg(JSONObject productInfoInEs, List<String> productSkns, int pageSize) { | ||
158 | - // 1、设置SearchParam | ||
159 | - SearchParam searchParam = new SearchParam(); | ||
160 | - // 2)设置filter | ||
161 | - String isGlobalInEs = productInfoInEs.getString(ProductIndexEsField.isGlobal); | ||
162 | - boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs); | ||
163 | - BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(null, isGlobal); | ||
164 | - boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, productSkns)); | ||
165 | - String gender = productInfoInEs.getString(ProductIndexEsField.gender); | ||
166 | - List<String> genderList = searchLikeHelper.getGenderInfo(gender); | ||
167 | - if (genderList != null && !genderList.isEmpty()) { | ||
168 | - boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.gender, genderList)); | ||
169 | - } | ||
170 | - searchParam.setFiter(boolFilter); | ||
171 | - // 4、设置分页参数 | ||
172 | - searchParam.setOffset(0); | ||
173 | - searchParam.setSize(pageSize); | ||
174 | - // 5)设置返回的参数【节省带宽】 | ||
175 | - List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields(); | ||
176 | - searchParam.setIncludeFields(includeFields); | ||
177 | - return searchParam; | ||
178 | - } | 135 | + private QueryBuilder builderQueryBuilder(JSONObject productInfoInEs, String minimumShouldMatch) { |
136 | + String queryString = searchLikeHelper.genYohoQueryStringWithBrandName(productInfoInEs); | ||
137 | + String productFeatureFactor = productInfoInEs.getString(ProductIndexEsField.productFeatureFactor); | ||
138 | + QueryBuilder queryBuilder = searchLikeHelper.genSearchLikeQueryBuilder(queryString, minimumShouldMatch, productFeatureFactor); | ||
139 | + return queryBuilder; | ||
140 | + } | ||
179 | 141 | ||
180 | } | 142 | } |
1 | +package com.yoho.search.service.scene.shopbrand; | ||
2 | + | ||
3 | +import com.yoho.search.base.utils.ISearchConstants; | ||
4 | +import com.yoho.search.cache.beans.AbstractCacheBean; | ||
5 | +import com.yoho.search.common.SearchCommonService; | ||
6 | +import com.yoho.search.core.es.model.SearchParam; | ||
7 | +import com.yoho.search.core.es.model.SearchResult; | ||
8 | +import com.yoho.search.service.helper.ProductListHelper; | ||
9 | +import com.yoho.search.service.index.ShopsIndexBaseService; | ||
10 | +import org.apache.commons.lang3.StringUtils; | ||
11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
12 | +import org.springframework.stereotype.Service; | ||
13 | +import org.springframework.util.CollectionUtils; | ||
14 | + | ||
15 | +import java.util.ArrayList; | ||
16 | +import java.util.HashMap; | ||
17 | +import java.util.List; | ||
18 | +import java.util.Map; | ||
19 | + | ||
20 | +@Service | ||
21 | +public class ShopProductCacheBean extends AbstractCacheBean<ShopProductRequest, ShopProductResponse, ShopProductRequestResponse> { | ||
22 | + | ||
23 | + @Autowired | ||
24 | + private SearchCommonService searchCommonService; | ||
25 | + @Autowired | ||
26 | + private ShopsIndexBaseService shopsIndexBaseService; | ||
27 | + @Autowired | ||
28 | + private ProductListHelper productListHelper; | ||
29 | + | ||
30 | + | ||
31 | + public Map<String, ShopProductResponse> queryShopProductList(List<ShopProductRequest> requests) { | ||
32 | + List<ShopProductRequestResponse> requestResponses = new ArrayList<>(); | ||
33 | + requests.forEach(e -> requestResponses.add(new ShopProductRequestResponse(e))); | ||
34 | + //2、执行查询 | ||
35 | + this.bacthFillResponseWithCache(requestResponses,requests.size()); | ||
36 | + //3、返回结果 | ||
37 | + Map<String, ShopProductResponse> responseMap = new HashMap<>(); | ||
38 | + requestResponses.forEach(e -> { | ||
39 | + if (e.getResponse()!=null && e.getResponse().getCount() > 0) { | ||
40 | + responseMap.put(e.getRequest().getShopId().toString(), e.getResponse()); | ||
41 | + } | ||
42 | + }); | ||
43 | + return responseMap; | ||
44 | + } | ||
45 | + | ||
46 | + @Override | ||
47 | + protected boolean useEhCache() { | ||
48 | + return false; | ||
49 | + } | ||
50 | + | ||
51 | + @Override | ||
52 | + protected Map<ShopProductRequest, ShopProductResponse> queryMissCacheRequestResults(List<ShopProductRequestResponse> missCacheRequests) { | ||
53 | + Map<ShopProductRequest, ShopProductResponse> results = new HashMap<>(); | ||
54 | + if (missCacheRequests == null || missCacheRequests.isEmpty()) { | ||
55 | + return results; | ||
56 | + } | ||
57 | + List<SearchParam> searchParams = new ArrayList<>(); | ||
58 | + for (ShopProductRequestResponse requestResponse : missCacheRequests) { | ||
59 | + searchParams.add(requestResponse.getRequest().searchParam()); | ||
60 | + } | ||
61 | + List<SearchResult> searchResults = searchCommonService.doMutiSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParams); | ||
62 | + Map<String, List<Map<String, Object>>> shopProductListMap = new HashMap<>(); | ||
63 | + Map<String, Long> shopProductCountMap = new HashMap<>(); | ||
64 | + List<String> shopIds = new ArrayList<>(); | ||
65 | + for (int i = 0; i < missCacheRequests.size(); i++) { | ||
66 | + SearchResult searchResult = searchResults.get(i); | ||
67 | + String shopIdString = missCacheRequests.get(i).getRequest().getShopId().toString(); | ||
68 | + if (StringUtils.isNotBlank(shopIdString) && !shopIds.contains(shopIdString)) { | ||
69 | + shopIds.add(shopIdString); | ||
70 | + } | ||
71 | + if (!CollectionUtils.isEmpty(searchResult.getResultList())) { | ||
72 | + shopProductListMap.put(shopIdString, searchResult.getResultList()); | ||
73 | + } | ||
74 | + shopProductCountMap.put(shopIdString, searchResult.getTotal()); | ||
75 | + } | ||
76 | + Map<String, Map<String, Object>> shopMap = shopsIndexBaseService.getShopsMapByIds(shopIds); | ||
77 | + if (!CollectionUtils.isEmpty(shopProductListMap)) { | ||
78 | + shopProductListMap = productListHelper.buildReturnInfoByEsSourceListMap(shopProductListMap); | ||
79 | + } | ||
80 | + for (ShopProductRequestResponse requestResponse : missCacheRequests) { | ||
81 | + String shopId = requestResponse.getRequest().getShopId().toString(); | ||
82 | + ShopProductResponse response = new ShopProductResponse(); | ||
83 | + response.setCount(shopProductCountMap.get(shopId) != null ? shopProductCountMap.get(shopId).intValue() : 0); | ||
84 | + response.setInfo(shopMap.get(shopId)); | ||
85 | + response.setProduct_list(shopProductListMap.get(shopId)); | ||
86 | + results.put(requestResponse.getRequest(), response); | ||
87 | + } | ||
88 | + return results; | ||
89 | + } | ||
90 | +} |
1 | +package com.yoho.search.service.scene.shopbrand; | ||
2 | + | ||
3 | +import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder; | ||
4 | +import com.yoho.search.base.utils.MD5Util; | ||
5 | +import com.yoho.search.cache.CacheTimeConstants; | ||
6 | +import com.yoho.search.cache.model.ICacheRequest; | ||
7 | +import com.yoho.search.core.es.model.SearchParam; | ||
8 | +import com.yoho.search.service.recall.models.common.ParamQueryFilter; | ||
9 | +import org.elasticsearch.search.sort.SortBuilders; | ||
10 | +import org.elasticsearch.search.sort.SortOrder; | ||
11 | + | ||
12 | +import java.util.Arrays; | ||
13 | + | ||
14 | +public class ShopProductRequest implements ICacheRequest { | ||
15 | + | ||
16 | + private ParamQueryFilter paramQueryFilter; | ||
17 | + private Integer shopId; | ||
18 | + private Integer topHitCount; | ||
19 | + private RedisKeyBuilder redisKeyBuilder; | ||
20 | + | ||
21 | + | ||
22 | + public ShopProductRequest(ParamQueryFilter paramQueryFilter, Integer shopId, Integer topHitCount) { | ||
23 | + this.paramQueryFilter = paramQueryFilter; | ||
24 | + this.shopId = shopId; | ||
25 | + this.topHitCount = topHitCount; | ||
26 | + this.redisKeyBuilder = genRedisKeyBuilder(); | ||
27 | + } | ||
28 | + | ||
29 | + private RedisKeyBuilder genRedisKeyBuilder() { | ||
30 | + StringBuilder sb = new StringBuilder(); | ||
31 | + sb.append("paramMd5Key:").append(paramQueryFilter == null ? "" : paramQueryFilter.getParamMd5Key()); | ||
32 | + sb.append("shopCacheKey:").append(shopId == null ? "" : shopId); | ||
33 | + sb.append("topHitCountCacheKey:").append(topHitCount == null ? "" : topHitCount); | ||
34 | + String cacheKey = MD5Util.string2MD5(sb.toString()); | ||
35 | + RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance(); | ||
36 | + redisKeyBuilder.appendFixed("YOHOSEARCH:").appendFixed("SHOP:"); | ||
37 | + redisKeyBuilder.appendFixed(shopId).appendFixed(":"); | ||
38 | + redisKeyBuilder.appendVar(cacheTimeInMinute()).appendFixed(":"); | ||
39 | + redisKeyBuilder.appendVar(cacheKey); | ||
40 | + return redisKeyBuilder; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public RedisKeyBuilder redisKeyBuilder() { | ||
45 | + return this.redisKeyBuilder; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public int cacheTimeInMinute() { | ||
50 | + return CacheTimeConstants.CACHE_60_MINUTE; | ||
51 | + } | ||
52 | + | ||
53 | + public SearchParam searchParam() { | ||
54 | + SearchParam searchParam = new SearchParam(); | ||
55 | + if (paramQueryFilter != null && paramQueryFilter.getParamQuery() != null) { | ||
56 | + searchParam.setQuery(this.paramQueryFilter.getParamQuery()); | ||
57 | + } | ||
58 | + searchParam.setFiter(paramQueryFilter.getParamFilter()); | ||
59 | + searchParam.setSortBuilders(Arrays.asList(SortBuilders.fieldSort("heatValue").order(SortOrder.DESC))); | ||
60 | + searchParam.setOffset(0); | ||
61 | + searchParam.setSize(topHitCount); | ||
62 | + return searchParam; | ||
63 | + } | ||
64 | + | ||
65 | + | ||
66 | + public Integer getShopId() { | ||
67 | + return shopId; | ||
68 | + } | ||
69 | + | ||
70 | + public void setShopId(Integer shopId) { | ||
71 | + this.shopId = shopId; | ||
72 | + } | ||
73 | +} |
1 | -package com.yoho.search.service.scene.others.hongren; | ||
2 | - | ||
3 | -import com.alibaba.fastjson.JSON; | ||
4 | -import com.yoho.search.base.utils.Transfer; | ||
5 | -import com.yoho.search.cache.model.AbstractCacheRequestResponse; | ||
6 | - | ||
7 | -public class ShopProductRequestResponse extends AbstractCacheRequestResponse<ShopProductRequest, ShopProductResponse> { | ||
8 | - | ||
9 | - public ShopProductRequestResponse(ShopProductRequest request) { | ||
10 | - super(request); | ||
11 | - } | ||
12 | - | ||
13 | - @Override | ||
14 | - public Transfer<String, ShopProductResponse> getToResponseTransfer() { | ||
15 | - return (v) -> JSON.parseObject(v, ShopProductResponse.class); | ||
16 | - } | ||
17 | - | ||
18 | - @Override | ||
19 | - public Transfer<ShopProductResponse, String> getFromResponseTransfer() { | ||
20 | - return (v) -> JSON.toJSONString(v); | ||
21 | - } | ||
22 | -} | 1 | +package com.yoho.search.service.scene.shopbrand; |
2 | + | ||
3 | +import com.alibaba.fastjson.JSON; | ||
4 | +import com.yoho.search.base.utils.Transfer; | ||
5 | +import com.yoho.search.cache.model.AbstractCacheRequestResponse; | ||
6 | + | ||
7 | +public class ShopProductRequestResponse extends AbstractCacheRequestResponse<ShopProductRequest, ShopProductResponse> { | ||
8 | + | ||
9 | + public ShopProductRequestResponse(ShopProductRequest request) { | ||
10 | + super(request); | ||
11 | + } | ||
12 | + | ||
13 | + @Override | ||
14 | + public Transfer<String, ShopProductResponse> getToResponseTransfer() { | ||
15 | + return (v) -> JSON.parseObject(v, ShopProductResponse.class); | ||
16 | + } | ||
17 | + | ||
18 | + @Override | ||
19 | + public Transfer<ShopProductResponse, String> getFromResponseTransfer() { | ||
20 | + return (v) -> JSON.toJSONString(v); | ||
21 | + } | ||
22 | +} |
1 | +package com.yoho.search.service.scene.shopbrand; | ||
2 | + | ||
3 | +import java.util.List; | ||
4 | +import java.util.Map; | ||
5 | + | ||
6 | +public class ShopProductResponse { | ||
7 | + | ||
8 | + private Integer count; | ||
9 | + private Map<String, Object> info; | ||
10 | + private List<Map<String, Object>> product_list; | ||
11 | + | ||
12 | + public Integer getCount() { | ||
13 | + return count; | ||
14 | + } | ||
15 | + | ||
16 | + public void setCount(Integer count) { | ||
17 | + this.count = count; | ||
18 | + } | ||
19 | + | ||
20 | + public Map<String, Object> getInfo() { | ||
21 | + return info; | ||
22 | + } | ||
23 | + | ||
24 | + public void setInfo(Map<String, Object> info) { | ||
25 | + this.info = info; | ||
26 | + } | ||
27 | + | ||
28 | + public List<Map<String, Object>> getProduct_list() { | ||
29 | + return product_list; | ||
30 | + } | ||
31 | + | ||
32 | + public void setProduct_list(List<Map<String, Object>> product_list) { | ||
33 | + this.product_list = product_list; | ||
34 | + } | ||
35 | +} |
@@ -20,6 +20,7 @@ import com.yoho.search.common.SearchCommonService; | @@ -20,6 +20,7 @@ import com.yoho.search.common.SearchCommonService; | ||
20 | import com.yoho.search.common.SearchRequestParams; | 20 | import com.yoho.search.common.SearchRequestParams; |
21 | import com.yoho.search.service.helper.SearchParamHelper; | 21 | import com.yoho.search.service.helper.SearchParamHelper; |
22 | import com.yoho.search.common.BaseService; | 22 | import com.yoho.search.common.BaseService; |
23 | +import com.yoho.search.service.recall.models.common.ParamQueryFilter; | ||
23 | import org.apache.commons.collections.CollectionUtils; | 24 | import org.apache.commons.collections.CollectionUtils; |
24 | import org.apache.commons.lang.StringUtils; | 25 | import org.apache.commons.lang.StringUtils; |
25 | import org.elasticsearch.index.query.BoolQueryBuilder; | 26 | import org.elasticsearch.index.query.BoolQueryBuilder; |
@@ -37,6 +38,7 @@ import org.springframework.context.ApplicationEventPublisherAware; | @@ -37,6 +38,7 @@ import org.springframework.context.ApplicationEventPublisherAware; | ||
37 | import org.springframework.stereotype.Service; | 38 | import org.springframework.stereotype.Service; |
38 | 39 | ||
39 | import java.util.*; | 40 | import java.util.*; |
41 | +import java.util.stream.Collectors; | ||
40 | 42 | ||
41 | @Service | 43 | @Service |
42 | public class ShopsService extends BaseService implements ApplicationEventPublisherAware { | 44 | public class ShopsService extends BaseService implements ApplicationEventPublisherAware { |
@@ -53,6 +55,8 @@ public class ShopsService extends BaseService implements ApplicationEventPublish | @@ -53,6 +55,8 @@ public class ShopsService extends BaseService implements ApplicationEventPublish | ||
53 | private AggregationFactory aggregationFactory; | 55 | private AggregationFactory aggregationFactory; |
54 | @Autowired | 56 | @Autowired |
55 | private SearchParamHelper searchParamHelper; | 57 | private SearchParamHelper searchParamHelper; |
58 | + @Autowired | ||
59 | + private ShopProductCacheBean shopProductCacheBean; | ||
56 | 60 | ||
57 | private ApplicationEventPublisher publisher; | 61 | private ApplicationEventPublisher publisher; |
58 | 62 | ||
@@ -91,6 +95,37 @@ public class ShopsService extends BaseService implements ApplicationEventPublish | @@ -91,6 +95,37 @@ public class ShopsService extends BaseService implements ApplicationEventPublish | ||
91 | } | 95 | } |
92 | } | 96 | } |
93 | 97 | ||
98 | + public SearchApiResult groupShopsV2(Map<String, String> paramMap) { | ||
99 | + try { | ||
100 | + if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SHOP))) { | ||
101 | + return new SearchApiResult().setCode(400).setMessage("请传shop参数"); | ||
102 | + } | ||
103 | + // 1、获取topHitCount | ||
104 | + int topHitCount = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum")); | ||
105 | + | ||
106 | + // 2、从ES中获取 | ||
107 | + String[] shopIds = paramMap.get(SearchRequestParams.PARAM_SEARCH_SHOP).split(","); | ||
108 | + List<ShopProductRequest> requests = new ArrayList<>(); | ||
109 | + for (String shopId : shopIds) { | ||
110 | + paramMap.put(SearchRequestParams.PARAM_SEARCH_SHOP, shopId); | ||
111 | + SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, false); | ||
112 | + ParamQueryFilter paramQueryFilter = new ParamQueryFilter(searchParam.getQuery(), (BoolQueryBuilder) searchParam.getFiter()); | ||
113 | + requests.add(new ShopProductRequest(paramQueryFilter, Integer.valueOf(shopId), topHitCount)); | ||
114 | + } | ||
115 | + Map<String, ShopProductResponse> responseMap = shopProductCacheBean.queryShopProductList(requests); | ||
116 | + // 3、返回生成结果 | ||
117 | + Integer total = responseMap.values().stream().collect(Collectors.summingInt(ShopProductResponse::getCount)); | ||
118 | + JSONObject realResult = new JSONObject(); | ||
119 | + realResult.put("total", total); | ||
120 | + realResult.put("shops", responseMap); | ||
121 | + return new SearchApiResult().setData(realResult).setMessage("groupShops new List."); | ||
122 | + } catch (Exception e) { | ||
123 | + publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getEventName(), EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getFunctionName(), | ||
124 | + EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null)); | ||
125 | + return SearchApiResultUtils.errorSearchApiResult("group_shops", paramMap, e); | ||
126 | + } | ||
127 | + } | ||
128 | + | ||
94 | @SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_YOHO_BRAND", includeParams = {"keyword", "is_encode"}) | 129 | @SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_YOHO_BRAND", includeParams = {"keyword", "is_encode"}) |
95 | public SearchApiResult searchYohoBrand(Map<String, String> paramMap) { | 130 | public SearchApiResult searchYohoBrand(Map<String, String> paramMap) { |
96 | try { | 131 | try { |
@@ -257,5 +292,5 @@ public class ShopsService extends BaseService implements ApplicationEventPublish | @@ -257,5 +292,5 @@ public class ShopsService extends BaseService implements ApplicationEventPublish | ||
257 | } | 292 | } |
258 | return searchResult.getResultList().get(0).get(esFieldName).toString(); | 293 | return searchResult.getResultList().get(0).get(esFieldName).toString(); |
259 | } | 294 | } |
260 | - | 295 | + |
261 | } | 296 | } |
@@ -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 | } |
@@ -121,3 +121,5 @@ search.persional.rateLimit.productindex.recommendShop=100:2 | @@ -121,3 +121,5 @@ search.persional.rateLimit.productindex.recommendShop=100:2 | ||
121 | search.persional.rateLimit.productindex.aggRecommendBrand=100:2 | 121 | search.persional.rateLimit.productindex.aggRecommendBrand=100:2 |
122 | 122 | ||
123 | search.tbl.use.new.index = true | 123 | search.tbl.use.new.index = true |
124 | + | ||
125 | +search.shop.group.new=true |
@@ -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