Authored by unknown

优化4种场景

@@ -33,7 +33,7 @@ public class PriceAggregation extends AbstractAggregation { @@ -33,7 +33,7 @@ public class PriceAggregation extends AbstractAggregation {
33 33
34 @Override 34 @Override
35 public String filterName() { 35 public String filterName() {
36 - return "price"; 36 + return "priceRange";
37 } 37 }
38 38
39 @Override 39 @Override
@@ -98,17 +98,4 @@ public class BaseService { @@ -98,17 +98,4 @@ public class BaseService {
98 int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")); 98 int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
99 return page; 99 return page;
100 } 100 }
101 -  
102 - protected JSONObject getFilterResults(List<IAggregation> aggregations, Map<String, Aggregation> aggMaps) {  
103 - JSONObject filter = new JSONObject();  
104 - for (IAggregation aggregation : aggregations) {  
105 - Object response = aggregation.getAggregationResponseMap(aggMaps);  
106 - if (response == null) {  
107 - continue;  
108 - }  
109 - filter.put(aggregation.filterName(), response);  
110 - }  
111 - return filter;  
112 - }  
113 -  
114 } 101 }
1 package com.yoho.search.service.servicenew.scene; 1 package com.yoho.search.service.servicenew.scene;
2 2
3 -import java.util.List;  
4 import java.util.Map; 3 import java.util.Map;
  4 +import java.util.concurrent.CompletableFuture;
  5 +import java.util.concurrent.Executors;
