Authored by hugufei

拆包

Showing 19 changed files with 546 additions and 503 deletions
@@ -5,7 +5,8 @@ import com.yoho.search.aop.downgrade.PersionalRateLimit; @@ -5,7 +5,8 @@ import com.yoho.search.aop.downgrade.PersionalRateLimit;
5 import com.yoho.search.common.utils.HttpServletRequestUtils; 5 import com.yoho.search.common.utils.HttpServletRequestUtils;
6 import com.yoho.search.models.SearchApiResult; 6 import com.yoho.search.models.SearchApiResult;
7 import com.yoho.search.service.scene.list.ProductListSwitchService; 7 import com.yoho.search.service.scene.list.ProductListSwitchService;
8 -import com.yoho.search.service.scene.guang.ProductListService; 8 +import com.yoho.search.service.scene.guang.ProductListWithPhraseService;
  9 +import com.yoho.search.service.scene.tools.ProductListDslService;
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;
11 import org.springframework.web.bind.annotation.RequestBody; 12 import org.springframework.web.bind.annotation.RequestBody;
@@ -20,73 +21,61 @@ import java.util.Map; @@ -20,73 +21,61 @@ import java.util.Map;
20 @Controller 21 @Controller
21 public class ProductListController { 22 public class ProductListController {
22 23
23 - @Autowired  
24 - private ProductListService productListService;  
25 - @Autowired  
26 - private ProductListSwitchService productListSwitchService; 24 + @Autowired
  25 + private ProductListWithPhraseService productListWithPhraseService;
  26 + @Autowired
  27 + private ProductListSwitchService productListSwitchService;
27 28
28 - /**  
29 - * 获取商品列表-支持个性化降级  
30 - *  
31 - * @return  
32 - */  
33 - @PersionalRateLimit(isOrderUseable = true)  
34 - @RequestMapping(method = RequestMethod.GET, value = "/productindex/productList")  
35 - @ResponseBody  
36 - public SearchApiResult productList(HttpServletRequest request) {  
37 - Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);  
38 - return productListSwitchService.productList(paramMap);  
39 - } 29 + /**
  30 + * 获取商品列表-支持个性化降级
  31 + *
  32 + * @return
  33 + */
  34 + @PersionalRateLimit(isOrderUseable = true)
  35 + @RequestMapping(method = RequestMethod.GET, value = "/productindex/productList")
  36 + @ResponseBody
  37 + public SearchApiResult productList(HttpServletRequest request) {
  38 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  39 + return productListSwitchService.productList(paramMap);
  40 + }
40 41
41 - /**  
42 - * post的方式获取商品列表-不支持个性化  
43 - *  
44 - * @return  
45 - */  
46 - @RequestMapping(method = RequestMethod.POST, value = "/productindex/productListByPost")  
47 - @ResponseBody  
48 - public SearchApiResult productListByPost(@RequestBody JSONObject param) {  
49 - Map<String, String> paramMap = this.getParamMap(param);  
50 - paramMap.remove("uid");  
51 - return productListSwitchService.productList(paramMap);  
52 - } 42 + /**
  43 + * post的方式获取商品列表-不支持个性化
  44 + *
  45 + * @return
  46 + */
  47 + @RequestMapping(method = RequestMethod.POST, value = "/productindex/productListByPost")
  48 + @ResponseBody
  49 + public SearchApiResult productListByPost(@RequestBody JSONObject param) {
  50 + Map<String, String> paramMap = this.getParamMap(param);
  51 + paramMap.remove("uid");
  52 + return productListSwitchService.productList(paramMap);
  53 + }
53 54
54 - /**  
55 - * 获取商品列表-不支持个性化  
56 - *  
57 - * @return  
58 - */  
59 - @RequestMapping(method = RequestMethod.GET, value = "/productindex/productListWithPhrase")  
60 - @ResponseBody  
61 - public SearchApiResult productListWithPhrase(HttpServletRequest request) {  
62 - Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);  
63 - paramMap.remove("uid");  
64 - return productListService.productListWithPhrase(paramMap);  
65 - } 55 + /**
  56 + * 获取商品列表-不支持个性化
  57 + *
  58 + * @return
  59 + */
  60 + @RequestMapping(method = RequestMethod.GET, value = "/productindex/productListWithPhrase")
  61 + @ResponseBody
  62 + public SearchApiResult productListWithPhrase(HttpServletRequest request) {
  63 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  64 + paramMap.remove("uid");
  65 + return productListWithPhraseService.productListWithPhrase(paramMap);
  66 + }
66 67
67 - private Map<String, String> getParamMap(JSONObject param) {  
68 - Map<String, String> paramMap = new HashMap<String, String>();  
69 - for (Map.Entry<String, Object> entry : param.entrySet()) {  
70 - try {  
71 - Object value = entry.getValue();  
72 - String valueString = value == null ? null : value.toString();  
73 - paramMap.put(entry.getKey(), valueString);  
74 - } catch (Exception e) {  
75 - }  
76 - }  
77 - return paramMap;  
78 - }  
79 -  
80 - /**  
81 - * 打印获取商品列表的ES的dsl的工具接口  
82 - *  
83 - * @return  
84 - */  
85 - @RequestMapping(method = RequestMethod.GET, value = "/dsl/productList")  
86 - @ResponseBody  
87 - public SearchApiResult getESDsl(HttpServletRequest request) {  
88 - Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);  
89 - return productListService.getESDsl(paramMap);  
90 - } 68 + private Map<String, String> getParamMap(JSONObject param) {
  69 + Map<String, String> paramMap = new HashMap<String, String>();
  70 + for (Map.Entry<String, Object> entry : param.entrySet()) {
  71 + try {
  72 + Object value = entry.getValue();
  73 + String valueString = value == null ? null : value.toString();
  74 + paramMap.put(entry.getKey(), valueString);
  75 + } catch (Exception e) {
  76 + }
  77 + }
  78 + return paramMap;
  79 + }
91 80
92 } 81 }
  1 +package com.yoho.search.restapi.tools;
  2 +
  3 +import com.yoho.search.common.utils.HttpServletRequestUtils;
  4 +import com.yoho.search.models.SearchApiResult;
  5 +import com.yoho.search.service.scene.tools.ProductListDslService;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.web.bind.annotation.RequestMapping;
  8 +import org.springframework.web.bind.annotation.RequestMethod;
  9 +import org.springframework.web.bind.annotation.ResponseBody;
  10 +import org.springframework.web.bind.annotation.RestController;
  11 +
  12 +import javax.servlet.http.HttpServletRequest;
  13 +import java.util.Map;
  14 +
  15 +@RestController
  16 +public class ProductListDslController {
  17 +
  18 + @Autowired
  19 + private ProductListDslService productListDslService;
  20 +
  21 + /**
  22 + * 打印获取商品列表的ES的dsl的工具接口
  23 + *
  24 + * @return
  25 + */
  26 + @RequestMapping(method = RequestMethod.GET, value = "/dsl/productList")
  27 + @ResponseBody
  28 + public SearchApiResult getESDsl(HttpServletRequest request) {
  29 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  30 + return productListDslService.getESDsl(paramMap);
  31 + }
  32 +}
@@ -6,8 +6,8 @@ import com.yoho.search.models.SearchApiResult; @@ -6,8 +6,8 @@ import com.yoho.search.models.SearchApiResult;
6 import com.yoho.search.common.SearchRequestParams; 6 import com.yoho.search.common.SearchRequestParams;
7 import com.yoho.search.service.scene.list.ProductListSwitchService; 7 import com.yoho.search.service.scene.list.ProductListSwitchService;
8 import com.yoho.search.service.scene.common.AbstractSceneService; 8 import com.yoho.search.service.scene.common.AbstractSceneService;
9 -import com.yoho.search.service.scene.common.SceneRecommendBrandsService;  
10 -import com.yoho.search.service.scene.common.SceneSelectionsService; 9 +import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
  10 +import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
