Authored by unknown

fix bug

... ... @@ -3,12 +3,14 @@ package com.yoho.search.service.base.index;
import com.alibaba.fastjson.JSONArray;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.base.utils.ProductIndexEsField;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.text.ParseException;
import java.util.*;
... ... @@ -223,12 +225,13 @@ public class ProductIndexBaseService {
* @param map
* @return
*/
private boolean getPromotionActive(Map<String, Object> map) {
@SuppressWarnings({ "rawtypes", "unchecked" })
private boolean getPromotionActive(Map<String, Object> map) {
boolean promotionActive = false;
try {
Date date = new Date();
long nowUnixTime = DateUtil.Date2TimeStamp(date);
List<Map<String, Object>> promotionList = (ArrayList) MapUtils.getObject(map, ProductIndexEsField.matchedPromotions, new ArrayList());
List<Map<String, Object>> promotionList = (ArrayList) MapUtils.getObject(map, ProductIndexEsField.matchedPromotions, new ArrayList());
for (Map<String, Object> hashMap : promotionList) {
Integer startTime = hashMap.get("startTime") == null ? 0 : (Integer) hashMap.get("startTime");
Integer endTime = hashMap.get("endTime") == null ? 0 : (Integer) hashMap.get("endTime");
... ...
... ... @@ -114,7 +114,7 @@ public class BreakSizeSceneService extends AbstractSceneService {
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
List<IAggregation> aggregation = sceneSelectionsService.getBreakSizeAggregations(paramMap);
return sceneSelectionsService.aggregations(paramMap, aggregation);
return sceneSelectionsService.aggregations(paramMap, aggregation,true);
} catch (Exception e) {
logger.error("[func=Couponaggregations][params=" + paramMap + "]", e);
return SearchApiResultUtils.errorSearchApiResult("Couponaggregations", paramMap, e);
... ...
... ... @@ -65,7 +65,7 @@ public class ReducePriceSceneService extends AbstractSceneService {
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
List<IAggregation> aggregation = sceneSelectionsService.getReducePriceAggregations(paramMap);
return sceneSelectionsService.aggregations(paramMap, aggregation);
return sceneSelectionsService.aggregations(paramMap, aggregation,false);
} catch (Exception e) {
logger.error("[func=NewArrivalAggregations][params=" + paramMap + "]", e);
return SearchApiResultUtils.errorSearchApiResult("NewArrivalAggregations", paramMap, e);
... ...
... ... @@ -82,7 +82,7 @@ public class ShopSceneService extends AbstractSceneService {
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
List<IAggregation> aggregations = sceneSelectionsService.getShopOldAggregations(paramMap);
return sceneSelectionsService.aggregations(paramMap, aggregations);
return sceneSelectionsService.aggregations(paramMap, aggregations,false);
} catch (Exception e) {
logger.error("[func=ShopAggregations][params=" + paramMap + "]", e);
return SearchApiResultUtils.errorSearchApiResult("ShopAggregations", paramMap, e);
... ...
... ... @@ -248,29 +248,35 @@ public class SceneSelectionsService extends AbstractCacheAbleService {
return this.aggregations(paramMap, commonAggregations, null);
}
public SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations) throws Exception {
return this.aggregations(paramMap, aggregations, null);
public SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations, boolean needRecommendBrand) throws Exception {
return this.aggregations(paramMap, aggregations, null,needRecommendBrand);
}
public SearchApiResult aggregations(Map<String, String> paramMap, BoolQueryBuilder mustFilter) throws Exception {
List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap);
return this.aggregations(paramMap, commonAggregations, mustFilter);
}
public SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations, BoolQueryBuilder mustFilter) throws Exception {
return this.aggregations(paramMap,aggregations,mustFilter,true);
}
public SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations, BoolQueryBuilder mustFilter,boolean needRecommendBrand) throws Exception {
// 1、获取通用筛选项
CompletableFuture<JSONObject> commonFiltersFuture = CompletableFuture.supplyAsync(() -> {
return this.getFiltersResult(paramMap, aggregations, mustFilter);
}, executorService);
// 2、获取推荐的品牌
CompletableFuture<Object> recommendBrandFuture = CompletableFuture.supplyAsync(() -> {
return this.getRecommendBrands(paramMap, mustFilter);
}, executorService);
CompletableFuture<Object> recommendBrandFuture = null;
if(needRecommendBrand){
recommendBrandFuture = CompletableFuture.supplyAsync(() -> {
return this.getRecommendBrands(paramMap, mustFilter);
}, executorService);
}
// 3、组合
JSONObject commonFilters = commonFiltersFuture.get();
Object recommendBrand = recommendBrandFuture.get();
if (recommendBrand != null) {
commonFilters.put("recommendBrand", recommendBrand);
if (needRecommendBrand && recommendBrandFuture != null) {
commonFilters.put("recommendBrand", recommendBrandFuture.get());
}
// 4、返回最终结果
Map<String, Object> result = new JSONObject();
... ...
package com.yoho.search.service.service.impl;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import com.yoho.search.base.utils.DateUtil;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.slf4j.Logger;
... ...
... ... @@ -47,7 +47,6 @@ import com.yoho.search.service.service.ISearchRecommendService;
public class ProductListServiceImpl implements IProductListService {
private static final Logger logger = LoggerFactory.getLogger(ProductListServiceImpl.class);
private static Logger CACHE_MATCH_REQUEST = LoggerFactory.getLogger("CACHE_MATCH_REQUEST");
// 当少于20个商品时 返回智能搜索词提示
private static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20;
... ...