Showing
4 changed files
with
30 additions
and
60 deletions
@@ -19,7 +19,7 @@ import java.util.Map; | @@ -19,7 +19,7 @@ import java.util.Map; | ||
19 | * @version 2018/9/14 | 19 | * @version 2018/9/14 |
20 | */ | 20 | */ |
21 | @Controller | 21 | @Controller |
22 | -public class UfoProductListController { | 22 | +public class UfoController { |
23 | 23 | ||
24 | @Autowired | 24 | @Autowired |
25 | private UfoProductListService ufoProductListService; | 25 | private UfoProductListService ufoProductListService; |
@@ -56,11 +56,11 @@ public class UfoProductListController { | @@ -56,11 +56,11 @@ public class UfoProductListController { | ||
56 | return ufoProductListService.recommendList(paramMap); | 56 | return ufoProductListService.recommendList(paramMap); |
57 | } | 57 | } |
58 | 58 | ||
59 | - @RequestMapping(method = RequestMethod.GET, value = "/ufo/suggest") | 59 | + @RequestMapping(method = RequestMethod.GET, value = "/ufo/suggestList") |
60 | @ResponseBody | 60 | @ResponseBody |
61 | - public SearchApiResult suggest(HttpServletRequest request) { | 61 | + public SearchApiResult suggestList(HttpServletRequest request) { |
62 | Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); | 62 | Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); |
63 | - return ufoProductListService.suggest(paramMap); | 63 | + return ufoProductListService.suggestList(paramMap); |
64 | } | 64 | } |
65 | 65 | ||
66 | } | 66 | } |
@@ -2,8 +2,8 @@ package com.yoho.search.service.scene.shopbrand; | @@ -2,8 +2,8 @@ package com.yoho.search.service.scene.shopbrand; | ||
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONArray; | 3 | import com.alibaba.fastjson.JSONArray; |
4 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
5 | +import com.yoho.search.aop.cache.SearchCacheAble; | ||
5 | import com.yoho.search.base.utils.ISearchConstants; | 6 | import com.yoho.search.base.utils.ISearchConstants; |
6 | -import com.yoho.search.cache.beans.AbstractCacheComponent; | ||
7 | import com.yoho.search.common.SearchCommonService; | 7 | import com.yoho.search.common.SearchCommonService; |
8 | import com.yoho.search.common.SearchRequestParams; | 8 | import com.yoho.search.common.SearchRequestParams; |
9 | import com.yoho.search.common.utils.SearchApiResultUtils; | 9 | import com.yoho.search.common.utils.SearchApiResultUtils; |
@@ -30,7 +30,7 @@ import java.util.Map; | @@ -30,7 +30,7 @@ import java.util.Map; | ||
30 | * @version 2018/9/17 | 30 | * @version 2018/9/17 |
31 | */ | 31 | */ |
32 | @Service | 32 | @Service |
33 | -public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> { | 33 | +public class UfoAggBrandService { |
34 | private static final Logger logger = LoggerFactory.getLogger(UfoAggBrandService.class); | 34 | private static final Logger logger = LoggerFactory.getLogger(UfoAggBrandService.class); |
35 | 35 | ||
36 | @Autowired | 36 | @Autowired |
@@ -40,7 +40,7 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> { | @@ -40,7 +40,7 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> { | ||
40 | @Autowired | 40 | @Autowired |
41 | private SearchCommonService searchCommonService; | 41 | private SearchCommonService searchCommonService; |
42 | 42 | ||
43 | - | 43 | + @SearchCacheAble(cacheName = "UFO_BRAND_LIST", cacheInMinute = 10) |
44 | public SearchApiResult aggAllBrandList(Map<String, String> paramMap) { | 44 | public SearchApiResult aggAllBrandList(Map<String, String> paramMap) { |
45 | try { | 45 | try { |
46 | // 1、构造带filter和query的SearchParam | 46 | // 1、构造带filter和query的SearchParam |
@@ -57,7 +57,7 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> { | @@ -57,7 +57,7 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> { | ||
57 | searchParam.setAggregationBuilders(Arrays.asList(brandAggregation.getBuilder())); | 57 | searchParam.setAggregationBuilders(Arrays.asList(brandAggregation.getBuilder())); |
58 | 58 | ||
59 | // 3、调父类方法执行查询 | 59 | // 3、调父类方法执行查询 |
60 | - JSONArray brandJSONArray = super.queryWithCache(searchParam, brandAggregation); | 60 | + JSONArray brandJSONArray = doRealQuery(searchParam, brandAggregation); |
61 | JSONObject dataMap = new JSONObject(); | 61 | JSONObject dataMap = new JSONObject(); |
62 | dataMap.put("brand_list", brandJSONArray); | 62 | dataMap.put("brand_list", brandJSONArray); |
63 | return new SearchApiResult().setData(dataMap); | 63 | return new SearchApiResult().setData(dataMap); |
@@ -66,23 +66,12 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> { | @@ -66,23 +66,12 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> { | ||
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | - @Override | ||
70 | - protected String cacheSceneKey() { | ||
71 | - return "AGG_UFO_BRAND_LIST"; | ||
72 | - } | ||
73 | - | ||
74 | - @Override | ||
75 | - protected int cacheTimeInMinute() { | ||
76 | - return 0;//CacheTimeConstants.CACHE_30_MINUTE; | ||
77 | - } | ||
78 | - | ||
79 | - @Override | ||
80 | - protected JSONArray doRealQuery(SearchParam searchParam, @Nullable Object... params) throws Exception { | 69 | + private JSONArray doRealQuery(SearchParam searchParam, @Nullable Object... params) throws Exception { |
81 | // 1、从参数中获取IAggregation brandAggregation | 70 | // 1、从参数中获取IAggregation brandAggregation |
82 | IAggregation brandAggregation = (IAggregation) params[0]; | 71 | IAggregation brandAggregation = (IAggregation) params[0]; |
83 | 72 | ||
84 | // 2、从ES中获取 | 73 | // 2、从ES中获取 |
85 | - SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);//this.doSearchForAggregation(searchParam, AggregationServiceIndex); | 74 | + SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam); |
86 | Map<String, Aggregation> aggMaps = searchResult.getAggMaps(); | 75 | Map<String, Aggregation> aggMaps = searchResult.getAggMaps(); |
87 | JSONObject jsonObject = brandAggregation.getAggNameAndResponse(aggMaps); | 76 | JSONObject jsonObject = brandAggregation.getAggNameAndResponse(aggMaps); |
88 | 77 |
1 | package com.yoho.search.service.scene.ufo; | 1 | package com.yoho.search.service.scene.ufo; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | +import com.yoho.search.aop.cache.SearchCacheAble; | ||
4 | import com.yoho.search.base.utils.ISearchConstants; | 5 | import com.yoho.search.base.utils.ISearchConstants; |
5 | import com.yoho.search.common.SearchCommonService; | 6 | import com.yoho.search.common.SearchCommonService; |
6 | import com.yoho.search.core.es.model.SearchParam; | 7 | import com.yoho.search.core.es.model.SearchParam; |
@@ -39,6 +40,7 @@ public class UfoProductListService { | @@ -39,6 +40,7 @@ public class UfoProductListService { | ||
39 | private static final String RETURN_LIST_NAME = "product_list"; | 40 | private static final String RETURN_LIST_NAME = "product_list"; |
40 | private static final Integer RECOMMEND_LIMIT = 30; | 41 | private static final Integer RECOMMEND_LIMIT = 30; |
41 | 42 | ||
43 | + @SearchCacheAble(cacheName = "UFO_PRODUCT_LIST", cacheInMinute = 10) | ||
42 | public SearchApiResult productList(Map<String, String> paramMap) { | 44 | public SearchApiResult productList(Map<String, String> paramMap) { |
43 | try { | 45 | try { |
44 | // 1、参数校验 | 46 | // 1、参数校验 |
@@ -81,13 +83,14 @@ public class UfoProductListService { | @@ -81,13 +83,14 @@ public class UfoProductListService { | ||
81 | } | 83 | } |
82 | } | 84 | } |
83 | 85 | ||
86 | + @SearchCacheAble(cacheName = "UFO_RECOMMEND_LIST", cacheInMinute = 10) | ||
84 | public SearchApiResult recommendList(Map<String, String> paramMap) { | 87 | public SearchApiResult recommendList(Map<String, String> paramMap) { |
85 | String query = MapUtils.getString(paramMap, "query"); | 88 | String query = MapUtils.getString(paramMap, "query"); |
86 | Integer brandId = MapUtils.getInteger(paramMap, "brand"); | 89 | Integer brandId = MapUtils.getInteger(paramMap, "brand"); |
87 | Integer midSortId = MapUtils.getInteger(paramMap, "midSort"); | 90 | Integer midSortId = MapUtils.getInteger(paramMap, "midSort"); |
88 | Integer not_id = MapUtils.getInteger(paramMap, "not_id"); | 91 | Integer not_id = MapUtils.getInteger(paramMap, "not_id"); |
89 | - if (StringUtils.isBlank(query) || brandId == null || midSortId == null) { | ||
90 | - return new SearchApiResult().setCode(400).setMessage("参数不合法,query,brand,midSort必传"); | 92 | + if (StringUtils.isBlank(query) || brandId == null || midSortId == null || not_id == null) { |
93 | + return new SearchApiResult().setCode(400).setMessage("参数不合法,缺少必传参数"); | ||
91 | } | 94 | } |
92 | //第一次查询 | 95 | //第一次查询 |
93 | paramMap.put("viewNum", "1000"); | 96 | paramMap.put("viewNum", "1000"); |
@@ -146,7 +149,7 @@ public class UfoProductListService { | @@ -146,7 +149,7 @@ public class UfoProductListService { | ||
146 | } | 149 | } |
147 | } | 150 | } |
148 | 151 | ||
149 | - public SearchApiResult suggest(Map<String, String> paramMap) { | 152 | + public SearchApiResult suggestList(Map<String, String> paramMap) { |
150 | try { | 153 | try { |
151 | // 1、参数校验 | 154 | // 1、参数校验 |
152 | int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum")); | 155 | int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum")); |
@@ -2,8 +2,8 @@ package com.yoho.search.service.scene.ufo; | @@ -2,8 +2,8 @@ package com.yoho.search.service.scene.ufo; | ||
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONArray; | 3 | import com.alibaba.fastjson.JSONArray; |
4 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
5 | +import com.yoho.search.aop.cache.SearchCacheAble; | ||
5 | import com.yoho.search.base.utils.ISearchConstants; | 6 | import com.yoho.search.base.utils.ISearchConstants; |
6 | -import com.yoho.search.cache.beans.AbstractCacheComponent; | ||
7 | import com.yoho.search.common.SearchCommonService; | 7 | import com.yoho.search.common.SearchCommonService; |
8 | import com.yoho.search.common.utils.SearchApiResultUtils; | 8 | import com.yoho.search.common.utils.SearchApiResultUtils; |
9 | import com.yoho.search.core.es.agg.IAggregation; | 9 | import com.yoho.search.core.es.agg.IAggregation; |
@@ -32,7 +32,7 @@ import java.util.Map; | @@ -32,7 +32,7 @@ import java.util.Map; | ||
32 | * @version 2018/9/17 | 32 | * @version 2018/9/17 |
33 | */ | 33 | */ |
34 | @Service | 34 | @Service |
35 | -public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { | 35 | +public class UfoSelectionsService { |
36 | 36 | ||
37 | private static final Logger logger = LoggerFactory.getLogger(UfoSelectionsService.class); | 37 | private static final Logger logger = LoggerFactory.getLogger(UfoSelectionsService.class); |
38 | 38 | ||
@@ -43,15 +43,9 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { | @@ -43,15 +43,9 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { | ||
43 | @Autowired | 43 | @Autowired |
44 | private SearchCommonService searchCommonService; | 44 | private SearchCommonService searchCommonService; |
45 | 45 | ||
46 | + @SearchCacheAble(cacheName = "UFO_PRODUCT_LIST", cacheInMinute = 10) | ||
46 | public SearchApiResult getSelectionsForApp(Map<String, String> paramMap) { | 47 | public SearchApiResult getSelectionsForApp(Map<String, String> paramMap) { |
47 | try { | 48 | try { |
48 | - return this.getSelectionsForApp(paramMap, null); | ||
49 | - } catch (Exception e) { | ||
50 | - return SearchApiResultUtils.errorSearchApiResult(logger, paramMap, e); | ||
51 | - } | ||
52 | - } | ||
53 | - | ||
54 | - public SearchApiResult getSelectionsForApp(Map<String, String> paramMap, BoolQueryBuilder mustFilter) throws Exception { | ||
55 | // 1)构造searchParam | 49 | // 1)构造searchParam |
56 | SearchParam searchParam = new SearchParam(); | 50 | SearchParam searchParam = new SearchParam(); |
57 | BoolQueryBuilder boolFilter = ufoSearchQueryHelper.constructFilterBuilder(paramMap, null); | 51 | BoolQueryBuilder boolFilter = ufoSearchQueryHelper.constructFilterBuilder(paramMap, null); |
@@ -60,14 +54,15 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { | @@ -60,14 +54,15 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { | ||
60 | searchParam.setQuery(queryBuilder); | 54 | searchParam.setQuery(queryBuilder); |
61 | searchParam.setSize(0); | 55 | searchParam.setSize(0); |
62 | // 2)调父类查询 | 56 | // 2)调父类查询 |
63 | - JSONObject result = super.queryWithCache(searchParam, paramMap); | 57 | + JSONObject result = doRealQuery(searchParam, paramMap); |
64 | // 3)生成结果 | 58 | // 3)生成结果 |
65 | return new SearchApiResult().setData(result); | 59 | return new SearchApiResult().setData(result); |
60 | + } catch (Exception e) { | ||
61 | + return SearchApiResultUtils.errorSearchApiResult(logger, paramMap, e); | ||
62 | + } | ||
66 | } | 63 | } |
67 | 64 | ||
68 | - @Override | ||
69 | - protected JSONObject doRealQuery(SearchParam searchParam, @Nullable Object... params) throws Exception { | ||
70 | - | 65 | + private JSONObject doRealQuery(SearchParam searchParam, @Nullable Object... params) throws Exception { |
71 | Map<String, String> paramMap = (Map<String, String>) params[0]; | 66 | Map<String, String> paramMap = (Map<String, String>) params[0]; |
72 | 67 | ||
73 | // 构造聚合报文 | 68 | // 构造聚合报文 |
@@ -89,42 +84,26 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { | @@ -89,42 +84,26 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { | ||
89 | return dataMap; | 84 | return dataMap; |
90 | } | 85 | } |
91 | 86 | ||
92 | - @Override | ||
93 | - protected int cacheTimeInMinute() { | ||
94 | - return 0; | ||
95 | - } | ||
96 | - | ||
97 | - @Override | ||
98 | - protected String cacheSceneKey() { | ||
99 | - return "UFO_SELECTIONS_FOR_APP"; | ||
100 | - } | ||
101 | - | ||
102 | /** | 87 | /** |
103 | * 构造不带提前聚合逻辑的报文 | 88 | * 构造不带提前聚合逻辑的报文 |
104 | **/ | 89 | **/ |
105 | private List<AbstractAggregationBuilder<?>> getAllAggregationBuilders(Map<String, String> paramMap) { | 90 | private List<AbstractAggregationBuilder<?>> getAllAggregationBuilders(Map<String, String> paramMap) { |
106 | List<AbstractAggregationBuilder<?>> list = new ArrayList<AbstractAggregationBuilder<?>>(); | 91 | List<AbstractAggregationBuilder<?>> list = new ArrayList<AbstractAggregationBuilder<?>>(); |
107 | - | ||
108 | - // 6)品牌 | 92 | + //品牌 |
109 | list.add(aggregationFactory.getUfoBrandAggregation(paramMap).getBuilder()); | 93 | list.add(aggregationFactory.getUfoBrandAggregation(paramMap).getBuilder()); |
110 | - | ||
111 | //品类 | 94 | //品类 |
112 | list.add(aggregationFactory.getUfoSortAggregation(paramMap).getBuilder()); | 95 | list.add(aggregationFactory.getUfoSortAggregation(paramMap).getBuilder()); |
113 | - | ||
114 | - // 2)性别 | 96 | + //性别 |
115 | list.add(aggregationFactory.getUfoGenderAggregation().getBuilder()); | 97 | list.add(aggregationFactory.getUfoGenderAggregation().getBuilder()); |
116 | - | ||
117 | - // 8)尺码 | 98 | + //尺码 |
118 | list.add(aggregationFactory.getUfoSizeAggregation().getBuilder()); | 99 | list.add(aggregationFactory.getUfoSizeAggregation().getBuilder()); |
119 | - | ||
120 | - | ||
121 | return list; | 100 | return list; |
122 | } | 101 | } |
123 | 102 | ||
124 | private Map<String, Object> getAggResultMap(Map<String, String> paramMap, Map<String, Aggregation> aggMaps) { | 103 | private Map<String, Object> getAggResultMap(Map<String, String> paramMap, Map<String, Aggregation> aggMaps) { |
125 | Map<String, Object> filter = new HashMap<String, Object>(); | 104 | Map<String, Object> filter = new HashMap<String, Object>(); |
126 | 105 | ||
127 | - // 2)获取性别的聚合结果 | 106 | + // 性别的聚合结果 |
128 | IAggregation genderAggregation = aggregationFactory.getUfoGenderAggregation(); | 107 | IAggregation genderAggregation = aggregationFactory.getUfoGenderAggregation(); |
129 | Object genderResponse = genderAggregation.getAggregationResponseMap(aggMaps); | 108 | Object genderResponse = genderAggregation.getAggregationResponseMap(aggMaps); |
130 | if (genderResponse != null) { | 109 | if (genderResponse != null) { |
@@ -133,7 +112,7 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { | @@ -133,7 +112,7 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { | ||
133 | filter.put("gender", new JSONArray()); | 112 | filter.put("gender", new JSONArray()); |
134 | } | 113 | } |
135 | 114 | ||
136 | - // 6)获取品牌层面的聚合结果 | 115 | + // 6品牌层面的聚合结果 |
137 | IAggregation brandAggregation = aggregationFactory.getUfoBrandAggregation(paramMap); | 116 | IAggregation brandAggregation = aggregationFactory.getUfoBrandAggregation(paramMap); |
138 | Object brandResponse = brandAggregation.getAggregationResponseMap(aggMaps); | 117 | Object brandResponse = brandAggregation.getAggregationResponseMap(aggMaps); |
139 | if (brandResponse != null) { | 118 | if (brandResponse != null) { |
@@ -151,7 +130,7 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { | @@ -151,7 +130,7 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { | ||
151 | filter.put("sort", new JSONArray()); | 130 | filter.put("sort", new JSONArray()); |
152 | } | 131 | } |
153 | 132 | ||
154 | - // 7)获取尺码聚合结果[尺码不会提前聚合] | 133 | + // 尺码 |
155 | IAggregation sizeAggregation = aggregationFactory.getUfoSizeAggregation(); | 134 | IAggregation sizeAggregation = aggregationFactory.getUfoSizeAggregation(); |
156 | Object sizeResponse = sizeAggregation.getAggregationResponseMap(aggMaps); | 135 | Object sizeResponse = sizeAggregation.getAggregationResponseMap(aggMaps); |
157 | if (sizeResponse != null) { | 136 | if (sizeResponse != null) { |
@@ -160,7 +139,6 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { | @@ -160,7 +139,6 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { | ||
160 | filter.put("size", new JSONArray()); | 139 | filter.put("size", new JSONArray()); |
161 | } | 140 | } |
162 | 141 | ||
163 | - | ||
164 | return filter; | 142 | return filter; |
165 | } | 143 | } |
166 | 144 |
-
Please register or login to post a comment