Authored by Zhao

aggpromotion parallel

... ... @@ -25,9 +25,6 @@ public class FuzzySceneController {
@Autowired
private FuzzySceneService fuzzySearchService;
@Autowired
private IAggRecommendService aggRecommendService;
/**
* 模糊搜索列表
... ... @@ -39,7 +36,6 @@ public class FuzzySceneController {
public SearchApiResult fuzzyProductList(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
SearchApiResult searchApiResult = fuzzySearchService.productList(paramMap);
aggRecommendService.recommendPromotion(searchApiResult, paramMap);
return searchApiResult;
}
... ...
... ... @@ -23,8 +23,6 @@ public class SortSceneController {
@Autowired
private SortSceneService sortSearchService;
@Autowired
private IAggRecommendService aggRecommendService;
/**
* 品类页列表
... ... @@ -36,7 +34,6 @@ public class SortSceneController {
public SearchApiResult sortProductList(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
SearchApiResult searchApiResult = sortSearchService.productList(paramMap);
aggRecommendService.recommendPromotion(searchApiResult, paramMap);
return searchApiResult;
}
... ...
... ... @@ -11,6 +11,7 @@ import com.yoho.search.service.helper.SearchKeyWordHelper;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.common.SceneProductListService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.service.IAggRecommendService;
import com.yoho.search.service.service.IProductIndexService;
import com.yoho.search.service.service.ISearchRecommendService;
import org.apache.commons.lang.StringUtils;
... ... @@ -19,6 +20,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
... ... @@ -43,12 +45,16 @@ public class FuzzySceneService extends AbstractSceneService {
private SearchKeyWordHelper searchKeyWordService;
@Autowired
private IProductIndexService productIndexService;
@Autowired
private IAggRecommendService aggRecommendService;
private ExecutorService executorService = Executors.newFixedThreadPool(100);
// 当少于20个商品时 返回智能搜索词提示
private static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20;
private static final String RECOMMENG_PROMOTION_LIST = "recommend_promotion_list";
@Override
public String pageId() {
return SearchPageIdDefine.PAGE_ID_SEARCH;
... ... @@ -89,9 +95,17 @@ public class FuzzySceneService extends AbstractSceneService {
CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> {
return productIndexService.aggCustomizeTag(paramMap);
}, executorService);
CompletableFuture<List<Object>> recommendProductFuture = CompletableFuture.supplyAsync(() -> {
return aggRecommendService.recommendPromotion(paramMap);
}, executorService);
SearchApiResult customizeTags = customizeTagFuture.get();
JSONObject dataMap = (JSONObject)searchApiResult.getData();
List<Object> recommendProducts = recommendProductFuture.get();
JSONObject dataMap = (JSONObject)searchApiResult.getData();
dataMap.put("customize_tag", customizeTags.getData());
dataMap.put(RECOMMENG_PROMOTION_LIST, recommendProducts);
return searchApiResult;
} catch (Exception e) {
logger.error(e.getMessage(), e);
... ...
... ... @@ -9,6 +9,7 @@ import com.yoho.search.service.helper.SearchCommonHelper;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.common.SceneProductListService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.service.IAggRecommendService;
import com.yoho.search.service.service.IProductIndexService;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
... ... @@ -29,6 +30,7 @@ import java.util.concurrent.Executors;
public class SortSceneService extends AbstractSceneService {
private static final Logger logger = LoggerFactory.getLogger(SortSceneService.class);
private static final String RECOMMENG_PROMOTION_LIST = "recommend_promotion_list";
@Autowired
private SceneProductListService sceneProductListService;
... ... @@ -39,7 +41,7 @@ public class SortSceneService extends AbstractSceneService {
@Autowired
private IProductIndexService productIndexService;
@Autowired
private AggregationFactoryService aggregationFactoryService;
private IAggRecommendService aggRecommendService;
@Override
public String pageId() {
... ... @@ -100,13 +102,20 @@ public class SortSceneService extends AbstractSceneService {
CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> {
return productIndexService.aggCustomizeTag(paramMap);
}, executorService);
CompletableFuture<List<Object>> recommendProductFuture = CompletableFuture.supplyAsync(() -> {
return aggRecommendService.recommendPromotion(paramMap);
}, executorService);
// 4、组合结果
SearchApiResult productList = productListFuture.get();
SearchApiResult standards = standardsFuture.get();
SearchApiResult customizeTags = customizeTagFuture.get();
List<Object> recommendProducts = recommendProductFuture.get();
JSONObject jsonObject = (JSONObject) productList.getData();
jsonObject.put("standard", standards.getData());
jsonObject.put("customize_tag", customizeTags.getData());
jsonObject.put(RECOMMENG_PROMOTION_LIST, recommendProducts);
return productList;
} catch (Exception e) {
logger.error(e.getMessage(), e);
... ...
package com.yoho.search.service.service;
import java.util.List;
import java.util.Map;
import org.elasticsearch.index.query.BoolQueryBuilder;
... ... @@ -36,9 +37,8 @@ public interface IAggRecommendService {
/**
* 获取促销的聚合结果[使用本地缓存]
*
* @param paramMap
* @return
*/
void recommendPromotion(SearchApiResult searchApiResult, Map<String, String> paramMap);
List<Object> recommendPromotion(Map<String, String> paramMap);
}
... ...
... ... @@ -34,7 +34,6 @@ import com.yoho.search.service.service.IAggRecommendService;
public class AggRecommendServiceImpl implements IAggRecommendService {
private static final Logger logger = LoggerFactory.getLogger(AggRecommendServiceImpl.class);
private static final String RECOMMENG_PROMOTION_LIST = "recommend_promotion_list";
private static final int DEFAULT_AGGREGATION_COUNT = 100;
@Autowired
... ... @@ -159,12 +158,8 @@ public class AggRecommendServiceImpl implements IAggRecommendService {
}
@Override
public void recommendPromotion(SearchApiResult searchResult, Map<String, String> paramMap) {
public List<Object> recommendPromotion(Map<String, String> paramMap) {
try {
if (searchResult == null || searchResult.getCode() != 200 || searchResult.getData() == null) {
return;
}
JSONObject dataMap = ((JSONObject) searchResult.getData());
// 1、获取核心参数
int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
// 1.1添加默认参数
... ... @@ -185,24 +180,23 @@ public class AggRecommendServiceImpl implements IAggRecommendService {
JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(searchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
if (cacheJSONArray != null) {
SearchCacheMatchLogger.doSearchCacheMatchLog("/productList.json", paramMap);
dataMap.put(RECOMMENG_PROMOTION_LIST, subList(cacheJSONArray, page, 1));
return;
return subList(cacheJSONArray, page, 1);
}
// 6、从ES中获取
JSONObject recommendPromotionResult = aggregationService.getAggNameAndResponse(recommendPromotionAgg, searchParam);
if (recommendPromotionResult == null) {
return;
return Collections.emptyList();
}
// 7、生成结果并且加入缓存
JSONArray recommendPromotions = recommendPromotionResult.getJSONArray(recommendPromotionAgg.aggName());
if (recommendPromotions != null) {
searchCacheService.addJSONArrayToCache(searchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam, recommendPromotions);
dataMap.put(RECOMMENG_PROMOTION_LIST, subList(recommendPromotions, page, 1));
return subList(recommendPromotions, page, 1);
}
} catch (Exception e) {
return;
return Collections.emptyList();
}
return;
return Collections.emptyList();
}
private List<Object> subList(JSONArray sourceList, int page, int count) {
... ...