11 import org.apache.commons.lang3.StringUtils; 11 import org.apache.commons.lang3.StringUtils;
12 import org.slf4j.Logger; 12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory; 13 import org.slf4j.LoggerFactory;
@@ -26,7 +26,7 @@ public class BrandSceneService extends AbstractSceneService { @@ -26,7 +26,7 @@ public class BrandSceneService extends AbstractSceneService {
26 @Autowired 26 @Autowired
27 private SceneSelectionsService sceneSelectionsService; 27 private SceneSelectionsService sceneSelectionsService;
28 @Autowired 28 @Autowired
29 - private SceneRecommendBrandsService sceneRecommendBrandsService; 29 + private RecommendBrandsService recommendBrandsService;
30 30
31 @Override 31 @Override
32 public String pageId() { 32 public String pageId() {
@@ -66,7 +66,7 @@ public class BrandSceneService extends AbstractSceneService { @@ -66,7 +66,7 @@ public class BrandSceneService extends AbstractSceneService {
66 this.addParamsToParamMap(paramMap); 66 this.addParamsToParamMap(paramMap);
67 // 2、返回聚合结果 67 // 2、返回聚合结果
68 SearchApiResult result = sceneSelectionsService.aggregations(paramMap); 68 SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
69 - sceneRecommendBrandsService.getRecommendBrands(paramMap, result); 69 + recommendBrandsService.getRecommendBrands(paramMap, result);
70 return result; 70 return result;
71 } catch (Exception e) { 71 } catch (Exception e) {
72 logger.error("[func=BrandAggregations][params=" + paramMap + "]", e); 72 logger.error("[func=BrandAggregations][params=" + paramMap + "]", e);
@@ -18,8 +18,8 @@ import com.yoho.search.service.index.SizeIndexBaseService; @@ -18,8 +18,8 @@ import com.yoho.search.service.index.SizeIndexBaseService;
18 import com.yoho.search.service.helper.SearchParamHelper; 18 import com.yoho.search.service.helper.SearchParamHelper;
19 import com.yoho.search.service.scene.list.ProductListSwitchService; 19 import com.yoho.search.service.scene.list.ProductListSwitchService;
20 import com.yoho.search.service.scene.common.AbstractSceneService; 20 import com.yoho.search.service.scene.common.AbstractSceneService;
21 -import com.yoho.search.service.scene.common.SceneRecommendBrandsService;  
22 -import com.yoho.search.service.scene.common.SceneSelectionsService; 21 +import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
  22 +import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
23 import org.elasticsearch.search.SearchHit; 23 import org.elasticsearch.search.SearchHit;
24 import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; 24 import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
25 import org.elasticsearch.search.aggregations.Aggregation; 25 import org.elasticsearch.search.aggregations.Aggregation;
@@ -53,7 +53,7 @@ public class BreakSizeSceneService extends AbstractSceneService { @@ -53,7 +53,7 @@ public class BreakSizeSceneService extends AbstractSceneService {
53 @Autowired 53 @Autowired
54 private SceneSelectionsService sceneSelectionsService; 54 private SceneSelectionsService sceneSelectionsService;
55 @Autowired 55 @Autowired
56 - private SceneRecommendBrandsService sceneRecommendBrandsService; 56 + private RecommendBrandsService recommendBrandsService;
57 57
58 /** 58 /**
59 * 为断码区添加默认的过滤条件 59 * 为断码区添加默认的过滤条件
@@ -92,7 +92,7 @@ public class BreakSizeSceneService extends AbstractSceneService { @@ -92,7 +92,7 @@ public class BreakSizeSceneService extends AbstractSceneService {
92 // 2、返回聚合结果 92 // 2、返回聚合结果
93 List<IAggregation> aggregation = sceneSelectionsService.getBreakSizeAggregations(paramMap); 93 List<IAggregation> aggregation = sceneSelectionsService.getBreakSizeAggregations(paramMap);
94 SearchApiResult result = sceneSelectionsService.aggregations(paramMap, aggregation); 94 SearchApiResult result = sceneSelectionsService.aggregations(paramMap, aggregation);
95 - sceneRecommendBrandsService.getRecommendBrands(paramMap, result); 95 + recommendBrandsService.getRecommendBrands(paramMap, result);
96 return result; 96 return result;
97 } catch (Exception e) { 97 } catch (Exception e) {
98 logger.error("[func=Couponaggregations][params=" + paramMap + "]", e); 98 logger.error("[func=Couponaggregations][params=" + paramMap + "]", e);
@@ -8,8 +8,8 @@ import com.yoho.search.service.scene.img.SknImgsResponse; @@ -8,8 +8,8 @@ import com.yoho.search.service.scene.img.SknImgsResponse;
8 import com.yoho.search.common.SearchRequestParams; 8 import com.yoho.search.common.SearchRequestParams;
9 import com.yoho.search.service.scene.list.ProductListSwitchService; 9 import com.yoho.search.service.scene.list.ProductListSwitchService;
10 import com.yoho.search.service.scene.common.AbstractSceneService; 10 import com.yoho.search.service.scene.common.AbstractSceneService;
11 -import com.yoho.search.service.scene.common.SceneRecommendBrandsService;  
12 -import com.yoho.search.service.scene.common.SceneSelectionsService; 11 +import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
  12 +import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
13 import com.yoho.search.service.scene.img.SknImgsCacheBean; 13 import com.yoho.search.service.scene.img.SknImgsCacheBean;
14 import org.apache.commons.lang3.StringUtils; 14 import org.apache.commons.lang3.StringUtils;
15 import org.slf4j.Logger; 15 import org.slf4j.Logger;
@@ -30,7 +30,7 @@ public class CommonSceneService extends AbstractSceneService { @@ -30,7 +30,7 @@ public class CommonSceneService extends AbstractSceneService {
30 @Autowired 30 @Autowired
31 private SceneSelectionsService sceneSelectionsService; 31 private SceneSelectionsService sceneSelectionsService;
32 @Autowired 32 @Autowired
33 - private SceneRecommendBrandsService sceneRecommendBrandsService; 33 + private RecommendBrandsService recommendBrandsService;
34 @Autowired 34 @Autowired
35 private SknImgsCacheBean sknImgsCacheBean; 35 private SknImgsCacheBean sknImgsCacheBean;
36 36
@@ -64,7 +64,7 @@ public class CommonSceneService extends AbstractSceneService { @@ -64,7 +64,7 @@ public class CommonSceneService extends AbstractSceneService {
64 this.addParamsToParamMap(paramMap); 64 this.addParamsToParamMap(paramMap);
65 // 2、返回聚合结果 65 // 2、返回聚合结果
66 SearchApiResult result = sceneSelectionsService.aggregations(paramMap); 66 SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
67 - sceneRecommendBrandsService.getRecommendBrands(paramMap, result); 67 + recommendBrandsService.getRecommendBrands(paramMap, result);
68 return result; 68 return result;
69 } catch (Exception e) { 69 } catch (Exception e) {
70 logger.error("[func=Couponaggregations][params=" + paramMap + "]", e); 70 logger.error("[func=Couponaggregations][params=" + paramMap + "]", e);
@@ -5,8 +5,8 @@ import com.yoho.search.common.utils.SearchApiResultUtils; @@ -5,8 +5,8 @@ import com.yoho.search.common.utils.SearchApiResultUtils;
5 import com.yoho.search.models.SearchApiResult; 5 import com.yoho.search.models.SearchApiResult;
6 import com.yoho.search.service.scene.list.ProductListSwitchService; 6 import com.yoho.search.service.scene.list.ProductListSwitchService;
7 import com.yoho.search.service.scene.common.AbstractSceneService; 7 import com.yoho.search.service.scene.common.AbstractSceneService;
8 -import com.yoho.search.service.scene.common.SceneRecommendBrandsService;  
9 -import com.yoho.search.service.scene.common.SceneSelectionsService; 8 +import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
  9 +import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
10 import org.slf4j.Logger; 10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory; 11 import org.slf4j.LoggerFactory;
12 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.beans.factory.annotation.Autowired;
@@ -24,7 +24,7 @@ public class CouponSceneService extends AbstractSceneService { @@ -24,7 +24,7 @@ public class CouponSceneService extends AbstractSceneService {
24 @Autowired 24 @Autowired
25 private SceneSelectionsService sceneSelectionsService; 25 private SceneSelectionsService sceneSelectionsService;
26 @Autowired 26 @Autowired
27 - private SceneRecommendBrandsService sceneRecommendBrandsService; 27 + private RecommendBrandsService recommendBrandsService;
28 28
29 @Override 29 @Override
30 public String pageId() { 30 public String pageId() {
@@ -57,7 +57,7 @@ public class CouponSceneService extends AbstractSceneService { @@ -57,7 +57,7 @@ public class CouponSceneService extends AbstractSceneService {
57 this.addParamsToParamMap(paramMap); 57 this.addParamsToParamMap(paramMap);
58 // 2、返回聚合结果 58 // 2、返回聚合结果
59 SearchApiResult result = sceneSelectionsService.aggregations(paramMap); 59 SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
60 - sceneRecommendBrandsService.getRecommendBrands(paramMap, result); 60 + recommendBrandsService.getRecommendBrands(paramMap, result);
61 return result; 61 return result;
62 } catch (Exception e) { 62 } catch (Exception e) {
63 logger.error("[func=Couponaggregations][params=" + paramMap + "]", e); 63 logger.error("[func=Couponaggregations][params=" + paramMap + "]", e);
@@ -4,7 +4,7 @@ import java.util.Date; @@ -4,7 +4,7 @@ import java.util.Date;
4 import java.util.List; 4 import java.util.List;
5 import java.util.Map; 5 import java.util.Map;
6 6
7 -import com.yoho.search.service.scene.common.SceneRecommendBrandsService; 7 +import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
8 import org.slf4j.Logger; 8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory; 9 import org.slf4j.LoggerFactory;
10 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
@@ -18,7 +18,7 @@ import com.yoho.search.models.SearchApiResult; @@ -18,7 +18,7 @@ import com.yoho.search.models.SearchApiResult;
18 import com.yoho.search.common.SearchRequestParams; 18 import com.yoho.search.common.SearchRequestParams;
19 import com.yoho.search.service.scene.common.AbstractSceneService; 19 import com.yoho.search.service.scene.common.AbstractSceneService;
20 import com.yoho.search.service.scene.list.ProductListSwitchService; 20 import com.yoho.search.service.scene.list.ProductListSwitchService;
21 -import com.yoho.search.service.scene.common.SceneSelectionsService; 21 +import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
22 22
23 @Service 23 @Service
24 public class NewArrivalSceneService extends AbstractSceneService { 24 public class NewArrivalSceneService extends AbstractSceneService {
@@ -30,7 +30,7 @@ public class NewArrivalSceneService extends AbstractSceneService { @@ -30,7 +30,7 @@ public class NewArrivalSceneService extends AbstractSceneService {
30 @Autowired 30 @Autowired
31 private SceneSelectionsService sceneSelectionsService; 31 private SceneSelectionsService sceneSelectionsService;
32 @Autowired 32 @Autowired
33 - private SceneRecommendBrandsService sceneRecommendBrandsService; 33 + private RecommendBrandsService recommendBrandsService;
34 34
35 @Override 35 @Override
36 public String pageId() { 36 public String pageId() {
@@ -66,7 +66,7 @@ public class NewArrivalSceneService extends AbstractSceneService { @@ -66,7 +66,7 @@ public class NewArrivalSceneService extends AbstractSceneService {
66 this.addParamsToParamMap(paramMap); 66 this.addParamsToParamMap(paramMap);
67 // 2、返回聚合结果 67 // 2、返回聚合结果
68 SearchApiResult result = sceneSelectionsService.aggregations(paramMap); 68 SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
69 - sceneRecommendBrandsService.getRecommendBrands(paramMap, result); 69 + recommendBrandsService.getRecommendBrands(paramMap, result);
70 return result; 70 return result;
71 } catch (Exception e) { 71 } catch (Exception e) {
72 logger.error("[func=NewArrivalAggregations][params=" + paramMap + "]", e); 72 logger.error("[func=NewArrivalAggregations][params=" + paramMap + "]", e);
@@ -2,7 +2,7 @@ package com.yoho.search.service.scene; @@ -2,7 +2,7 @@ package com.yoho.search.service.scene;
2 2
3 import java.util.Map; 3 import java.util.Map;
4 4
5 -import com.yoho.search.service.scene.common.SceneRecommendBrandsService; 5 +import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
6 import org.apache.commons.lang.StringUtils; 6 import org.apache.commons.lang.StringUtils;
7 import org.slf4j.Logger; 7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
@@ -15,7 +15,7 @@ import com.yoho.search.models.SearchApiResult; @@ -15,7 +15,7 @@ import com.yoho.search.models.SearchApiResult;
15 import com.yoho.search.common.SearchRequestParams; 15 import com.yoho.search.common.SearchRequestParams;
16 import com.yoho.search.service.scene.common.AbstractSceneService; 16 import com.yoho.search.service.scene.common.AbstractSceneService;
17 import com.yoho.search.service.scene.list.ProductListSwitchService; 17 import com.yoho.search.service.scene.list.ProductListSwitchService;
18 -import com.yoho.search.service.scene.common.SceneSelectionsService; 18 +import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
19 19
20 @Service 20 @Service
21 public class ProductPoolSceneService extends AbstractSceneService { 21 public class ProductPoolSceneService extends AbstractSceneService {
@@ -27,7 +27,7 @@ public class ProductPoolSceneService extends AbstractSceneService { @@ -27,7 +27,7 @@ public class ProductPoolSceneService extends AbstractSceneService {
27 @Autowired 27 @Autowired
28 private SceneSelectionsService sceneSelectionsService; 28 private SceneSelectionsService sceneSelectionsService;
29 @Autowired 29 @Autowired
30 - private SceneRecommendBrandsService sceneRecommendBrandsService; 30 + private RecommendBrandsService recommendBrandsService;
31 31
32 /** 32 /**
33 * 33 *
@@ -91,7 +91,7 @@ public class ProductPoolSceneService extends AbstractSceneService { @@ -91,7 +91,7 @@ public class ProductPoolSceneService extends AbstractSceneService {
91 try { 91 try {
92 this.addParamsToParamMap(paramMap); 92 this.addParamsToParamMap(paramMap);
93 SearchApiResult result = sceneSelectionsService.aggregations(paramMap); 93 SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
94 - sceneRecommendBrandsService.getRecommendBrands(paramMap, result); 94 + recommendBrandsService.getRecommendBrands(paramMap, result);
95 return result; 95 return result;
96 } catch (Exception e) { 96 } catch (Exception e) {
97 logger.error("[func=PoolAggregations][params=" + paramMap + "]", e); 97 logger.error("[func=PoolAggregations][params=" + paramMap + "]", e);
@@ -17,7 +17,7 @@ import com.yoho.search.models.SearchApiResult; @@ -17,7 +17,7 @@ import com.yoho.search.models.SearchApiResult;
17 import com.yoho.search.common.SearchRequestParams; 17 import com.yoho.search.common.SearchRequestParams;
18 import com.yoho.search.service.scene.common.AbstractSceneService; 18 import com.yoho.search.service.scene.common.AbstractSceneService;
19 import com.yoho.search.service.scene.list.ProductListSwitchService; 19 import com.yoho.search.service.scene.list.ProductListSwitchService;
20 -import com.yoho.search.service.scene.common.SceneSelectionsService; 20 +import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
21 21
22 @Service 22 @Service
23 public class ReducePriceSceneService extends AbstractSceneService { 23 public class ReducePriceSceneService extends AbstractSceneService {
@@ -3,7 +3,7 @@ package com.yoho.search.service.scene; @@ -3,7 +3,7 @@ package com.yoho.search.service.scene;
3 import java.util.List; 3 import java.util.List;
4 import java.util.Map; 4 import java.util.Map;
5 5
6 -import com.yoho.search.service.scene.common.SceneRecommendBrandsService; 6 +import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
7 import org.apache.commons.lang3.StringUtils; 7 import org.apache.commons.lang3.StringUtils;
8 import org.slf4j.Logger; 8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory; 9 import org.slf4j.LoggerFactory;
@@ -17,7 +17,7 @@ import com.yoho.search.models.SearchApiResult; @@ -17,7 +17,7 @@ import com.yoho.search.models.SearchApiResult;
17 import com.yoho.search.common.SearchRequestParams; 17 import com.yoho.search.common.SearchRequestParams;
18 import com.yoho.search.service.scene.common.AbstractSceneService; 18 import com.yoho.search.service.scene.common.AbstractSceneService;
19 import com.yoho.search.service.scene.list.ProductListSwitchService; 19 import com.yoho.search.service.scene.list.ProductListSwitchService;
20 -import com.yoho.search.service.scene.common.SceneSelectionsService; 20 +import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
21 21
22 @Service 22 @Service
23 public class ShopSceneService extends AbstractSceneService { 23 public class ShopSceneService extends AbstractSceneService {
@@ -29,7 +29,7 @@ public class ShopSceneService extends AbstractSceneService { @@ -29,7 +29,7 @@ public class ShopSceneService extends AbstractSceneService {
29 @Autowired 29 @Autowired
30 private SceneSelectionsService sceneSelectionsService; 30 private SceneSelectionsService sceneSelectionsService;
31 @Autowired 31 @Autowired
32 - private SceneRecommendBrandsService sceneRecommendBrandsService; 32 + private RecommendBrandsService recommendBrandsService;
33 33
34 @Override 34 @Override
35 public String pageId() { 35 public String pageId() {
@@ -69,7 +69,7 @@ public class ShopSceneService extends AbstractSceneService { @@ -69,7 +69,7 @@ public class ShopSceneService extends AbstractSceneService {
69 this.addParamsToParamMap(paramMap); 69 this.addParamsToParamMap(paramMap);
70 // 2、返回聚合结果 70 // 2、返回聚合结果
71 SearchApiResult result = sceneSelectionsService.aggregations(paramMap); 71 SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
72 - sceneRecommendBrandsService.getRecommendBrands(paramMap, result); 72 + recommendBrandsService.getRecommendBrands(paramMap, result);
73 return result; 73 return result;
74 } catch (Exception e) { 74 } catch (Exception e) {
75 logger.error("[func=ShopAggregations][params=" + paramMap + "]", e); 75 logger.error("[func=ShopAggregations][params=" + paramMap + "]", e);
@@ -7,8 +7,8 @@ import com.yoho.search.common.SearchRequestParams; @@ -7,8 +7,8 @@ import com.yoho.search.common.SearchRequestParams;
7 import com.yoho.search.service.scene.list.ProductListSwitchService; 7 import com.yoho.search.service.scene.list.ProductListSwitchService;
8 import com.yoho.search.service.scene.aggregations.SceneAggregationsHelper; 8 import com.yoho.search.service.scene.aggregations.SceneAggregationsHelper;
9 import com.yoho.search.service.scene.common.AbstractSceneService; 9 import com.yoho.search.service.scene.common.AbstractSceneService;
10 -import com.yoho.search.service.scene.common.SceneRecommendBrandsService;  
11 -import com.yoho.search.service.scene.common.SceneSelectionsService; 10 +import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
  11 +import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
12 import org.apache.commons.lang.StringUtils; 12 import org.apache.commons.lang.StringUtils;
13 import org.slf4j.Logger; 13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory; 14 import org.slf4j.LoggerFactory;
@@ -32,7 +32,7 @@ public class SortSceneService extends AbstractSceneService { @@ -32,7 +32,7 @@ public class SortSceneService extends AbstractSceneService {
32 @Autowired 32 @Autowired
33 private SceneAggregationsHelper sceneAggregationsHelper; 33 private SceneAggregationsHelper sceneAggregationsHelper;
34 @Autowired 34 @Autowired
35 - private SceneRecommendBrandsService sceneRecommendBrandsService; 35 + private RecommendBrandsService recommendBrandsService;
36 36
37 @Override 37 @Override
38 public String pageId() { 38 public String pageId() {
@@ -112,7 +112,7 @@ public class SortSceneService extends AbstractSceneService { @@ -112,7 +112,7 @@ public class SortSceneService extends AbstractSceneService {
112 this.addParamsToParamMap(paramMap); 112 this.addParamsToParamMap(paramMap);
113 // 2、返回聚合结果 113 // 2、返回聚合结果
114 SearchApiResult result = sceneSelectionsService.aggregations(paramMap); 114 SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
115 - sceneRecommendBrandsService.getRecommendBrands(paramMap, result); 115 + recommendBrandsService.getRecommendBrands(paramMap, result);
116 return result; 116 return result;
117 } catch (Exception e) { 117 } catch (Exception e) {
118 logger.error(e.getMessage(), e); 118 logger.error(e.getMessage(), e);
@@ -2,7 +2,7 @@ package com.yoho.search.service.scene; @@ -2,7 +2,7 @@ package com.yoho.search.service.scene;
2 2
3 import java.util.Map; 3 import java.util.Map;
4 4
5 -import com.yoho.search.service.scene.common.SceneRecommendBrandsService; 5 +import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
6 import org.apache.commons.lang.StringUtils; 6 import org.apache.commons.lang.StringUtils;
7 import org.slf4j.Logger; 7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
@@ -15,7 +15,7 @@ import com.yoho.search.models.SearchApiResult; @@ -15,7 +15,7 @@ import com.yoho.search.models.SearchApiResult;
15 import com.yoho.search.common.SearchRequestParams; 15 import com.yoho.search.common.SearchRequestParams;
16 import com.yoho.search.service.scene.common.AbstractSceneService; 16 import com.yoho.search.service.scene.common.AbstractSceneService;
17 import com.yoho.search.service.scene.list.ProductListSwitchService; 17 import com.yoho.search.service.scene.list.ProductListSwitchService;
18 -import com.yoho.search.service.scene.common.SceneSelectionsService; 18 +import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
19 19
20 @Service 20 @Service
21 public class ZqSceneService extends AbstractSceneService { 21 public class ZqSceneService extends AbstractSceneService {
@@ -27,7 +27,7 @@ public class ZqSceneService extends AbstractSceneService { @@ -27,7 +27,7 @@ public class ZqSceneService extends AbstractSceneService {
27 @Autowired 27 @Autowired
28 private SceneSelectionsService sceneSelectionsService; 28 private SceneSelectionsService sceneSelectionsService;
29 @Autowired 29 @Autowired
30 - private SceneRecommendBrandsService sceneRecommendBrandsService; 30 + private RecommendBrandsService recommendBrandsService;
31 31
32 @Override 32 @Override
33 public String pageId() { 33 public String pageId() {
@@ -67,7 +67,7 @@ public class ZqSceneService extends AbstractSceneService { @@ -67,7 +67,7 @@ public class ZqSceneService extends AbstractSceneService {
67 this.addParamsToParamMap(paramMap); 67 this.addParamsToParamMap(paramMap);
68 // 2、返回聚合结果 68 // 2、返回聚合结果
69 SearchApiResult result = sceneSelectionsService.aggregations(paramMap); 69 SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
70 - sceneRecommendBrandsService.getRecommendBrands(paramMap, result); 70 + recommendBrandsService.getRecommendBrands(paramMap, result);
71 return result; 71 return result;
72 } catch (Exception e) { 72 } catch (Exception e) {
73 logger.error("[func=zqProductList][params=" + paramMap + "]", e); 73 logger.error("[func=zqProductList][params=" + paramMap + "]", e);
1 -package com.yoho.search.service.scene.common;  
2 -  
3 -import com.alibaba.fastjson.JSONObject;  
4 -import com.yoho.search.base.utils.ISearchConstants;  
5 -import com.yoho.search.cache.log.SearchCacheMatchLogger;  
6 -import com.yoho.search.cache.model.SearchCache;  
7 -import com.yoho.search.cache.beans.AbstractCacheAbleService;  
8 -import com.yoho.search.core.es.agg.IAggregation;  
9 -import com.yoho.search.core.es.model.SearchParam;  
10 -import com.yoho.search.core.es.model.SearchResult;  
11 -import com.yoho.search.models.SearchApiResult;  
12 -import com.yoho.search.service.scene.aggregations.impls.AggregationFactory;  
13 -import com.yoho.search.common.SearchCommonService;  
14 -import com.yoho.search.service.helper.SearchParamHelper;  
15 -import org.elasticsearch.index.query.BoolQueryBuilder;  
16 -import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;  
17 -import org.elasticsearch.search.aggregations.Aggregation;  
18 -import org.slf4j.Logger;  
19 -import org.slf4j.LoggerFactory;  
20 -import org.springframework.beans.factory.annotation.Autowired;  
21 -import org.springframework.stereotype.Service;  
22 -  
23 -import java.util.ArrayList;  
24 -import java.util.HashMap;  
25 -import java.util.List;  
26 -import java.util.Map;  
27 -  
28 -  
29 -@Service  
30 -public class SceneSelectionsService extends AbstractCacheAbleService {  
31 -  
32 - private static final Logger logger = LoggerFactory.getLogger(SceneSelectionsService.class);  
33 -  
34 - @Autowired  
35 - private SearchParamHelper searchParamHelper;  
36 - @Autowired  
37 - private SearchCommonService searchCommonService;  
38 - @Autowired  
39 - private AggregationFactory aggregationFactory;  
40 -  
41 - @Override  
42 - public SearchCache getSearchCache() {  
43 - return searchCacheFactory.getSceneAggregationsCache();  
44 - }  
45 -  
46 - /**  
47 - * @新版筛选器的聚合选项:  
48 - * @1、全球购  
49 - * @2、促销  
50 - * @3、全部的品牌 +喜欢的品牌【个性化的】  
51 - * @4、人群  
52 - * @5、品类  
53 - * @6、性别  
54 - * @7、价格  
55 - * @8、折扣  
56 - * @9、颜色  
57 - * @10、尺码  
58 - * @11、风格  
59 - */  
60 -  
61 - public List<IAggregation> getCommonAggregations(Map<String, String> paramMap) {  
62 - List<IAggregation> aggregations = new ArrayList<>();  
63 - // 1)专区名称  
64 - aggregations.add(aggregationFactory.getZqNameAggregation(1000));  
65 - // 2)全球购  
66 - aggregations.add(aggregationFactory.getIsGlobalAggregation());  
67 - // 3)品牌  
68 - aggregations.add(aggregationFactory.getBrandAggregation(paramMap));  
69 - // 4)人群  
70 - aggregations.add(aggregationFactory.getAgeLevelAggregation());  
71 - // 5)品类  
72 - aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));  
73 - // 6)性别  
74 - aggregations.add(aggregationFactory.getGenderNewAggregation());  
75 - // 7)价格  
76 - aggregations.add(aggregationFactory.getPriceAggregation());  
77 - // 8)折扣  
78 - aggregations.add(aggregationFactory.getDiscountAggregation());  
79 - // 9)颜色  
80 - aggregations.add(aggregationFactory.getColorAggregation(paramMap));  
81 - // 10)尺码  
82 - aggregations.add(aggregationFactory.getSizeAggregation());  
83 - // 11)风格  
84 - aggregations.add(aggregationFactory.getStyleAggregation(paramMap));  
85 - return aggregations;  
86 - }  
87 -  
88 - /**  
89 - * @断码区的聚合选项:  
90 - * @比其他的场景少了品类和尺码的筛选项  
91 - */  
92 - public List<IAggregation> getBreakSizeAggregations(Map<String, String> paramMap) {  
93 - List<IAggregation> aggregations = new ArrayList<>();  
94 - // 1)专区名称  
95 - aggregations.add(aggregationFactory.getZqNameAggregation(1000));  
96 - // 2)全球购  
97 - aggregations.add(aggregationFactory.getIsGlobalAggregation());  
98 - // 3)品牌  
99 - aggregations.add(aggregationFactory.getBrandAggregation(paramMap));  
100 - // 4)人群  
101 - aggregations.add(aggregationFactory.getAgeLevelAggregation());  
102 - // 5)性别  
103 - aggregations.add(aggregationFactory.getGenderNewAggregation());  
104 - // 6)价格  
105 - aggregations.add(aggregationFactory.getPriceAggregation());  
106 - // 7)折扣  
107 - aggregations.add(aggregationFactory.getDiscountAggregation());  
108 - // 8)颜色  
109 - aggregations.add(aggregationFactory.getColorAggregation(paramMap));  
110 - // 9)风格  
111 - aggregations.add(aggregationFactory.getStyleAggregation(paramMap));  
112 - return aggregations;  
113 - }  
114 -  
115 - /**  
116 - * 最新降价的筛选项  
117 - *  
118 - * @param paramMap  
119 - * @return  
120 - */  
121 - public List<IAggregation> getReducePriceAggregations(Map<String, String> paramMap) {  
122 - List<IAggregation> aggregations = new ArrayList<>();  
123 - // 1)性别  
124 - aggregations.add(aggregationFactory.getGenderNewAggregation());  
125 - // 2)品牌  
126 - aggregations.add(aggregationFactory.getBrandAggregation(paramMap));  
127 - // 3)品类  
128 - aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));  
129 - // 4)颜色  
130 - aggregations.add(aggregationFactory.getColorAggregation(paramMap));  
131 - // 5)尺码  
132 - aggregations.add(aggregationFactory.getSizeAggregation());  
133 - // 6)价格  
134 - aggregations.add(aggregationFactory.getPriceAggregation());  
135 - // 7)折扣  
136 - aggregations.add(aggregationFactory.getDiscountAggregation());  
137 - // 8)风格  
138 - aggregations.add(aggregationFactory.getStyleAggregation(paramMap));  
139 - return aggregations;  
140 - }  
141 -  
142 - /**  
143 - * 老的店铺的筛选项  
144 - *  
145 - * @param paramMap  
146 - * @return  
147 - */  
148 - public List<IAggregation> getShopOldAggregations(Map<String, String> paramMap) {  
149 - List<IAggregation> aggregations = new ArrayList<>();  
150 - // 1)性别  
151 - aggregations.add(aggregationFactory.getGenderNewAggregation());  
152 - // 2)品牌  
153 - aggregations.add(aggregationFactory.getBrandAggregation(paramMap));  
154 - // 3)品类  
155 - aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));  
156 - // 4)颜色  
157 - aggregations.add(aggregationFactory.getColorAggregation(paramMap));  
158 - // 5)尺码  
159 - aggregations.add(aggregationFactory.getSizeAggregation());  
160 - // 6)价格  
161 - aggregations.add(aggregationFactory.getPriceAggregation());  
162 - // 7)折扣  
163 - aggregations.add(aggregationFactory.getDiscountAggregation());  
164 - // 8)风格  
165 - aggregations.add(aggregationFactory.getStyleAggregation(paramMap));  
166 - return aggregations;  
167 - }  
168 -  
169 - /**  
170 - * 老的新品到着的筛选项  
171 - *  
172 - * @param paramMap  
173 - * @return  
174 - */  
175 - public List<IAggregation> getNewArrivalOldAggregations(Map<String, String> paramMap) {  
176 - List<IAggregation> aggregations = new ArrayList<>();  
177 - // 1)性别  
178 - aggregations.add(aggregationFactory.getGenderNewAggregation());  
179 - // 2)品牌  
180 - aggregations.add(aggregationFactory.getBrandAggregation(paramMap));  
181 - // 3)品类  
182 - aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));  
183 - // 4)颜色  
184 - aggregations.add(aggregationFactory.getColorAggregation(paramMap));  
185 - // 5)尺码  
186 - aggregations.add(aggregationFactory.getSizeAggregation());  
187 - // 6)价格  
188 - aggregations.add(aggregationFactory.getPriceAggregation());  
189 - // 7)折扣  
190 - aggregations.add(aggregationFactory.getDiscountAggregation());  
191 - // 8)风格  
192 - aggregations.add(aggregationFactory.getStyleAggregation(paramMap));  
193 - return aggregations;  
194 - }  
195 -  
196 - private List<AbstractAggregationBuilder<?>> getAggregationBuilders(List<IAggregation> aggregations) {  
197 - List<AbstractAggregationBuilder<?>> builders = new ArrayList<>();  
198 - for (IAggregation aggregation : aggregations) {  
199 - builders.add(aggregation.getBuilder());  
200 - }  
201 - return builders;  
202 - }  
203 -  
204 - private JSONObject genFilterResult(List<IAggregation> aggregations, Map<String, Aggregation> aggMaps) {  
205 - JSONObject filter = new JSONObject();  
206 - for (IAggregation aggregation : aggregations) {  
207 - Object response = aggregation.getAggregationResponseMap(aggMaps);  
208 - if (response == null) {  
209 - continue;  
210 - }  
211 - filter.put(aggregation.filterName(), response);  
212 - }  
213 - return filter;  
214 - }  
215 -  
216 - private JSONObject getFiltersResults(Map<String, String> paramMap, SearchParam searchParam, List<IAggregation> aggregations) {  
217 - try {  
218 - // 1)构造聚合报文  
219 - searchParam.setAggregationBuilders(this.getAggregationBuilders(aggregations));  
220 - // 2)构造其他参数  
221 - final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;  
222 - searchParam.setOffset(100);// just for cache  
223 - searchParam.setSize(0);  
224 -  
225 - // 先从缓存里取,取到则处理下缓存结果并直接返回  
226 - JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(this.searchCache, productIndexName, searchParam);  
227 - if (cacheObject != null) {  
228 - SearchCacheMatchLogger.doSearchCacheMatchLog("/scene/aggregations.json", paramMap);  
229 - return cacheObject;  
230 - }  
231 -  
232 - // 调用ES  
233 - SearchResult searchResult = searchCommonService.doSearch(productIndexName, searchParam);  
234 - Map<String, Aggregation> aggMaps = searchResult.getAggMaps();  
235 - if (aggMaps == null) {  
236 - return null;  
237 - }  
238 - // 构造返回结果  
239 - JSONObject dataMap = this.genFilterResult(aggregations, aggMaps);  
240 - searchCacheService.addJSONObjectToCache(this.searchCache, productIndexName, searchParam, dataMap);  
241 - return dataMap;  
242 - } catch (Exception e) {  
243 - logger.error("[func=getFiltersResults][params=" + paramMap + "]", e);  
244 - return new JSONObject();  
245 - }  
246 - }  
247 -  
248 - private JSONObject getFiltersResult(Map<String, String> paramMap, List<IAggregation> aggregations, BoolQueryBuilder mustFilter) {  
249 - try {  
250 - Map<String, String> newParamMap = new HashMap<String, String>(paramMap);  
251 - SearchParam searchParam = searchParamHelper.buildWithMustFilter(newParamMap, mustFilter);  
252 - return this.getFiltersResults(paramMap, searchParam, aggregations);  
253 - } catch (Exception e) {  
254 - logger.error("[func=SceneSelectionsService][params=" + paramMap + "]", e);  
255 - return new JSONObject();  
256 - }  
257 - }  
258 -  
259 - public SearchApiResult aggregations(Map<String, String> paramMap) throws Exception {  
260 - List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap);  
261 - return this.aggregations(paramMap, commonAggregations, null);  
262 - }  
263 -  
264 - public SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations) throws Exception {  
265 - return this.aggregations(paramMap, aggregations, null);  
266 - }  
267 -  
268 - public SearchApiResult aggregations(Map<String, String> paramMap, BoolQueryBuilder mustFilter) throws Exception {  
269 - List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap);  
270 - return this.aggregations(paramMap, commonAggregations, mustFilter);  
271 - }  
272 -  
273 - private SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations, BoolQueryBuilder mustFilter) throws Exception {  
274 - // 1、获取通用筛选项  
275 - JSONObject commonFilters = this.getFiltersResult(paramMap, aggregations, mustFilter);  
276 - Map<String, Object> result = new JSONObject();  
277 - result.put("filter", commonFilters);  
278 - return new SearchApiResult().setData(result);  
279 - }  
280 -  
281 -} 1 +package com.yoho.search.service.scene.aggregations;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.yoho.search.base.utils.ISearchConstants;
  5 +import com.yoho.search.cache.log.SearchCacheMatchLogger;
  6 +import com.yoho.search.cache.model.SearchCache;
  7 +import com.yoho.search.cache.beans.AbstractCacheAbleService;
  8 +import com.yoho.search.core.es.agg.IAggregation;
  9 +import com.yoho.search.core.es.model.SearchParam;
  10 +import com.yoho.search.core.es.model.SearchResult;
  11 +import com.yoho.search.models.SearchApiResult;
  12 +import com.yoho.search.service.scene.aggregations.impls.AggregationFactory;
  13 +import com.yoho.search.common.SearchCommonService;
  14 +import com.yoho.search.service.helper.SearchParamHelper;
  15 +import org.elasticsearch.index.query.BoolQueryBuilder;
  16 +import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
  17 +import org.elasticsearch.search.aggregations.Aggregation;
  18 +import org.slf4j.Logger;
  19 +import org.slf4j.LoggerFactory;
  20 +import org.springframework.beans.factory.annotation.Autowired;
  21 +import org.springframework.stereotype.Service;
  22 +
  23 +import java.util.ArrayList;
  24 +import java.util.HashMap;
  25 +import java.util.List;
  26 +import java.util.Map;
  27 +
  28 +
  29 +@Service
  30 +public class SceneSelectionsService extends AbstractCacheAbleService {
  31 +
  32 + private static final Logger logger = LoggerFactory.getLogger(SceneSelectionsService.class);
  33 +
  34 + @Autowired
  35 + private SearchParamHelper searchParamHelper;
  36 + @Autowired
  37 + private SearchCommonService searchCommonService;
  38 + @Autowired
  39 + private AggregationFactory aggregationFactory;
  40 +
  41 + @Override
  42 + public SearchCache getSearchCache() {
  43 + return searchCacheFactory.getSceneAggregationsCache();
  44 + }
  45 +
  46 + /**
  47 + * @新版筛选器的聚合选项:
  48 + * @1、全球购
  49 + * @2、促销
  50 + * @3、全部的品牌 +喜欢的品牌【个性化的】
  51 + * @4、人群
  52 + * @5、品类
  53 + * @6、性别
  54 + * @7、价格
  55 + * @8、折扣
  56 + * @9、颜色
  57 + * @10、尺码
  58 + * @11、风格
  59 + */
  60 +
  61 + public List<IAggregation> getCommonAggregations(Map<String, String> paramMap) {
  62 + List<IAggregation> aggregations = new ArrayList<>();
  63 + // 1)专区名称
  64 + aggregations.add(aggregationFactory.getZqNameAggregation(1000));
  65 + // 2)全球购
  66 + aggregations.add(aggregationFactory.getIsGlobalAggregation());
  67 + // 3)品牌
  68 + aggregations.add(aggregationFactory.getBrandAggregation(paramMap));
  69 + // 4)人群
  70 + aggregations.add(aggregationFactory.getAgeLevelAggregation());
  71 + // 5)品类
  72 + aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));
  73 + // 6)性别
  74 + aggregations.add(aggregationFactory.getGenderNewAggregation());
  75 + // 7)价格
  76 + aggregations.add(aggregationFactory.getPriceAggregation());
  77 + // 8)折扣
  78 + aggregations.add(aggregationFactory.getDiscountAggregation());
  79 + // 9)颜色
  80 + aggregations.add(aggregationFactory.getColorAggregation(paramMap));
  81 + // 10)尺码
  82 + aggregations.add(aggregationFactory.getSizeAggregation());
  83 + // 11)风格
  84 + aggregations.add(aggregationFactory.getStyleAggregation(paramMap));
  85 + return aggregations;
  86 + }
  87 +
  88 + /**
  89 + * @断码区的聚合选项:
  90 + * @比其他的场景少了品类和尺码的筛选项
  91 + */
  92 + public List<IAggregation> getBreakSizeAggregations(Map<String, String> paramMap) {
  93 + List<IAggregation> aggregations = new ArrayList<>();
  94 + // 1)专区名称
  95 + aggregations.add(aggregationFactory.getZqNameAggregation(1000));
  96 + // 2)全球购
  97 + aggregations.add(aggregationFactory.getIsGlobalAggregation());
  98 + // 3)品牌
  99 + aggregations.add(aggregationFactory.getBrandAggregation(paramMap));
  100 + // 4)人群
  101 + aggregations.add(aggregationFactory.getAgeLevelAggregation());
  102 + // 5)性别
  103 + aggregations.add(aggregationFactory.getGenderNewAggregation());
  104 + // 6)价格
  105 + aggregations.add(aggregationFactory.getPriceAggregation());
  106 + // 7)折扣
  107 + aggregations.add(aggregationFactory.getDiscountAggregation());
  108 + // 8)颜色
  109 + aggregations.add(aggregationFactory.getColorAggregation(paramMap));
  110 + // 9)风格
  111 + aggregations.add(aggregationFactory.getStyleAggregation(paramMap));
  112 + return aggregations;
  113 + }
  114 +
  115 + /**
  116 + * 最新降价的筛选项
  117 + *
  118 + * @param paramMap
  119 + * @return
  120 + */
  121 + public List<IAggregation> getReducePriceAggregations(Map<String, String> paramMap) {
  122 + List<IAggregation> aggregations = new ArrayList<>();
  123 + // 1)性别
  124 + aggregations.add(aggregationFactory.getGenderNewAggregation());
  125 + // 2)品牌
  126 + aggregations.add(aggregationFactory.getBrandAggregation(paramMap));
  127 + // 3)品类
  128 + aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));
  129 + // 4)颜色
  130 + aggregations.add(aggregationFactory.getColorAggregation(paramMap));
  131 + // 5)尺码
  132 + aggregations.add(aggregationFactory.getSizeAggregation());
  133 + // 6)价格
  134 + aggregations.add(aggregationFactory.getPriceAggregation());
  135 + // 7)折扣
  136 + aggregations.add(aggregationFactory.getDiscountAggregation());
  137 + // 8)风格
  138 + aggregations.add(aggregationFactory.getStyleAggregation(paramMap));
  139 + return aggregations;
  140 + }
  141 +
  142 + /**
  143 + * 老的店铺的筛选项
  144 + *
  145 + * @param paramMap
  146 + * @return
  147 + */
  148 + public List<IAggregation> getShopOldAggregations(Map<String, String> paramMap) {
  149 + List<IAggregation> aggregations = new ArrayList<>();
  150 + // 1)性别
  151 + aggregations.add(aggregationFactory.getGenderNewAggregation());
  152 + // 2)品牌
  153 + aggregations.add(aggregationFactory.getBrandAggregation(paramMap));
  154 + // 3)品类
  155 + aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));
  156 + // 4)颜色
  157 + aggregations.add(aggregationFactory.getColorAggregation(paramMap));
  158 + // 5)尺码
  159 + aggregations.add(aggregationFactory.getSizeAggregation());
  160 + // 6)价格
  161 + aggregations.add(aggregationFactory.getPriceAggregation());
  162 + // 7)折扣
  163 + aggregations.add(aggregationFactory.getDiscountAggregation());
  164 + // 8)风格
  165 + aggregations.add(aggregationFactory.getStyleAggregation(paramMap));
  166 + return aggregations;
  167 + }
  168 +
  169 + /**
  170 + * 老的新品到着的筛选项
  171 + *
  172 + * @param paramMap
  173 + * @return
  174 + */
  175 + public List<IAggregation> getNewArrivalOldAggregations(Map<String, String> paramMap) {
  176 + List<IAggregation> aggregations = new ArrayList<>();
  177 + // 1)性别
  178 + aggregations.add(aggregationFactory.getGenderNewAggregation());
  179 + // 2)品牌
  180 + aggregations.add(aggregationFactory.getBrandAggregation(paramMap));
  181 + // 3)品类
  182 + aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));
  183 + // 4)颜色
  184 + aggregations.add(aggregationFactory.getColorAggregation(paramMap));
  185 + // 5)尺码
  186 + aggregations.add(aggregationFactory.getSizeAggregation());
  187 + // 6)价格
  188 + aggregations.add(aggregationFactory.getPriceAggregation());
  189 + // 7)折扣
  190 + aggregations.add(aggregationFactory.getDiscountAggregation());
  191 + // 8)风格
  192 + aggregations.add(aggregationFactory.getStyleAggregation(paramMap));
  193 + return aggregations;
  194 + }
  195 +
  196 + private List<AbstractAggregationBuilder<?>> getAggregationBuilders(List<IAggregation> aggregations) {
  197 + List<AbstractAggregationBuilder<?>> builders = new ArrayList<>();
  198 + for (IAggregation aggregation : aggregations) {
  199 + builders.add(aggregation.getBuilder());
  200 + }
  201 + return builders;
  202 + }
  203 +
  204 + private JSONObject genFilterResult(List<IAggregation> aggregations, Map<String, Aggregation> aggMaps) {
  205 + JSONObject filter = new JSONObject();
  206 + for (IAggregation aggregation : aggregations) {
  207 + Object response = aggregation.getAggregationResponseMap(aggMaps);
  208 + if (response == null) {
  209 + continue;
  210 + }
  211 + filter.put(aggregation.filterName(), response);
  212 + }
  213 + return filter;
  214 + }
  215 +
  216 + private JSONObject getFiltersResults(Map<String, String> paramMap, SearchParam searchParam, List<IAggregation> aggregations) {
  217 + try {
  218 + // 1)构造聚合报文
  219 + searchParam.setAggregationBuilders(this.getAggregationBuilders(aggregations));
  220 + // 2)构造其他参数
  221 + final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
  222 + searchParam.setOffset(100);// just for cache
  223 + searchParam.setSize(0);
  224 +
  225 + // 先从缓存里取,取到则处理下缓存结果并直接返回
  226 + JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(this.searchCache, productIndexName, searchParam);
  227 + if (cacheObject != null) {
  228 + SearchCacheMatchLogger.doSearchCacheMatchLog("/scene/aggregations.json", paramMap);
  229 + return cacheObject;
  230 + }
  231 +
  232 + // 调用ES
  233 + SearchResult searchResult = searchCommonService.doSearch(productIndexName, searchParam);
  234 + Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
  235 + if (aggMaps == null) {
  236 + return null;
  237 + }
  238 + // 构造返回结果
  239 + JSONObject dataMap = this.genFilterResult(aggregations, aggMaps);
  240 + searchCacheService.addJSONObjectToCache(this.searchCache, productIndexName, searchParam, dataMap);
  241 + return dataMap;
  242 + } catch (Exception e) {
  243 + logger.error("[func=getFiltersResults][params=" + paramMap + "]", e);
  244 + return new JSONObject();
  245 + }
  246 + }
  247 +
  248 + private JSONObject getFiltersResult(Map<String, String> paramMap, List<IAggregation> aggregations, BoolQueryBuilder mustFilter) {
  249 + try {
  250 + Map<String, String> newParamMap = new HashMap<String, String>(paramMap);
  251 + SearchParam searchParam = searchParamHelper.buildWithMustFilter(newParamMap, mustFilter);
  252 + return this.getFiltersResults(paramMap, searchParam, aggregations);
  253 + } catch (Exception e) {
  254 + logger.error("[func=SceneSelectionsService][params=" + paramMap + "]", e);
  255 + return new JSONObject();
  256 + }
  257 + }
  258 +
  259 + public SearchApiResult aggregations(Map<String, String> paramMap) throws Exception {
  260 + List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap);
  261 + return this.aggregations(paramMap, commonAggregations, null);
  262 + }
  263 +
  264 + public SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations) throws Exception {
  265 + return this.aggregations(paramMap, aggregations, null);
  266 + }
  267 +
  268 + public SearchApiResult aggregations(Map<String, String> paramMap, BoolQueryBuilder mustFilter) throws Exception {
  269 + List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap);
  270 + return this.aggregations(paramMap, commonAggregations, mustFilter);
  271 + }
  272 +
  273 + private SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations, BoolQueryBuilder mustFilter) throws Exception {
  274 + // 1、获取通用筛选项
  275 + JSONObject commonFilters = this.getFiltersResult(paramMap, aggregations, mustFilter);
  276 + Map<String, Object> result = new JSONObject();
  277 + result.put("filter", commonFilters);
  278 + return new SearchApiResult().setData(result);
  279 + }
  280 +
  281 +}
