Showing
7 changed files
with
28 additions
and
17 deletions
@@ -3,12 +3,14 @@ package com.yoho.search.service.base.index; | @@ -3,12 +3,14 @@ package com.yoho.search.service.base.index; | ||
3 | import com.alibaba.fastjson.JSONArray; | 3 | import com.alibaba.fastjson.JSONArray; |
4 | import com.yoho.search.base.utils.DateUtil; | 4 | import com.yoho.search.base.utils.DateUtil; |
5 | import com.yoho.search.base.utils.ProductIndexEsField; | 5 | import com.yoho.search.base.utils.ProductIndexEsField; |
6 | + | ||
6 | import org.apache.commons.collections.MapUtils; | 7 | import org.apache.commons.collections.MapUtils; |
7 | import org.apache.commons.lang.StringUtils; | 8 | import org.apache.commons.lang.StringUtils; |
8 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
9 | import org.springframework.stereotype.Service; | 10 | import org.springframework.stereotype.Service; |
10 | 11 | ||
11 | import javax.annotation.PostConstruct; | 12 | import javax.annotation.PostConstruct; |
13 | + | ||
12 | import java.text.ParseException; | 14 | import java.text.ParseException; |
13 | import java.util.*; | 15 | import java.util.*; |
14 | 16 | ||
@@ -223,12 +225,13 @@ public class ProductIndexBaseService { | @@ -223,12 +225,13 @@ public class ProductIndexBaseService { | ||
223 | * @param map | 225 | * @param map |
224 | * @return | 226 | * @return |
225 | */ | 227 | */ |
226 | - private boolean getPromotionActive(Map<String, Object> map) { | 228 | + @SuppressWarnings({ "rawtypes", "unchecked" }) |
229 | + private boolean getPromotionActive(Map<String, Object> map) { | ||
227 | boolean promotionActive = false; | 230 | boolean promotionActive = false; |
228 | try { | 231 | try { |
229 | Date date = new Date(); | 232 | Date date = new Date(); |
230 | long nowUnixTime = DateUtil.Date2TimeStamp(date); | 233 | long nowUnixTime = DateUtil.Date2TimeStamp(date); |
231 | - List<Map<String, Object>> promotionList = (ArrayList) MapUtils.getObject(map, ProductIndexEsField.matchedPromotions, new ArrayList()); | 234 | + List<Map<String, Object>> promotionList = (ArrayList) MapUtils.getObject(map, ProductIndexEsField.matchedPromotions, new ArrayList()); |
232 | for (Map<String, Object> hashMap : promotionList) { | 235 | for (Map<String, Object> hashMap : promotionList) { |
233 | Integer startTime = hashMap.get("startTime") == null ? 0 : (Integer) hashMap.get("startTime"); | 236 | Integer startTime = hashMap.get("startTime") == null ? 0 : (Integer) hashMap.get("startTime"); |
234 | Integer endTime = hashMap.get("endTime") == null ? 0 : (Integer) hashMap.get("endTime"); | 237 | Integer endTime = hashMap.get("endTime") == null ? 0 : (Integer) hashMap.get("endTime"); |
@@ -114,7 +114,7 @@ public class BreakSizeSceneService extends AbstractSceneService { | @@ -114,7 +114,7 @@ public class BreakSizeSceneService extends AbstractSceneService { | ||
114 | this.addParamsToParamMap(paramMap); | 114 | this.addParamsToParamMap(paramMap); |
115 | // 2、返回聚合结果 | 115 | // 2、返回聚合结果 |
116 | List<IAggregation> aggregation = sceneSelectionsService.getBreakSizeAggregations(paramMap); | 116 | List<IAggregation> aggregation = sceneSelectionsService.getBreakSizeAggregations(paramMap); |
117 | - return sceneSelectionsService.aggregations(paramMap, aggregation); | 117 | + return sceneSelectionsService.aggregations(paramMap, aggregation,true); |
118 | } catch (Exception e) { | 118 | } catch (Exception e) { |
119 | logger.error("[func=Couponaggregations][params=" + paramMap + "]", e); | 119 | logger.error("[func=Couponaggregations][params=" + paramMap + "]", e); |
120 | return SearchApiResultUtils.errorSearchApiResult("Couponaggregations", paramMap, e); | 120 | return SearchApiResultUtils.errorSearchApiResult("Couponaggregations", paramMap, e); |
@@ -65,7 +65,7 @@ public class ReducePriceSceneService extends AbstractSceneService { | @@ -65,7 +65,7 @@ public class ReducePriceSceneService extends AbstractSceneService { | ||
65 | this.addParamsToParamMap(paramMap); | 65 | this.addParamsToParamMap(paramMap); |
66 | // 2、返回聚合结果 | 66 | // 2、返回聚合结果 |
67 | List<IAggregation> aggregation = sceneSelectionsService.getReducePriceAggregations(paramMap); | 67 | List<IAggregation> aggregation = sceneSelectionsService.getReducePriceAggregations(paramMap); |
68 | - return sceneSelectionsService.aggregations(paramMap, aggregation); | 68 | + return sceneSelectionsService.aggregations(paramMap, aggregation,false); |
69 | } catch (Exception e) { | 69 | } catch (Exception e) { |
70 | logger.error("[func=NewArrivalAggregations][params=" + paramMap + "]", e); | 70 | logger.error("[func=NewArrivalAggregations][params=" + paramMap + "]", e); |
71 | return SearchApiResultUtils.errorSearchApiResult("NewArrivalAggregations", paramMap, e); | 71 | return SearchApiResultUtils.errorSearchApiResult("NewArrivalAggregations", paramMap, e); |
@@ -82,7 +82,7 @@ public class ShopSceneService extends AbstractSceneService { | @@ -82,7 +82,7 @@ public class ShopSceneService extends AbstractSceneService { | ||
82 | this.addParamsToParamMap(paramMap); | 82 | this.addParamsToParamMap(paramMap); |
83 | // 2、返回聚合结果 | 83 | // 2、返回聚合结果 |
84 | List<IAggregation> aggregations = sceneSelectionsService.getShopOldAggregations(paramMap); | 84 | List<IAggregation> aggregations = sceneSelectionsService.getShopOldAggregations(paramMap); |
85 | - return sceneSelectionsService.aggregations(paramMap, aggregations); | 85 | + return sceneSelectionsService.aggregations(paramMap, aggregations,false); |
86 | } catch (Exception e) { | 86 | } catch (Exception e) { |
87 | logger.error("[func=ShopAggregations][params=" + paramMap + "]", e); | 87 | logger.error("[func=ShopAggregations][params=" + paramMap + "]", e); |
88 | return SearchApiResultUtils.errorSearchApiResult("ShopAggregations", paramMap, e); | 88 | return SearchApiResultUtils.errorSearchApiResult("ShopAggregations", paramMap, e); |
@@ -248,29 +248,35 @@ public class SceneSelectionsService extends AbstractCacheAbleService { | @@ -248,29 +248,35 @@ public class SceneSelectionsService extends AbstractCacheAbleService { | ||
248 | return this.aggregations(paramMap, commonAggregations, null); | 248 | return this.aggregations(paramMap, commonAggregations, null); |
249 | } | 249 | } |
250 | 250 | ||
251 | - public SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations) throws Exception { | ||
252 | - return this.aggregations(paramMap, aggregations, null); | 251 | + public SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations, boolean needRecommendBrand) throws Exception { |
252 | + return this.aggregations(paramMap, aggregations, null,needRecommendBrand); | ||
253 | } | 253 | } |
254 | - | 254 | + |
255 | public SearchApiResult aggregations(Map<String, String> paramMap, BoolQueryBuilder mustFilter) throws Exception { | 255 | public SearchApiResult aggregations(Map<String, String> paramMap, BoolQueryBuilder mustFilter) throws Exception { |
256 | List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap); | 256 | List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap); |
257 | return this.aggregations(paramMap, commonAggregations, mustFilter); | 257 | return this.aggregations(paramMap, commonAggregations, mustFilter); |
258 | } | 258 | } |
259 | 259 | ||
260 | public SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations, BoolQueryBuilder mustFilter) throws Exception { | 260 | public SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations, BoolQueryBuilder mustFilter) throws Exception { |
261 | + return this.aggregations(paramMap,aggregations,mustFilter,true); | ||
262 | + } | ||
263 | + | ||
264 | + public SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations, BoolQueryBuilder mustFilter,boolean needRecommendBrand) throws Exception { | ||
261 | // 1、获取通用筛选项 | 265 | // 1、获取通用筛选项 |
262 | CompletableFuture<JSONObject> commonFiltersFuture = CompletableFuture.supplyAsync(() -> { | 266 | CompletableFuture<JSONObject> commonFiltersFuture = CompletableFuture.supplyAsync(() -> { |
263 | return this.getFiltersResult(paramMap, aggregations, mustFilter); | 267 | return this.getFiltersResult(paramMap, aggregations, mustFilter); |
264 | }, executorService); | 268 | }, executorService); |
265 | // 2、获取推荐的品牌 | 269 | // 2、获取推荐的品牌 |
266 | - CompletableFuture<Object> recommendBrandFuture = CompletableFuture.supplyAsync(() -> { | ||
267 | - return this.getRecommendBrands(paramMap, mustFilter); | ||
268 | - }, executorService); | 270 | + CompletableFuture<Object> recommendBrandFuture = null; |
271 | + if(needRecommendBrand){ | ||
272 | + recommendBrandFuture = CompletableFuture.supplyAsync(() -> { | ||
273 | + return this.getRecommendBrands(paramMap, mustFilter); | ||
274 | + }, executorService); | ||
275 | + } | ||
269 | // 3、组合 | 276 | // 3、组合 |
270 | JSONObject commonFilters = commonFiltersFuture.get(); | 277 | JSONObject commonFilters = commonFiltersFuture.get(); |
271 | - Object recommendBrand = recommendBrandFuture.get(); | ||
272 | - if (recommendBrand != null) { | ||
273 | - commonFilters.put("recommendBrand", recommendBrand); | 278 | + if (needRecommendBrand && recommendBrandFuture != null) { |
279 | + commonFilters.put("recommendBrand", recommendBrandFuture.get()); | ||
274 | } | 280 | } |
275 | // 4、返回最终结果 | 281 | // 4、返回最终结果 |
276 | Map<String, Object> result = new JSONObject(); | 282 | Map<String, Object> result = new JSONObject(); |
1 | package com.yoho.search.service.service.impl; | 1 | package com.yoho.search.service.service.impl; |
2 | 2 | ||
3 | -import java.util.*; | 3 | +import java.util.ArrayList; |
4 | +import java.util.Arrays; | ||
5 | +import java.util.Collections; | ||
6 | +import java.util.List; | ||
7 | +import java.util.Map; | ||
4 | 8 | ||
5 | import javax.annotation.PostConstruct; | 9 | import javax.annotation.PostConstruct; |
6 | 10 | ||
7 | -import com.yoho.search.base.utils.DateUtil; | ||
8 | import org.apache.commons.lang.StringUtils; | 11 | import org.apache.commons.lang.StringUtils; |
9 | import org.elasticsearch.index.query.BoolQueryBuilder; | 12 | import org.elasticsearch.index.query.BoolQueryBuilder; |
10 | import org.slf4j.Logger; | 13 | import org.slf4j.Logger; |
@@ -47,7 +47,6 @@ import com.yoho.search.service.service.ISearchRecommendService; | @@ -47,7 +47,6 @@ import com.yoho.search.service.service.ISearchRecommendService; | ||
47 | public class ProductListServiceImpl implements IProductListService { | 47 | public class ProductListServiceImpl implements IProductListService { |
48 | 48 | ||
49 | private static final Logger logger = LoggerFactory.getLogger(ProductListServiceImpl.class); | 49 | private static final Logger logger = LoggerFactory.getLogger(ProductListServiceImpl.class); |
50 | - private static Logger CACHE_MATCH_REQUEST = LoggerFactory.getLogger("CACHE_MATCH_REQUEST"); | ||
51 | 50 | ||
52 | // 当少于20个商品时 返回智能搜索词提示 | 51 | // 当少于20个商品时 返回智能搜索词提示 |
53 | private static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20; | 52 | private static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20; |
-
Please register or login to post a comment