Authored by unknown

优化4种场景

... ... @@ -33,7 +33,7 @@ public class PriceAggregation extends AbstractAggregation {
@Override
public String filterName() {
return "price";
return "priceRange";
}
@Override
... ...
... ... @@ -98,17 +98,4 @@ public class BaseService {
int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
return page;
}
protected JSONObject getFilterResults(List<IAggregation> aggregations, Map<String, Aggregation> aggMaps) {
JSONObject filter = new JSONObject();
for (IAggregation aggregation : aggregations) {
Object response = aggregation.getAggregationResponseMap(aggMaps);
if (response == null) {
continue;
}
filter.put(aggregation.filterName(), response);
}
return filter;
}
}
... ...
package com.yoho.search.service.servicenew.scene;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -10,7 +11,6 @@ import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.core.es.agg.IAggregation;
import com.yoho.search.service.servicenew.scene.common.AbstractSceneService;
import com.yoho.search.service.servicenew.scene.common.SceneProductListService;
import com.yoho.search.service.servicenew.scene.common.SceneSelectionsService;
... ... @@ -18,7 +18,7 @@ import com.yoho.search.service.utils.SearchApiResultUtils;
import com.yoho.search.service.vo.SearchApiResult;
@Service
public class CouponSceneService extends AbstractSceneService{
public class CouponSceneService extends AbstractSceneService {
private static final Logger logger = LoggerFactory.getLogger(CouponSceneService.class);
... ... @@ -26,13 +26,23 @@ public class CouponSceneService extends AbstractSceneService{
private SceneProductListService splitProductListService;
@Autowired
private SceneSelectionsService splitSelectionsService;
@Override
public String pageId() {
return SearchPageIdDefine.PAGE_ID_COUPON;
}
@Override
public void addParamsToParamMap(Map<String, String> paramMap) {
super.addDefaultParamsToParamMap(paramMap);
}
@Override
public void setExecutorService() {
this.executorService = Executors.newFixedThreadPool(50);
}
@Override
public SearchApiResult productList(Map<String, String> paramMap) {
try {
return splitProductListService.productList(paramMap);
... ... @@ -41,20 +51,33 @@ public class CouponSceneService extends AbstractSceneService{
return SearchApiResultUtils.errorSearchApiResult("couponProductList", paramMap, e);
}
}
@Override
public SearchApiResult aggregations(Map<String, String> paramMap) {
// 1、获取优惠券页面的筛选结果
List<IAggregation> couponAggregations = splitSelectionsService.getCouponAggregations(paramMap);
JSONObject filterResults = splitSelectionsService.getFiltersResults(paramMap,couponAggregations);
Map<String, Object> result = new JSONObject();
result.put("filter", filterResults);
return new SearchApiResult().setData(result);
}
@Override
public void addParamsToParamMap(Map<String, String> paramMap) {
// TODO Auto-generated method stub
public SearchApiResult aggregations(Map<String, String> paramMap) {
try {
// 0、添加默认参数
this.addParamsToParamMap(paramMap);
// 1、获取通用筛选项
CompletableFuture<JSONObject> commonFiltersFuture = CompletableFuture.supplyAsync(() -> {
return splitSelectionsService.getCommonFilters(paramMap);
}, executorService);
// 2、获取推荐的品牌
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);
}
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.service.servicenew.scene;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
... ... @@ -53,6 +54,12 @@ public class FuzzySceneService extends AbstractSceneService {
super.addDefaultParamsToParamMap(paramMap);
paramMap.put(SearchRequestParams.PARAM_SEARCH_NEED_SUGGESTION, "Y");// 返回建议词
paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_SECKILL, "Y");// 包含秒杀商品
paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "Y");// 包含全球购
}
@Override
public void setExecutorService() {
this.executorService = Executors.newFixedThreadPool(100);
}
/**
... ...
... ... @@ -57,4 +57,9 @@ public class NewArrivalSceneService extends AbstractSceneService{
// TODO Auto-generated method stub
}
@Override
public void setExecutorService() {
// TODO Auto-generated method stub
}
}
... ...
... ... @@ -56,4 +56,9 @@ public class ShopSceneService extends AbstractSceneService {
public void addParamsToParamMap(Map<String, String> paramMap) {
// TODO Auto-generated method stub
}
@Override
public void setExecutorService() {
// TODO Auto-generated method stub
}
}
... ...
... ... @@ -5,6 +5,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
... ... @@ -21,6 +22,7 @@ import com.yoho.search.service.servicenew.IProductIndexService;
import com.yoho.search.service.servicenew.scene.common.AbstractSceneService;
import com.yoho.search.service.servicenew.scene.common.SceneProductListService;
import com.yoho.search.service.servicenew.scene.common.SceneSelectionsService;
import com.yoho.search.service.utils.SearchRequestParams;
import com.yoho.search.service.vo.SearchApiResult;
@Service
... ... @@ -43,13 +45,24 @@ public class SortSceneService extends AbstractSceneService {
public String pageId() {
return SearchPageIdDefine.PAGE_ID_SORT;
}
@Override
public void addParamsToParamMap(Map<String, String> paramMap) {
super.addDefaultParamsToParamMap(paramMap);
paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "Y");// 包含全球购
}
@Override
public void setExecutorService() {
this.executorService = Executors.newFixedThreadPool(100);
}
/**
* @特殊参数:
* @1、paramNum-获取规则数量的接口
* @2、firstProductSkn-第一个展示的skn
*/
@Override
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 0、添加默认参数
... ...
package com.yoho.search.service.servicenew.scene;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -16,7 +18,7 @@ import com.yoho.search.service.utils.SearchApiResultUtils;
import com.yoho.search.service.vo.SearchApiResult;
@Service
public class ZqSceneService extends AbstractSceneService{
public class ZqSceneService extends AbstractSceneService {
private static final Logger logger = LoggerFactory.getLogger(ZqSceneService.class);
... ... @@ -31,6 +33,16 @@ public class ZqSceneService extends AbstractSceneService{
}
@Override
public void addParamsToParamMap(Map<String, String> paramMap) {
super.addDefaultParamsToParamMap(paramMap);
}
@Override
public void setExecutorService() {
this.executorService = Executors.newFixedThreadPool(50);
}
@Override
public SearchApiResult productList(Map<String, String> paramMap) {
try {
return splitProductListService.productList(paramMap);
... ... @@ -42,20 +54,30 @@ public class ZqSceneService extends AbstractSceneService{
@Override
public SearchApiResult aggregations(Map<String, String> paramMap) {
// 1、获取通用筛选项
JSONObject commonFilters = splitSelectionsService.getCommonFilters(paramMap);
// 2、获取推荐的品牌
Object recommendBrand = splitSelectionsService.getRecommendBrands(paramMap);
if (recommendBrand != null) {
commonFilters.put("recommendBrand", recommendBrand);
try {
// 0、添加默认参数
this.addParamsToParamMap(paramMap);
// 1、获取通用筛选项
CompletableFuture<JSONObject> commonFiltersFuture = CompletableFuture.supplyAsync(() -> {
return splitSelectionsService.getCommonFilters(paramMap);
}, executorService);
// 2、获取推荐的品牌
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("ZqAggregations Exception").setCode(500);
}
Map<String, Object> result = new JSONObject();
result.put("filter", commonFilters);
return new SearchApiResult().setData(result);
}
@Override
public void addParamsToParamMap(Map<String, String> paramMap) {
// TODO Auto-generated method stub
}
}
... ...
... ... @@ -2,7 +2,6 @@ package com.yoho.search.service.servicenew.scene.common;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.commons.lang.StringUtils;
... ... @@ -11,32 +10,33 @@ import com.yoho.search.service.vo.SearchApiResult;
public abstract class AbstractSceneService {
protected static ExecutorService executorService = Executors.newFixedThreadPool(500);
/**
* 场景化的默认参数
*
* @param paramMap
*/
protected void addDefaultParamsToParamMap(Map<String, String> paramMap) {
paramMap.put(SearchRequestParams.PARAM_SEARCH_PAGEID, this.pageId());
paramMap.put(SearchRequestParams.PARAM_SEARCH_PAGEID, this.pageId());// 根据场景划分的页面id
paramMap.put(SearchRequestParams.PARAM_SEARCH_GLOBAL_FILTER_BRAND, "Y");// 页面屏蔽
paramMap.put(SearchRequestParams.PARAM_SEARCH_STATUS, "1");// 上架
paramMap.put(SearchRequestParams.PARAM_SEARCH_STOCKNUM, "1");// 有库存
paramMap.put(SearchRequestParams.PARAM_SEARCH_SHOWSOLDOUT, "1");// 显示售罄商品
paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL, "Y");// 包含全球购
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISOUTLETS, "2");// 非奥莱
paramMap.put("attribute_not", "2");// 非赠品
// paramMap.put("sale", "Y");// 没用的参数
}
protected int getPage(Map<String, String> paramMap) {
int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
return page;
}
protected ExecutorService executorService;
public abstract void setExecutorService();
public abstract void addParamsToParamMap(Map<String, String> paramMap);
public abstract String pageId();
public abstract SearchApiResult productList(Map<String, String> paramMap);
... ...
... ... @@ -77,6 +77,18 @@ public class SceneSelectionsService extends BaseService {
}
return builders;
}
private JSONObject getFilterResults(List<IAggregation> aggregations, Map<String, Aggregation> aggMaps) {
JSONObject filter = new JSONObject();
for (IAggregation aggregation : aggregations) {
Object response = aggregation.getAggregationResponseMap(aggMaps);
if (response == null) {
continue;
}
filter.put(aggregation.filterName(), response);
}
return filter;
}
/**
* @聚合选项:
... ... @@ -164,34 +176,6 @@ public class SceneSelectionsService extends BaseService {
}
/**
* 优惠券页面时用的筛选项
* @param paramMap
* @return
*/
public List<IAggregation> getCouponAggregations(Map<String, String> paramMap) {
List<IAggregation> aggregations = new ArrayList<>();
// 1)性别
aggregations.add(aggregationFactoryService.getGenderNewAggregation());
// 2)品牌
aggregations.add(aggregationFactoryService.getBrandAggregation(paramMap));
// 3)人群
aggregations.add(aggregationFactoryService.getAgeLevelAggregation());
// 4)品类
aggregations.add(aggregationFactoryService.getSortGroupAggregation(paramMap));
// 5)颜色
aggregations.add(aggregationFactoryService.getColorAggregation(paramMap));
// 6)尺码
aggregations.add(aggregationFactoryService.getSizeAggregation());
// 7)价格
aggregations.add(aggregationFactoryService.getPriceAggregation());
// 8)折扣
aggregations.add(aggregationFactoryService.getDiscountAggregation());
// 9)风格
aggregations.add(aggregationFactoryService.getStyleAggregation(paramMap));
return aggregations;
}
/**
* 店铺、新频到着的筛选项列表
* @param paramMap
* @return
... ...