1 -package com.yoho.search.service.scene.common;  
2 -  
3 -import com.alibaba.fastjson.JSON;  
4 -import com.alibaba.fastjson.JSONArray;  
5 -import com.alibaba.fastjson.JSONObject;  
6 -import com.alibaba.fastjson.TypeReference;  
7 -import com.yoho.search.core.personalized.models.SortBrand;  
8 -import com.yoho.search.core.personalized.models.UserPersonalFactorRspNew;  
9 -import com.yoho.search.models.SearchApiResult;  
10 -import com.yoho.search.common.SearchRequestParams;  
11 -import org.apache.commons.collections.MapUtils;  
12 -import org.springframework.beans.factory.annotation.Autowired;  
13 -import com.yoho.search.service.recall.beans.persional.UserPersionalFactorComponent;  
14 -import org.springframework.stereotype.Service;  
15 -import org.springframework.util.CollectionUtils;  
16 -  
17 -import java.util.*;  
18 -import java.util.function.Function;  
19 -import java.util.stream.Collectors;  
20 -  
21 -@Service  
22 -public class SceneRecommendBrandsService {  
23 -  
24 - @Autowired  
25 - private UserPersionalFactorComponent userPersionalFactorComponent;  
26 -  
27 - public void getRecommendBrands(Map<String, String> paramMap, SearchApiResult result) {  
28 - if (result != null && result.getData() != null) {  
29 - JSONObject data = (JSONObject) result.getData();  
30 - JSONObject commonFilters = data.getJSONObject("filter");  
31 - if (commonFilters != null) {  
32 - queryRecommendBrandsNew(commonFilters, paramMap);  
33 - }  
34 - }  
35 - }  
36 -  
37 - private void queryRecommendBrandsNew(JSONObject commonFilters, Map<String, String> paramMap) {  
38 - JSONArray recommendBrands = new JSONArray();  
39 - JSONArray brandList = commonFilters.getJSONArray("brand");  
40 - if (!CollectionUtils.isEmpty(brandList)) {  
41 - recommendBrands = queryRecommendBrands(paramMap, brandList);  
42 - }  
43 - commonFilters.put("recommendBrand", recommendBrands);  
44 - }  
45 -  
46 - private JSONArray queryRecommendBrands(Map<String, String> paramMap, JSONArray brandList) {  
47 - List<JSONObject> brandListTemp = JSON.parseObject(brandList.toJSONString(), new TypeReference<List<JSONObject>>() {  
48 - });  
49 - Map<Integer, JSONObject> brandIdMap = brandListTemp.stream().collect(Collectors.toMap(e -> e.getInteger("id"), Function.identity(), (m1, m2) -> m2));  
50 - int uid = MapUtils.getIntValue(paramMap, "uid", 0);  
51 - String udid = MapUtils.getString(paramMap, "udid", "");  
52 - int recommendBrandCount = Integer.parseInt(paramMap.getOrDefault(SearchRequestParams.PARAM_SEARCH_VIEWNUM, "8"));  
53 - JSONArray recBrands = new JSONArray(recommendBrandCount);  
54 - UserPersonalFactorRspNew userFactor = userPersionalFactorComponent.queryUserPersionalFactor(uid, udid, null);  
55 - List<Integer> brandIds = new ArrayList<>();  
56 - if (userFactor != null && userFactor.getRealTimeSortBrandList()!=null) {  
57 - List<SortBrand> sortBrandList = new ArrayList<>(userFactor.getRealTimeSortBrandList());  
58 - for (SortBrand sortBrand : sortBrandList) {  
59 - if (recBrands.size() >= recommendBrandCount) {  
60 - break;  
61 - }  
62 - if (brandIds.contains(sortBrand.getBrandId())) {  
63 - continue;  
64 - }  
65 - JSONObject brand = brandIdMap.get(sortBrand.getBrandId());  
66 - if (brand != null) {  
67 - recBrands.add(brand);  
68 - brandIds.add(sortBrand.getBrandId());  
69 - }  
70 - }  
71 - }  
72 - if (recBrands.size() < recommendBrandCount) {  
73 - for (JSONObject brand : brandListTemp) {  
74 - if (recBrands.size() >= recommendBrandCount) {  
75 - break;  
76 - }  
77 - if (!brandIds.contains(brand.getInteger("id"))) {  
78 - recBrands.add(brand);  
79 - brandIds.add(brand.getInteger("id"));  
80 - }  
81 - }  
82 - }  
83 - return recBrands;  
84 - }  
85 -  
86 -} 1 +package com.yoho.search.service.scene.brandshop;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONArray;
  5 +import com.alibaba.fastjson.JSONObject;
  6 +import com.alibaba.fastjson.TypeReference;
  7 +import com.yoho.search.core.personalized.models.SortBrand;
  8 +import com.yoho.search.core.personalized.models.UserPersonalFactorRspNew;
  9 +import com.yoho.search.models.SearchApiResult;
  10 +import com.yoho.search.common.SearchRequestParams;
  11 +import org.apache.commons.collections.MapUtils;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import com.yoho.search.service.recall.beans.persional.UserPersionalFactorComponent;
  14 +import org.springframework.stereotype.Service;
  15 +import org.springframework.util.CollectionUtils;
  16 +
  17 +import java.util.*;
  18 +import java.util.function.Function;
  19 +import java.util.stream.Collectors;
  20 +
  21 +@Service
  22 +public class RecommendBrandsService {
  23 +
  24 + @Autowired
  25 + private UserPersionalFactorComponent userPersionalFactorComponent;
  26 +
  27 + public void getRecommendBrands(Map<String, String> paramMap, SearchApiResult result) {
  28 + if (result != null && result.getData() != null) {
  29 + JSONObject data = (JSONObject) result.getData();
  30 + JSONObject commonFilters = data.getJSONObject("filter");
  31 + if (commonFilters != null) {
  32 + queryRecommendBrandsNew(commonFilters, paramMap);
  33 + }
  34 + }
  35 + }
  36 +
  37 + private void queryRecommendBrandsNew(JSONObject commonFilters, Map<String, String> paramMap) {
  38 + JSONArray recommendBrands = new JSONArray();
  39 + JSONArray brandList = commonFilters.getJSONArray("brand");
  40 + if (!CollectionUtils.isEmpty(brandList)) {
  41 + recommendBrands = queryRecommendBrands(paramMap, brandList);
  42 + }
  43 + commonFilters.put("recommendBrand", recommendBrands);
  44 + }
  45 +
  46 + private JSONArray queryRecommendBrands(Map<String, String> paramMap, JSONArray brandList) {
  47 + List<JSONObject> brandListTemp = JSON.parseObject(brandList.toJSONString(), new TypeReference<List<JSONObject>>() {
  48 + });
  49 + Map<Integer, JSONObject> brandIdMap = brandListTemp.stream().collect(Collectors.toMap(e -> e.getInteger("id"), Function.identity(), (m1, m2) -> m2));
  50 + int uid = MapUtils.getIntValue(paramMap, "uid", 0);
  51 + String udid = MapUtils.getString(paramMap, "udid", "");
  52 + int recommendBrandCount = Integer.parseInt(paramMap.getOrDefault(SearchRequestParams.PARAM_SEARCH_VIEWNUM, "8"));
  53 + JSONArray recBrands = new JSONArray(recommendBrandCount);
  54 + UserPersonalFactorRspNew userFactor = userPersionalFactorComponent.queryUserPersionalFactor(uid, udid, null);
  55 + List<Integer> brandIds = new ArrayList<>();
  56 + if (userFactor != null && userFactor.getRealTimeSortBrandList()!=null) {
  57 + List<SortBrand> sortBrandList = new ArrayList<>(userFactor.getRealTimeSortBrandList());
  58 + for (SortBrand sortBrand : sortBrandList) {
  59 + if (recBrands.size() >= recommendBrandCount) {
  60 + break;
  61 + }
  62 + if (brandIds.contains(sortBrand.getBrandId())) {
  63 + continue;
  64 + }
  65 + JSONObject brand = brandIdMap.get(sortBrand.getBrandId());
  66 + if (brand != null) {
  67 + recBrands.add(brand);
  68 + brandIds.add(sortBrand.getBrandId());
  69 + }
  70 + }
  71 + }
  72 + if (recBrands.size() < recommendBrandCount) {
  73 + for (JSONObject brand : brandListTemp) {
  74 + if (recBrands.size() >= recommendBrandCount) {
  75 + break;
  76 + }
  77 + if (!brandIds.contains(brand.getInteger("id"))) {
  78 + recBrands.add(brand);
  79 + brandIds.add(brand.getInteger("id"));
  80 + }
  81 + }
  82 + }
  83 + return recBrands;
  84 + }
  85 +
  86 +}
