Showing
6 changed files
with
33 additions
and
23 deletions
@@ -25,9 +25,6 @@ public class FuzzySceneController { | @@ -25,9 +25,6 @@ public class FuzzySceneController { | ||
25 | 25 | ||
26 | @Autowired | 26 | @Autowired |
27 | private FuzzySceneService fuzzySearchService; | 27 | private FuzzySceneService fuzzySearchService; |
28 | - | ||
29 | - @Autowired | ||
30 | - private IAggRecommendService aggRecommendService; | ||
31 | 28 | ||
32 | /** | 29 | /** |
33 | * 模糊搜索列表 | 30 | * 模糊搜索列表 |
@@ -39,7 +36,6 @@ public class FuzzySceneController { | @@ -39,7 +36,6 @@ public class FuzzySceneController { | ||
39 | public SearchApiResult fuzzyProductList(HttpServletRequest request) { | 36 | public SearchApiResult fuzzyProductList(HttpServletRequest request) { |
40 | Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); | 37 | Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); |
41 | SearchApiResult searchApiResult = fuzzySearchService.productList(paramMap); | 38 | SearchApiResult searchApiResult = fuzzySearchService.productList(paramMap); |
42 | - aggRecommendService.recommendPromotion(searchApiResult, paramMap); | ||
43 | return searchApiResult; | 39 | return searchApiResult; |
44 | } | 40 | } |
45 | 41 |
@@ -23,8 +23,6 @@ public class SortSceneController { | @@ -23,8 +23,6 @@ public class SortSceneController { | ||
23 | 23 | ||
24 | @Autowired | 24 | @Autowired |
25 | private SortSceneService sortSearchService; | 25 | private SortSceneService sortSearchService; |
26 | - @Autowired | ||
27 | - private IAggRecommendService aggRecommendService; | ||
28 | 26 | ||
29 | /** | 27 | /** |
30 | * 品类页列表 | 28 | * 品类页列表 |
@@ -36,7 +34,6 @@ public class SortSceneController { | @@ -36,7 +34,6 @@ public class SortSceneController { | ||
36 | public SearchApiResult sortProductList(HttpServletRequest request) { | 34 | public SearchApiResult sortProductList(HttpServletRequest request) { |
37 | Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); | 35 | Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); |
38 | SearchApiResult searchApiResult = sortSearchService.productList(paramMap); | 36 | SearchApiResult searchApiResult = sortSearchService.productList(paramMap); |
39 | - aggRecommendService.recommendPromotion(searchApiResult, paramMap); | ||
40 | return searchApiResult; | 37 | return searchApiResult; |
41 | } | 38 | } |
42 | 39 |
@@ -11,6 +11,7 @@ import com.yoho.search.service.helper.SearchKeyWordHelper; | @@ -11,6 +11,7 @@ import com.yoho.search.service.helper.SearchKeyWordHelper; | ||
11 | import com.yoho.search.service.scene.common.AbstractSceneService; | 11 | import com.yoho.search.service.scene.common.AbstractSceneService; |
12 | import com.yoho.search.service.scene.common.SceneProductListService; | 12 | import com.yoho.search.service.scene.common.SceneProductListService; |
13 | import com.yoho.search.service.scene.common.SceneSelectionsService; | 13 | import com.yoho.search.service.scene.common.SceneSelectionsService; |
14 | +import com.yoho.search.service.service.IAggRecommendService; | ||
14 | import com.yoho.search.service.service.IProductIndexService; | 15 | import com.yoho.search.service.service.IProductIndexService; |
15 | import com.yoho.search.service.service.ISearchRecommendService; | 16 | import com.yoho.search.service.service.ISearchRecommendService; |
16 | import org.apache.commons.lang.StringUtils; | 17 | import org.apache.commons.lang.StringUtils; |
@@ -19,6 +20,7 @@ import org.slf4j.LoggerFactory; | @@ -19,6 +20,7 @@ import org.slf4j.LoggerFactory; | ||
19 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
20 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
21 | 22 | ||
23 | +import java.util.List; | ||
22 | import java.util.Map; | 24 | import java.util.Map; |
23 | import java.util.concurrent.CompletableFuture; | 25 | import java.util.concurrent.CompletableFuture; |
24 | import java.util.concurrent.ExecutorService; | 26 | import java.util.concurrent.ExecutorService; |
@@ -43,12 +45,16 @@ public class FuzzySceneService extends AbstractSceneService { | @@ -43,12 +45,16 @@ public class FuzzySceneService extends AbstractSceneService { | ||
43 | private SearchKeyWordHelper searchKeyWordService; | 45 | private SearchKeyWordHelper searchKeyWordService; |
44 | @Autowired | 46 | @Autowired |
45 | private IProductIndexService productIndexService; | 47 | private IProductIndexService productIndexService; |
48 | + @Autowired | ||
49 | + private IAggRecommendService aggRecommendService; | ||
46 | 50 | ||
47 | private ExecutorService executorService = Executors.newFixedThreadPool(100); | 51 | private ExecutorService executorService = Executors.newFixedThreadPool(100); |
48 | 52 | ||
49 | // 当少于20个商品时 返回智能搜索词提示 | 53 | // 当少于20个商品时 返回智能搜索词提示 |
50 | private static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20; | 54 | private static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20; |
51 | 55 | ||
56 | + private static final String RECOMMENG_PROMOTION_LIST = "recommend_promotion_list"; | ||
57 | + | ||
52 | @Override | 58 | @Override |
53 | public String pageId() { | 59 | public String pageId() { |
54 | return SearchPageIdDefine.PAGE_ID_SEARCH; | 60 | return SearchPageIdDefine.PAGE_ID_SEARCH; |
@@ -89,9 +95,17 @@ public class FuzzySceneService extends AbstractSceneService { | @@ -89,9 +95,17 @@ public class FuzzySceneService extends AbstractSceneService { | ||
89 | CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> { | 95 | CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> { |
90 | return productIndexService.aggCustomizeTag(paramMap); | 96 | return productIndexService.aggCustomizeTag(paramMap); |
91 | }, executorService); | 97 | }, executorService); |
98 | + | ||
99 | + CompletableFuture<List<Object>> recommendProductFuture = CompletableFuture.supplyAsync(() -> { | ||
100 | + return aggRecommendService.recommendPromotion(paramMap); | ||
101 | + }, executorService); | ||
102 | + | ||
92 | SearchApiResult customizeTags = customizeTagFuture.get(); | 103 | SearchApiResult customizeTags = customizeTagFuture.get(); |
93 | - JSONObject dataMap = (JSONObject)searchApiResult.getData(); | 104 | + List<Object> recommendProducts = recommendProductFuture.get(); |
105 | + | ||
106 | + JSONObject dataMap = (JSONObject)searchApiResult.getData(); | ||
94 | dataMap.put("customize_tag", customizeTags.getData()); | 107 | dataMap.put("customize_tag", customizeTags.getData()); |
108 | + dataMap.put(RECOMMENG_PROMOTION_LIST, recommendProducts); | ||
95 | return searchApiResult; | 109 | return searchApiResult; |
96 | } catch (Exception e) { | 110 | } catch (Exception e) { |
97 | logger.error(e.getMessage(), e); | 111 | logger.error(e.getMessage(), e); |
@@ -9,6 +9,7 @@ import com.yoho.search.service.helper.SearchCommonHelper; | @@ -9,6 +9,7 @@ import com.yoho.search.service.helper.SearchCommonHelper; | ||
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.SceneProductListService; | 10 | import com.yoho.search.service.scene.common.SceneProductListService; |
11 | import com.yoho.search.service.scene.common.SceneSelectionsService; | 11 | import com.yoho.search.service.scene.common.SceneSelectionsService; |
12 | +import com.yoho.search.service.service.IAggRecommendService; | ||
12 | import com.yoho.search.service.service.IProductIndexService; | 13 | import com.yoho.search.service.service.IProductIndexService; |
13 | import org.apache.commons.collections.MapUtils; | 14 | import org.apache.commons.collections.MapUtils; |
14 | import org.apache.commons.lang.StringUtils; | 15 | import org.apache.commons.lang.StringUtils; |
@@ -29,6 +30,7 @@ import java.util.concurrent.Executors; | @@ -29,6 +30,7 @@ import java.util.concurrent.Executors; | ||
29 | public class SortSceneService extends AbstractSceneService { | 30 | public class SortSceneService extends AbstractSceneService { |
30 | 31 | ||
31 | private static final Logger logger = LoggerFactory.getLogger(SortSceneService.class); | 32 | private static final Logger logger = LoggerFactory.getLogger(SortSceneService.class); |
33 | + private static final String RECOMMENG_PROMOTION_LIST = "recommend_promotion_list"; | ||
32 | 34 | ||
33 | @Autowired | 35 | @Autowired |
34 | private SceneProductListService sceneProductListService; | 36 | private SceneProductListService sceneProductListService; |
@@ -39,7 +41,7 @@ public class SortSceneService extends AbstractSceneService { | @@ -39,7 +41,7 @@ public class SortSceneService extends AbstractSceneService { | ||
39 | @Autowired | 41 | @Autowired |
40 | private IProductIndexService productIndexService; | 42 | private IProductIndexService productIndexService; |
41 | @Autowired | 43 | @Autowired |
42 | - private AggregationFactoryService aggregationFactoryService; | 44 | + private IAggRecommendService aggRecommendService; |
43 | 45 | ||
44 | @Override | 46 | @Override |
45 | public String pageId() { | 47 | public String pageId() { |
@@ -100,13 +102,20 @@ public class SortSceneService extends AbstractSceneService { | @@ -100,13 +102,20 @@ public class SortSceneService extends AbstractSceneService { | ||
100 | CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> { | 102 | CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> { |
101 | return productIndexService.aggCustomizeTag(paramMap); | 103 | return productIndexService.aggCustomizeTag(paramMap); |
102 | }, executorService); | 104 | }, executorService); |
105 | + CompletableFuture<List<Object>> recommendProductFuture = CompletableFuture.supplyAsync(() -> { | ||
106 | + return aggRecommendService.recommendPromotion(paramMap); | ||
107 | + }, executorService); | ||
108 | + | ||
103 | // 4、组合结果 | 109 | // 4、组合结果 |
104 | SearchApiResult productList = productListFuture.get(); | 110 | SearchApiResult productList = productListFuture.get(); |
105 | SearchApiResult standards = standardsFuture.get(); | 111 | SearchApiResult standards = standardsFuture.get(); |
106 | SearchApiResult customizeTags = customizeTagFuture.get(); | 112 | SearchApiResult customizeTags = customizeTagFuture.get(); |
113 | + List<Object> recommendProducts = recommendProductFuture.get(); | ||
114 | + | ||
107 | JSONObject jsonObject = (JSONObject) productList.getData(); | 115 | JSONObject jsonObject = (JSONObject) productList.getData(); |
108 | jsonObject.put("standard", standards.getData()); | 116 | jsonObject.put("standard", standards.getData()); |
109 | jsonObject.put("customize_tag", customizeTags.getData()); | 117 | jsonObject.put("customize_tag", customizeTags.getData()); |
118 | + jsonObject.put(RECOMMENG_PROMOTION_LIST, recommendProducts); | ||
110 | return productList; | 119 | return productList; |
111 | } catch (Exception e) { | 120 | } catch (Exception e) { |
112 | logger.error(e.getMessage(), e); | 121 | logger.error(e.getMessage(), e); |
1 | package com.yoho.search.service.service; | 1 | package com.yoho.search.service.service; |
2 | 2 | ||
3 | +import java.util.List; | ||
3 | import java.util.Map; | 4 | import java.util.Map; |
4 | 5 | ||
5 | import org.elasticsearch.index.query.BoolQueryBuilder; | 6 | import org.elasticsearch.index.query.BoolQueryBuilder; |
@@ -36,9 +37,8 @@ public interface IAggRecommendService { | @@ -36,9 +37,8 @@ public interface IAggRecommendService { | ||
36 | /** | 37 | /** |
37 | * 获取促销的聚合结果[使用本地缓存] | 38 | * 获取促销的聚合结果[使用本地缓存] |
38 | * | 39 | * |
39 | - * @param paramMap | ||
40 | * @return | 40 | * @return |
41 | */ | 41 | */ |
42 | - void recommendPromotion(SearchApiResult searchApiResult, Map<String, String> paramMap); | 42 | + List<Object> recommendPromotion(Map<String, String> paramMap); |
43 | 43 | ||
44 | } | 44 | } |
@@ -34,7 +34,6 @@ import com.yoho.search.service.service.IAggRecommendService; | @@ -34,7 +34,6 @@ import com.yoho.search.service.service.IAggRecommendService; | ||
34 | public class AggRecommendServiceImpl implements IAggRecommendService { | 34 | public class AggRecommendServiceImpl implements IAggRecommendService { |
35 | 35 | ||
36 | private static final Logger logger = LoggerFactory.getLogger(AggRecommendServiceImpl.class); | 36 | private static final Logger logger = LoggerFactory.getLogger(AggRecommendServiceImpl.class); |
37 | - private static final String RECOMMENG_PROMOTION_LIST = "recommend_promotion_list"; | ||
38 | private static final int DEFAULT_AGGREGATION_COUNT = 100; | 37 | private static final int DEFAULT_AGGREGATION_COUNT = 100; |
39 | 38 | ||
40 | @Autowired | 39 | @Autowired |
@@ -159,12 +158,8 @@ public class AggRecommendServiceImpl implements IAggRecommendService { | @@ -159,12 +158,8 @@ public class AggRecommendServiceImpl implements IAggRecommendService { | ||
159 | } | 158 | } |
160 | 159 | ||
161 | @Override | 160 | @Override |
162 | - public void recommendPromotion(SearchApiResult searchResult, Map<String, String> paramMap) { | 161 | + public List<Object> recommendPromotion(Map<String, String> paramMap) { |
163 | try { | 162 | try { |
164 | - if (searchResult == null || searchResult.getCode() != 200 || searchResult.getData() == null) { | ||
165 | - return; | ||
166 | - } | ||
167 | - JSONObject dataMap = ((JSONObject) searchResult.getData()); | ||
168 | // 1、获取核心参数 | 163 | // 1、获取核心参数 |
169 | int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")); | 164 | int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page")); |
170 | // 1.1添加默认参数 | 165 | // 1.1添加默认参数 |
@@ -185,24 +180,23 @@ public class AggRecommendServiceImpl implements IAggRecommendService { | @@ -185,24 +180,23 @@ public class AggRecommendServiceImpl implements IAggRecommendService { | ||
185 | JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(searchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam); | 180 | JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(searchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam); |
186 | if (cacheJSONArray != null) { | 181 | if (cacheJSONArray != null) { |
187 | SearchCacheMatchLogger.doSearchCacheMatchLog("/productList.json", paramMap); | 182 | SearchCacheMatchLogger.doSearchCacheMatchLog("/productList.json", paramMap); |
188 | - dataMap.put(RECOMMENG_PROMOTION_LIST, subList(cacheJSONArray, page, 1)); | ||
189 | - return; | 183 | + return subList(cacheJSONArray, page, 1); |
190 | } | 184 | } |
191 | // 6、从ES中获取 | 185 | // 6、从ES中获取 |
192 | JSONObject recommendPromotionResult = aggregationService.getAggNameAndResponse(recommendPromotionAgg, searchParam); | 186 | JSONObject recommendPromotionResult = aggregationService.getAggNameAndResponse(recommendPromotionAgg, searchParam); |
193 | if (recommendPromotionResult == null) { | 187 | if (recommendPromotionResult == null) { |
194 | - return; | 188 | + return Collections.emptyList(); |
195 | } | 189 | } |
196 | // 7、生成结果并且加入缓存 | 190 | // 7、生成结果并且加入缓存 |
197 | JSONArray recommendPromotions = recommendPromotionResult.getJSONArray(recommendPromotionAgg.aggName()); | 191 | JSONArray recommendPromotions = recommendPromotionResult.getJSONArray(recommendPromotionAgg.aggName()); |
198 | if (recommendPromotions != null) { | 192 | if (recommendPromotions != null) { |
199 | searchCacheService.addJSONArrayToCache(searchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam, recommendPromotions); | 193 | searchCacheService.addJSONArrayToCache(searchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam, recommendPromotions); |
200 | - dataMap.put(RECOMMENG_PROMOTION_LIST, subList(recommendPromotions, page, 1)); | 194 | + return subList(recommendPromotions, page, 1); |
201 | } | 195 | } |
202 | } catch (Exception e) { | 196 | } catch (Exception e) { |
203 | - return; | 197 | + return Collections.emptyList(); |
204 | } | 198 | } |
205 | - return; | 199 | + return Collections.emptyList(); |
206 | } | 200 | } |
207 | 201 | ||
208 | private List<Object> subList(JSONArray sourceList, int page, int count) { | 202 | private List<Object> subList(JSONArray sourceList, int page, int count) { |
-
Please register or login to post a comment