|
|
package com.yoho.search.service.servicenew.scene;
|
|
|
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
...
|
...
|
@@ -47,6 +48,11 @@ public class FuzzySceneService extends AbstractSceneService { |
|
|
return SearchPageIdDefine.PAGE_ID_SEARCH;
|
|
|
}
|
|
|
|
|
|
private void addParamsToParamMap(Map<String, String> paramMap) {
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_PAGEID, this.pageId());
|
|
|
paramMap.put("aggWithParamBrand", "Y");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @1、返回商品列表
|
|
|
* @2、数量太多则返回建议词
|
...
|
...
|
@@ -54,6 +60,8 @@ public class FuzzySceneService extends AbstractSceneService { |
|
|
@Override
|
|
|
public SearchApiResult productList(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 0、添加默认参数
|
|
|
this.addParamsToParamMap(paramMap);
|
|
|
// 1、获取商品列表
|
|
|
SearchApiResult searchApiResult = splitProductListService.productList(paramMap);
|
|
|
// 2)、加入建议词
|
...
|
...
|
@@ -110,15 +118,30 @@ public class FuzzySceneService extends AbstractSceneService { |
|
|
|
|
|
@Override
|
|
|
public SearchApiResult aggregations(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 0、添加默认参数
|
|
|
this.addParamsToParamMap(paramMap);
|
|
|
// 1、获取通用筛选项
|
|
|
JSONObject commonFilters = splitSelectionsService.getCommonFilters(paramMap);
|
|
|
CompletableFuture<JSONObject> commonFiltersFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
return splitSelectionsService.getCommonFilters(paramMap);
|
|
|
}, executorService);
|
|
|
// 2、获取推荐的品牌
|
|
|
Object recommendBrand = splitSelectionsService.getRecommendBrands(paramMap);
|
|
|
CompletableFuture<Object> recommendBrandFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
return splitSelectionsService.getRecommendBrands(paramMap);
|
|
|
}, executorService);
|
|
|
// 3、组合
|
|
|
JSONObject commonFilters = commonFiltersFuture.get();
|
|
|
Object recommendBrand = recommendBrandFuture.get();
|
|
|
if (recommendBrand != null) {
|
|
|
commonFilters.put("recommendBrand", recommendBrand);
|
|
|
}
|
|
|
// 4、返回最终结果
|
|
|
Map<String, Object> result = new JSONObject();
|
|
|
result.put("filter", commonFilters);
|
|
|
return new SearchApiResult().setData(result);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new SearchApiResult().setData(null).setMessage("FuzzyAggregations Exception").setCode(500);
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|