@@ -11,8 +11,8 @@ import com.yoho.search.service.helper.SearchKeyWordHelper; @@ -11,8 +11,8 @@ import com.yoho.search.service.helper.SearchKeyWordHelper;
11 import com.yoho.search.service.scene.list.ProductListSwitchService; 11 import com.yoho.search.service.scene.list.ProductListSwitchService;
12 import com.yoho.search.service.scene.aggregations.SceneAggregationsHelper; 12 import com.yoho.search.service.scene.aggregations.SceneAggregationsHelper;
13 import com.yoho.search.service.scene.common.AbstractSceneService; 13 import com.yoho.search.service.scene.common.AbstractSceneService;
14 -import com.yoho.search.service.scene.common.SceneRecommendBrandsService;  
15 -import com.yoho.search.service.scene.common.SceneSelectionsService; 14 +import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
  15 +import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
16 import org.apache.commons.lang.StringUtils; 16 import org.apache.commons.lang.StringUtils;
17 import org.slf4j.Logger; 17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory; 18 import org.slf4j.LoggerFactory;
@@ -42,7 +42,7 @@ public class FuzzySceneService extends AbstractSceneService { @@ -42,7 +42,7 @@ public class FuzzySceneService extends AbstractSceneService {
42 @Autowired 42 @Autowired
43 private SceneAggregationsHelper sceneAggregationsHelper; 43 private SceneAggregationsHelper sceneAggregationsHelper;
44 @Autowired 44 @Autowired
45 - private SceneRecommendBrandsService sceneRecommendBrandsService; 45 + private RecommendBrandsService recommendBrandsService;
46 @Autowired 46 @Autowired
47 private ProductListSwitchService productListSwitchService; 47 private ProductListSwitchService productListSwitchService;
48 48
@@ -118,7 +118,7 @@ public class FuzzySceneService extends AbstractSceneService { @@ -118,7 +118,7 @@ public class FuzzySceneService extends AbstractSceneService {
118 this.addParamsToParamMap(paramMap); 118 this.addParamsToParamMap(paramMap);
119 // 2、返回聚合结果 119 // 2、返回聚合结果
120 SearchApiResult result = sceneSelectionsService.aggregations(paramMap); 120 SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
121 - sceneRecommendBrandsService.getRecommendBrands(paramMap, result); 121 + recommendBrandsService.getRecommendBrands(paramMap, result);
122 return result; 122 return result;
123 } catch (Exception e) { 123 } catch (Exception e) {
124 logger.error(e.getMessage(), e); 124 logger.error(e.getMessage(), e);
1 package com.yoho.search.service.scene.guang; 1 package com.yoho.search.service.scene.guang;
2 2
3 -import com.alibaba.fastjson.JSON;  
4 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
5 import com.yoho.search.aop.cache.SearchCacheAble; 4 import com.yoho.search.aop.cache.SearchCacheAble;
6 import com.yoho.search.base.utils.ISearchConstants; 5 import com.yoho.search.base.utils.ISearchConstants;
  6 +import com.yoho.search.common.SearchCommonService;
7 import com.yoho.search.common.utils.SearchApiResultUtils; 7 import com.yoho.search.common.utils.SearchApiResultUtils;
8 import com.yoho.search.core.es.model.SearchParam; 8 import com.yoho.search.core.es.model.SearchParam;
9 import com.yoho.search.core.es.model.SearchResult; 9 import com.yoho.search.core.es.model.SearchResult;
10 -import com.yoho.search.core.es.utils.SearchParamUtils;  
11 import com.yoho.search.models.SearchApiResult; 10 import com.yoho.search.models.SearchApiResult;
12 -import com.yoho.search.service.recall.beans.strategy.NotRecallTypeEnum;  
13 -import com.yoho.search.common.SearchCommonService;  
14 import com.yoho.search.service.helper.ProductListHelper; 11 import com.yoho.search.service.helper.ProductListHelper;
15 -import org.elasticsearch.search.builder.SearchSourceBuilder; 12 +import com.yoho.search.service.recall.beans.strategy.NotRecallTypeEnum;
16 import org.slf4j.Logger; 13 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory; 14 import org.slf4j.LoggerFactory;
18 import org.springframework.beans.factory.annotation.Autowired; 15 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,30 +18,15 @@ import org.springframework.stereotype.Service; @@ -21,30 +18,15 @@ import org.springframework.stereotype.Service;
21 import java.util.Map; 18 import java.util.Map;
22 19
23 @Service 20 @Service
24 -public class ProductListService { 21 +public class ProductListWithPhraseService {
25 22
26 - private static final Logger logger = LoggerFactory.getLogger(ProductListService.class); 23 + private static final Logger logger = LoggerFactory.getLogger(ProductListWithPhraseService.class);
27 24
28 @Autowired 25 @Autowired
29 private SearchCommonService searchCommonService; 26 private SearchCommonService searchCommonService;
30 @Autowired 27 @Autowired
31 private ProductListHelper productListHelper; 28 private ProductListHelper productListHelper;
32 29
33 - public SearchApiResult getESDsl(Map<String, String> paramMap) {  
34 - logger.info("[func=getESDsl][param={}]", paramMap);  
35 - try {  
36 - SearchParam searchParam = productListHelper.buildProductListSearchParam(paramMap, true);  
37 - SearchSourceBuilder searchSourceBuilder = SearchParamUtils.genSearchSourceBuilderFromSearchParam(searchParam);  
38 - SearchApiResult searchApiResult = new SearchApiResult();  
39 - String results = searchSourceBuilder.toString();  
40 - searchApiResult.setData(JSON.parseObject(results));  
41 - logger.info("[func=getESDsl][dsl=\n{}]", searchApiResult.getData());  
42 - return searchApiResult;  
43 - } catch (Exception e) {  
44 - return SearchApiResultUtils.errorSearchApiResult("getESDsl", paramMap, e);  
45 - }  
46 - }  
47 -  
48 @SearchCacheAble(cacheInMinute = 10, cacheName = "PRODUCT_LIST_WITH_PHRASE") 30 @SearchCacheAble(cacheInMinute = 10, cacheName = "PRODUCT_LIST_WITH_PHRASE")
49 public SearchApiResult productListWithPhrase(Map<String, String> paramMap) { 31 public SearchApiResult productListWithPhrase(Map<String, String> paramMap) {
50 try { 32 try {
@@ -10,8 +10,8 @@ import com.yoho.search.service.helper.SearchKeyWordHelper; @@ -10,8 +10,8 @@ import com.yoho.search.service.helper.SearchKeyWordHelper;
10 import com.yoho.search.service.scene.list.ProductListSwitchService; 10 import com.yoho.search.service.scene.list.ProductListSwitchService;
11 import com.yoho.search.service.scene.fuzzy.FuzzySceneService; 11 import com.yoho.search.service.scene.fuzzy.FuzzySceneService;
12 import com.yoho.search.service.scene.common.AbstractSceneService; 12 import com.yoho.search.service.scene.common.AbstractSceneService;
13 -import com.yoho.search.service.scene.common.SceneRecommendBrandsService;  
14 -import com.yoho.search.service.scene.common.SceneSelectionsService; 13 +import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
  14 +import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
15 import org.apache.commons.lang.StringUtils; 15 import org.apache.commons.lang.StringUtils;
16 import org.slf4j.Logger; 16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory; 17 import org.slf4j.LoggerFactory;
@@ -34,7 +34,7 @@ public class MiniappFuzzySceneService extends AbstractSceneService { @@ -34,7 +34,7 @@ public class MiniappFuzzySceneService extends AbstractSceneService {
34 @Autowired 34 @Autowired
35 private SceneSelectionsService sceneSelectionsService; 35 private SceneSelectionsService sceneSelectionsService;
36 @Autowired 36 @Autowired
37 - private SceneRecommendBrandsService sceneRecommendBrandsService; 37 + private RecommendBrandsService recommendBrandsService;
38 @Autowired 38 @Autowired
39 private ProductListSwitchService productListSwitchService; 39 private ProductListSwitchService productListSwitchService;
40 40
@@ -96,7 +96,7 @@ public class MiniappFuzzySceneService extends AbstractSceneService { @@ -96,7 +96,7 @@ public class MiniappFuzzySceneService extends AbstractSceneService {
96 // 2、返回聚合结果 96 // 2、返回聚合结果
97 SearchApiResult result = sceneSelectionsService.aggregations(paramMap); 97 SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
98 if(result!=null){ 98 if(result!=null){
99 - sceneRecommendBrandsService.getRecommendBrands(paramMap, result); 99 + recommendBrandsService.getRecommendBrands(paramMap, result);
100 } 100 }
101 return result; 101 return result;
102 } catch (Exception e) { 102 } catch (Exception e) {
@@ -7,7 +7,7 @@ import java.util.Map; @@ -7,7 +7,7 @@ import java.util.Map;
7 import com.yoho.search.base.utils.CollectionUtils; 7 import com.yoho.search.base.utils.CollectionUtils;
8 import com.yoho.search.models.RecommendPromotionAggVO; 8 import com.yoho.search.models.RecommendPromotionAggVO;
9 import com.yoho.search.service.scene.aggregations.SceneAggregationsHelper; 9 import com.yoho.search.service.scene.aggregations.SceneAggregationsHelper;
10 -import com.yoho.search.service.scene.common.SceneRecommendBrandsService; 10 +import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
11 import org.elasticsearch.index.query.BoolQueryBuilder; 11 import org.elasticsearch.index.query.BoolQueryBuilder;
12 import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; 12 import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
13 import org.elasticsearch.search.aggregations.Aggregation; 13 import org.elasticsearch.search.aggregations.Aggregation;
@@ -31,7 +31,7 @@ import com.yoho.search.common.SearchCommonService; @@ -31,7 +31,7 @@ import com.yoho.search.common.SearchCommonService;
31 import com.yoho.search.service.helper.SearchAfterCacheHelper; 31 import com.yoho.search.service.helper.SearchAfterCacheHelper;
32 import com.yoho.search.service.helper.SearchParamHelper; 32 import com.yoho.search.service.helper.SearchParamHelper;
33 import com.yoho.search.cache.beans.AbstractCacheAbleService; 33 import com.yoho.search.cache.beans.AbstractCacheAbleService;
34 -import com.yoho.search.service.scene.common.SceneSelectionsService; 34 +import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
35 import com.yoho.search.service.scene.brandshop.BrandService; 35 import com.yoho.search.service.scene.brandshop.BrandService;
36 import com.yoho.search.service.scene.aggregations.DiscountService; 36 import com.yoho.search.service.scene.aggregations.DiscountService;
37 import com.yoho.search.service.scene.aggregations.SearchSortGroupService; 37 import com.yoho.search.service.scene.aggregations.SearchSortGroupService;
@@ -66,7 +66,7 @@ public class PromotionAggregationsService extends AbstractCacheAbleService { @@ -66,7 +66,7 @@ public class PromotionAggregationsService extends AbstractCacheAbleService {
66 @Autowired 66 @Autowired
67 private PromotionSceneHelper promotionSceneHelper; 67 private PromotionSceneHelper promotionSceneHelper;
68 @Autowired 68 @Autowired
69 - private SceneRecommendBrandsService sceneRecommendBrandsService; 69 + private RecommendBrandsService recommendBrandsService;
70 @Autowired 70 @Autowired
71 private SceneAggregationsHelper sceneAggregationsHelper; 71 private SceneAggregationsHelper sceneAggregationsHelper;
72 72
@@ -196,7 +196,7 @@ public class PromotionAggregationsService extends AbstractCacheAbleService { @@ -196,7 +196,7 @@ public class PromotionAggregationsService extends AbstractCacheAbleService {
196 // 0、解析promotion的限制条件 196 // 0、解析promotion的限制条件
197 BoolQueryBuilder mustFilter = promotionSceneHelper.getMustFilterByPromotion(promotionConditions); 197 BoolQueryBuilder mustFilter = promotionSceneHelper.getMustFilterByPromotion(promotionConditions);
198 SearchApiResult result = sceneSelectionsService.aggregations(paramMap, mustFilter); 198 SearchApiResult result = sceneSelectionsService.aggregations(paramMap, mustFilter);
199 - sceneRecommendBrandsService.getRecommendBrands(paramMap, result); 199 + recommendBrandsService.getRecommendBrands(paramMap, result);
200 return result; 200 return result;
201 } catch (Exception e) { 201 } catch (Exception e) {
202 logger.error(e.getMessage(), e); 202 logger.error(e.getMessage(), e);
  1 +package com.yoho.search.service.scene.tools;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.yoho.search.common.utils.SearchApiResultUtils;
  5 +import com.yoho.search.core.es.model.SearchParam;
  6 +import com.yoho.search.core.es.utils.SearchParamUtils;
  7 +import com.yoho.search.models.SearchApiResult;
  8 +import com.yoho.search.service.helper.ProductListHelper;
  9 +import org.elasticsearch.search.builder.SearchSourceBuilder;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.stereotype.Service;
  14 +
  15 +import java.util.Map;
  16 +
  17 +@Service
  18 +public class ProductListDslService {
  19 +
  20 + private static final Logger logger = LoggerFactory.getLogger(ProductListDslService.class);
  21 +
  22 + @Autowired
  23 + private ProductListHelper productListHelper;
  24 +
  25 + public SearchApiResult getESDsl(Map<String, String> paramMap) {
  26 + logger.info("[func=getESDsl][param={}]", paramMap);
  27 + try {
  28 + SearchParam searchParam = productListHelper.buildProductListSearchParam(paramMap, true);
  29 + SearchSourceBuilder searchSourceBuilder = SearchParamUtils.genSearchSourceBuilderFromSearchParam(searchParam);
  30 + SearchApiResult searchApiResult = new SearchApiResult();
  31 + String results = searchSourceBuilder.toString();
  32 + searchApiResult.setData(JSON.parseObject(results));
  33 + logger.info("[func=getESDsl][dsl=\n{}]", searchApiResult.getData());
  34 + return searchApiResult;
  35 + } catch (Exception e) {
  36 + return SearchApiResultUtils.errorSearchApiResult("getESDsl", paramMap, e);
  37 + }
  38 + }
  39 +
  40 +}