5 6
6 import org.slf4j.Logger; 7 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
@@ -10,7 +11,6 @@ import org.springframework.stereotype.Service; @@ -10,7 +11,6 @@ import org.springframework.stereotype.Service;
10 11
11 import com.alibaba.fastjson.JSONObject; 12 import com.alibaba.fastjson.JSONObject;
12 import com.yoho.search.base.utils.SearchPageIdDefine; 13 import com.yoho.search.base.utils.SearchPageIdDefine;
13 -import com.yoho.search.core.es.agg.IAggregation;  
14 import com.yoho.search.service.servicenew.scene.common.AbstractSceneService; 14 import com.yoho.search.service.servicenew.scene.common.AbstractSceneService;
15 import com.yoho.search.service.servicenew.scene.common.SceneProductListService; 15 import com.yoho.search.service.servicenew.scene.common.SceneProductListService;
16 import com.yoho.search.service.servicenew.scene.common.SceneSelectionsService; 16 import com.yoho.search.service.servicenew.scene.common.SceneSelectionsService;
@@ -18,7 +18,7 @@ import com.yoho.search.service.utils.SearchApiResultUtils; @@ -18,7 +18,7 @@ import com.yoho.search.service.utils.SearchApiResultUtils;
18 import com.yoho.search.service.vo.SearchApiResult; 18 import com.yoho.search.service.vo.SearchApiResult;
19 19
20 @Service 20 @Service
21 -public class CouponSceneService extends AbstractSceneService{ 21 +public class CouponSceneService extends AbstractSceneService {
22 22
23 private static final Logger logger = LoggerFactory.getLogger(CouponSceneService.class); 23 private static final Logger logger = LoggerFactory.getLogger(CouponSceneService.class);
24 24
@@ -26,13 +26,23 @@ public class CouponSceneService extends AbstractSceneService{ @@ -26,13 +26,23 @@ public class CouponSceneService extends AbstractSceneService{
26 private SceneProductListService splitProductListService; 26 private SceneProductListService splitProductListService;
27 @Autowired 27 @Autowired
28 private SceneSelectionsService splitSelectionsService; 28 private SceneSelectionsService splitSelectionsService;
29 - 29 +
30 @Override 30 @Override
31 public String pageId() { 31 public String pageId() {
32 return SearchPageIdDefine.PAGE_ID_COUPON; 32 return SearchPageIdDefine.PAGE_ID_COUPON;
33 } 33 }
  34 +
  35 + @Override
  36 + public void addParamsToParamMap(Map<String, String> paramMap) {
  37 + super.addDefaultParamsToParamMap(paramMap);
  38 + }
34 39
35 @Override 40 @Override
  41 + public void setExecutorService() {
  42 + this.executorService = Executors.newFixedThreadPool(50);
  43 + }
  44 +
  45 + @Override
36 public SearchApiResult productList(Map<String, String> paramMap) { 46 public SearchApiResult productList(Map<String, String> paramMap) {
37 try { 47 try {
38 return splitProductListService.productList(paramMap); 48 return splitProductListService.productList(paramMap);
@@ -41,20 +51,33 @@ public class CouponSceneService extends AbstractSceneService{ @@ -41,20 +51,33 @@ public class CouponSceneService extends AbstractSceneService{
41 return SearchApiResultUtils.errorSearchApiResult("couponProductList", paramMap, e); 51 return SearchApiResultUtils.errorSearchApiResult("couponProductList", paramMap, e);
42 } 52 }
43 } 53 }
44 -  
45 - @Override  
46 - public SearchApiResult aggregations(Map<String, String> paramMap) {  
47 - // 1、获取优惠券页面的筛选结果  
48 - List<IAggregation> couponAggregations = splitSelectionsService.getCouponAggregations(paramMap);  
49 - JSONObject filterResults = splitSelectionsService.getFiltersResults(paramMap,couponAggregations);  
50 - Map<String, Object> result = new JSONObject();  
51 - result.put("filter", filterResults);  
52 - return new SearchApiResult().setData(result);  
53 - }  
54 54
55 @Override 55 @Override
56 - public void addParamsToParamMap(Map<String, String> paramMap) {  
57 - // TODO Auto-generated method stub 56 + public SearchApiResult aggregations(Map<String, String> paramMap) {
  57 + try {
  58 + // 0、添加默认参数
  59 + this.addParamsToParamMap(paramMap);
  60 + // 1、获取通用筛选项
  61 + CompletableFuture<JSONObject> commonFiltersFuture = CompletableFuture.supplyAsync(() -> {
  62 + return splitSelectionsService.getCommonFilters(paramMap);
  63 + }, executorService);
  64 + // 2、获取推荐的品牌
  65 + CompletableFuture<Object> recommendBrandFuture = CompletableFuture.supplyAsync(() -> {
  66 + return splitSelectionsService.getRecommendBrands(paramMap);
  67 + }, executorService);
  68 + // 3、组合
  69 + JSONObject commonFilters = commonFiltersFuture.get();
  70 + Object recommendBrand = recommendBrandFuture.get();
  71 + if (recommendBrand != null) {
  72 + commonFilters.put("recommendBrand", recommendBrand);
  73 + }
  74 + // 4、返回最终结果
  75 + Map<String, Object> result = new JSONObject();
  76 + result.put("filter", commonFilters);
  77 + return new SearchApiResult().setData(result);
  78 + } catch (Exception e) {
  79 + logger.error(e.getMessage(), e);
  80 + return new SearchApiResult().setData(null).setMessage("FuzzyAggregations Exception").setCode(500);
  81 + }
58 } 82 }
59 -  
60 } 83 }
@@ -2,6 +2,7 @@ package com.yoho.search.service.servicenew.scene; @@ -2,6 +2,7 @@ package com.yoho.search.service.servicenew.scene;
2 2
3 import java.util.Map; 3 import java.util.Map;
4 import java.util.concurrent.CompletableFuture; 4 import java.util.concurrent.CompletableFuture;
  5 +import java.util.concurrent.Executors;
5 6
6 import org.apache.commons.lang.StringUtils; 7 import org.apache.commons.lang.StringUtils;
7 import org.slf4j.Logger; 8 import org.slf4j.Logger;
@@ -53,6 +54,12 @@ public class FuzzySceneService extends AbstractSceneService { @@ -53,6 +54,12 @@ public class FuzzySceneService extends AbstractSceneService {
53 super.addDefaultParamsToParamMap(paramMap); 54 super.addDefaultParamsToParamMap(paramMap);
54 paramMap.put(SearchRequestParams.PARAM_SEARCH_NEED_SUGGESTION, "Y");// 返回建议词 55 paramMap.put(SearchRequestParams.PARAM_SEARCH_NEED_SUGGESTION, "Y");// 返回建议词
55 paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_SECKILL, "Y");// 包含秒杀商品 56 paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_SECKILL, "Y");// 包含秒杀商品
  57 + paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "Y");// 包含全球购
  58 + }
  59 +
  60 + @Override
  61 + public void setExecutorService() {
  62 + this.executorService = Executors.newFixedThreadPool(100);
56 } 63 }
57 64
58 /** 65 /**
@@ -57,4 +57,9 @@ public class NewArrivalSceneService extends AbstractSceneService{ @@ -57,4 +57,9 @@ public class NewArrivalSceneService extends AbstractSceneService{
57 // TODO Auto-generated method stub 57 // TODO Auto-generated method stub
58 } 58 }
59 59
  60 + @Override
  61 + public void setExecutorService() {
  62 + // TODO Auto-generated method stub
  63 + }
  64 +
60 } 65 }
@@ -56,4 +56,9 @@ public class ShopSceneService extends AbstractSceneService { @@ -56,4 +56,9 @@ public class ShopSceneService extends AbstractSceneService {
56 public void addParamsToParamMap(Map<String, String> paramMap) { 56 public void addParamsToParamMap(Map<String, String> paramMap) {
57 // TODO Auto-generated method stub 57 // TODO Auto-generated method stub
58 } 58 }
  59 +
  60 + @Override
  61 + public void setExecutorService() {
  62 + // TODO Auto-generated method stub
  63 + }
59 } 64 }
@@ -5,6 +5,7 @@ import java.util.Iterator; @@ -5,6 +5,7 @@ import java.util.Iterator;
5 import java.util.List; 5 import java.util.List;
6 import java.util.Map; 6 import java.util.Map;
7 import java.util.concurrent.CompletableFuture; 7 import java.util.concurrent.CompletableFuture;
  8 +import java.util.concurrent.Executors;
8 9
9 import org.apache.commons.collections.MapUtils; 10 import org.apache.commons.collections.MapUtils;
10 import org.apache.commons.lang.StringUtils; 11 import org.apache.commons.lang.StringUtils;
@@ -21,6 +22,7 @@ import com.yoho.search.service.servicenew.IProductIndexService; @@ -21,6 +22,7 @@ import com.yoho.search.service.servicenew.IProductIndexService;
21 import com.yoho.search.service.servicenew.scene.common.AbstractSceneService; 22 import com.yoho.search.service.servicenew.scene.common.AbstractSceneService;
22 import com.yoho.search.service.servicenew.scene.common.SceneProductListService; 23 import com.yoho.search.service.servicenew.scene.common.SceneProductListService;
23 import com.yoho.search.service.servicenew.scene.common.SceneSelectionsService; 24 import com.yoho.search.service.servicenew.scene.common.SceneSelectionsService;
  25 +import com.yoho.search.service.utils.SearchRequestParams;
24 import com.yoho.search.service.vo.SearchApiResult; 26 import com.yoho.search.service.vo.SearchApiResult;
25 27
26 @Service 28 @Service
@@ -43,13 +45,24 @@ public class SortSceneService extends AbstractSceneService { @@ -43,13 +45,24 @@ public class SortSceneService extends AbstractSceneService {
43 public String pageId() { 45 public String pageId() {
44 return SearchPageIdDefine.PAGE_ID_SORT; 46 return SearchPageIdDefine.PAGE_ID_SORT;
45 } 47 }
46 - 48 +
47 @Override 49 @Override
48 public void addParamsToParamMap(Map<String, String> paramMap) { 50 public void addParamsToParamMap(Map<String, String> paramMap) {
49 super.addDefaultParamsToParamMap(paramMap); 51 super.addDefaultParamsToParamMap(paramMap);
  52 + paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "Y");// 包含全球购
50 } 53 }
51 54
52 @Override 55 @Override
  56 + public void setExecutorService() {
  57 + this.executorService = Executors.newFixedThreadPool(100);
  58 + }
  59 +
  60 + /**
  61 + * @特殊参数:
  62 + * @1、paramNum-获取规则数量的接口
  63 + * @2、firstProductSkn-第一个展示的skn
  64 + */
  65 + @Override
53 public SearchApiResult productList(Map<String, String> paramMap) { 66 public SearchApiResult productList(Map<String, String> paramMap) {
54 try { 67 try {
55 // 0、添加默认参数 68 // 0、添加默认参数
1 package com.yoho.search.service.servicenew.scene; 1 package com.yoho.search.service.servicenew.scene;
2 2
3 import java.util.Map; 3 import java.util.Map;
  4 +import java.util.concurrent.CompletableFuture;
  5 +import java.util.concurrent.Executors;
4 6
5 import org.slf4j.Logger; 7 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
@@ -16,7 +18,7 @@ import com.yoho.search.service.utils.SearchApiResultUtils; @@ -16,7 +18,7 @@ import com.yoho.search.service.utils.SearchApiResultUtils;
16 import com.yoho.search.service.vo.SearchApiResult; 18 import com.yoho.search.service.vo.SearchApiResult;
17 19
18 @Service 20 @Service
19 -public class ZqSceneService extends AbstractSceneService{ 21 +public class ZqSceneService extends AbstractSceneService {
20 22
21 private static final Logger logger = LoggerFactory.getLogger(ZqSceneService.class); 23 private static final Logger logger = LoggerFactory.getLogger(ZqSceneService.class);
22 24
@@ -31,6 +33,16 @@ public class ZqSceneService extends AbstractSceneService{ @@ -31,6 +33,16 @@ public class ZqSceneService extends AbstractSceneService{
31 } 33 }
32 34
33 @Override 35 @Override
  36 + public void addParamsToParamMap(Map<String, String> paramMap) {
  37 + super.addDefaultParamsToParamMap(paramMap);
  38 + }
  39 +
  40 + @Override
  41 + public void setExecutorService() {
  42 + this.executorService = Executors.newFixedThreadPool(50);
  43 + }
  44 +
  45 + @Override
34 public SearchApiResult productList(Map<String, String> paramMap) { 46 public SearchApiResult productList(Map<String, String> paramMap) {
35 try { 47 try {
36 return splitProductListService.productList(paramMap); 48 return splitProductListService.productList(paramMap);
@@ -42,20 +54,30 @@ public class ZqSceneService extends AbstractSceneService{ @@ -42,20 +54,30 @@ public class ZqSceneService extends AbstractSceneService{
42 54
43 @Override 55 @Override
44 public SearchApiResult aggregations(Map<String, String> paramMap) { 56 public SearchApiResult aggregations(Map<String, String> paramMap) {
45 - // 1、获取通用筛选项  
46 - JSONObject commonFilters = splitSelectionsService.getCommonFilters(paramMap);  
47 - // 2、获取推荐的品牌  
48 - Object recommendBrand = splitSelectionsService.getRecommendBrands(paramMap);  
49 - if (recommendBrand != null) {  
50 - commonFilters.put("recommendBrand", recommendBrand); 57 + try {
  58 + // 0、添加默认参数
  59 + this.addParamsToParamMap(paramMap);
  60 + // 1、获取通用筛选项
  61 + CompletableFuture<JSONObject> commonFiltersFuture = CompletableFuture.supplyAsync(() -> {
  62 + return splitSelectionsService.getCommonFilters(paramMap);
  63 + }, executorService);
  64 + // 2、获取推荐的品牌
  65 + CompletableFuture<Object> recommendBrandFuture = CompletableFuture.supplyAsync(() -> {
  66 + return splitSelectionsService.getRecommendBrands(paramMap);
  67 + }, executorService);
  68 + // 3、组合
  69 + JSONObject commonFilters = commonFiltersFuture.get();
  70 + Object recommendBrand = recommendBrandFuture.get();
  71 + if (recommendBrand != null) {
  72 + commonFilters.put("recommendBrand", recommendBrand);
  73 + }
  74 + // 4、返回最终结果
  75 + Map<String, Object> result = new JSONObject();
  76 + result.put("filter", commonFilters);
  77 + return new SearchApiResult().setData(result);
  78 + } catch (Exception e) {
  79 + logger.error(e.getMessage(), e);
  80 + return new SearchApiResult().setData(null).setMessage("ZqAggregations Exception").setCode(500);
51 } 81 }
52 - Map<String, Object> result = new JSONObject();  
53 - result.put("filter", commonFilters);  
54 - return new SearchApiResult().setData(result);  
55 - }  
56 -  
57 - @Override  
58 - public void addParamsToParamMap(Map<String, String> paramMap) {  
59 - // TODO Auto-generated method stub  
60 } 82 }
61 } 83 }
@@ -2,7 +2,6 @@ package com.yoho.search.service.servicenew.scene.common; @@ -2,7 +2,6 @@ package com.yoho.search.service.servicenew.scene.common;
2 2
3 import java.util.Map; 3 import java.util.Map;
4 import java.util.concurrent.ExecutorService; 4 import java.util.concurrent.ExecutorService;
5 -import java.util.concurrent.Executors;  
6 5
7 import org.apache.commons.lang.StringUtils; 6 import org.apache.commons.lang.StringUtils;
8 7
@@ -11,32 +10,33 @@ import com.yoho.search.service.vo.SearchApiResult; @@ -11,32 +10,33 @@ import com.yoho.search.service.vo.SearchApiResult;
11 10
12 public abstract class AbstractSceneService { 11 public abstract class AbstractSceneService {
13 12
14 - protected static ExecutorService executorService = Executors.newFixedThreadPool(500);  
15 -  
16 /** 13 /**
17 * 场景化的默认参数 14 * 场景化的默认参数
18 * 15 *
19 * @param paramMap 16 * @param paramMap
20 */ 17 */
21 protected void addDefaultParamsToParamMap(Map<String, String> paramMap) { 18 protected void addDefaultParamsToParamMap(Map<String, String> paramMap) {
22 - paramMap.put(SearchRequestParams.PARAM_SEARCH_PAGEID, this.pageId()); 19 + paramMap.put(SearchRequestParams.PARAM_SEARCH_PAGEID, this.pageId());// 根据场景划分的页面id
23 paramMap.put(SearchRequestParams.PARAM_SEARCH_GLOBAL_FILTER_BRAND, "Y");// 页面屏蔽 20 paramMap.put(SearchRequestParams.PARAM_SEARCH_GLOBAL_FILTER_BRAND, "Y");// 页面屏蔽
24 paramMap.put(SearchRequestParams.PARAM_SEARCH_STATUS, "1");// 上架 21 paramMap.put(SearchRequestParams.PARAM_SEARCH_STATUS, "1");// 上架
25 paramMap.put(SearchRequestParams.PARAM_SEARCH_STOCKNUM, "1");// 有库存 22 paramMap.put(SearchRequestParams.PARAM_SEARCH_STOCKNUM, "1");// 有库存
26 paramMap.put(SearchRequestParams.PARAM_SEARCH_SHOWSOLDOUT, "1");// 显示售罄商品 23 paramMap.put(SearchRequestParams.PARAM_SEARCH_SHOWSOLDOUT, "1");// 显示售罄商品
27 - paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "Y");// 包含全球购  
28 paramMap.put(SearchRequestParams.PARAM_SEARCH_ISOUTLETS, "2");// 非奥莱 24 paramMap.put(SearchRequestParams.PARAM_SEARCH_ISOUTLETS, "2");// 非奥莱
29 paramMap.put("attribute_not", "2");// 非赠品 25 paramMap.put("attribute_not", "2");// 非赠品
30 // paramMap.put("sale", "Y");// 没用的参数 26 // paramMap.put("sale", "Y");// 没用的参数
31 } 27 }
32 - 28 +
33 protected int getPage(Map<String, String> paramMap) { 29 protected int getPage(Map<String, String> paramMap) {
34 int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")); 30 int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
35 return page; 31 return page;
36 } 32 }
37 - 33 +
  34 + protected ExecutorService executorService;
  35 +
  36 + public abstract void setExecutorService();
  37 +
38 public abstract void addParamsToParamMap(Map<String, String> paramMap); 38 public abstract void addParamsToParamMap(Map<String, String> paramMap);
39 - 39 +
40 public abstract String pageId(); 40 public abstract String pageId();
41 41
42 public abstract SearchApiResult productList(Map<String, String> paramMap); 42 public abstract SearchApiResult productList(Map<String, String> paramMap);
@@ -77,6 +77,18 @@ public class SceneSelectionsService extends BaseService { @@ -77,6 +77,18 @@ public class SceneSelectionsService extends BaseService {
77 } 77 }
78 return builders; 78 return builders;
79 } 79 }
  80 +
  81 + private JSONObject getFilterResults(List<IAggregation> aggregations, Map<String, Aggregation> aggMaps) {
  82 + JSONObject filter = new JSONObject();
  83 + for (IAggregation aggregation : aggregations) {
  84 + Object response = aggregation.getAggregationResponseMap(aggMaps);
  85 + if (response == null) {
  86 + continue;
  87 + }
  88 + filter.put(aggregation.filterName(), response);
  89 + }
  90 + return filter;
  91 + }
80 92
81 /** 93 /**
82 * @聚合选项: 94 * @聚合选项:
@@ -164,34 +176,6 @@ public class SceneSelectionsService extends BaseService { @@ -164,34 +176,6 @@ public class SceneSelectionsService extends BaseService {
164 } 176 }
165 177
166 /** 178 /**
167 - * 优惠券页面时用的筛选项  
168 - * @param paramMap  
169 - * @return  
170 - */  
171 - public List<IAggregation> getCouponAggregations(Map<String, String> paramMap) {  
172 - List<IAggregation> aggregations = new ArrayList<>();  
173 - // 1)性别  
174 - aggregations.add(aggregationFactoryService.getGenderNewAggregation());  
175 - // 2)品牌  
176 - aggregations.add(aggregationFactoryService.getBrandAggregation(paramMap));  
177 - // 3)人群  
178 - aggregations.add(aggregationFactoryService.getAgeLevelAggregation());  
179 - // 4)品类  
180 - aggregations.add(aggregationFactoryService.getSortGroupAggregation(paramMap));  
181 - // 5)颜色  
182 - aggregations.add(aggregationFactoryService.getColorAggregation(paramMap));  
183 - // 6)尺码  
184 - aggregations.add(aggregationFactoryService.getSizeAggregation());  
185 - // 7)价格  
186 - aggregations.add(aggregationFactoryService.getPriceAggregation());  
187 - // 8)折扣  
188 - aggregations.add(aggregationFactoryService.getDiscountAggregation());  
189 - // 9)风格  
190 - aggregations.add(aggregationFactoryService.getStyleAggregation(paramMap));  
191 - return aggregations;  
192 - }  
193 -  
194 - /**  
195 * 店铺、新频到着的筛选项列表 179 * 店铺、新频到着的筛选项列表
196 * @param paramMap 180 * @param paramMap
197 * @return 181 * @return