Authored by hugufei

拆包

Showing 19 changed files with 546 additions and 503 deletions
... ... @@ -5,7 +5,8 @@ import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.guang.ProductListService;
import com.yoho.search.service.scene.guang.ProductListWithPhraseService;
import com.yoho.search.service.scene.tools.ProductListDslService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
... ... @@ -20,73 +21,61 @@ import java.util.Map;
@Controller
public class ProductListController {
@Autowired
private ProductListService productListService;
@Autowired
private ProductListSwitchService productListSwitchService;
@Autowired
private ProductListWithPhraseService productListWithPhraseService;
@Autowired
private ProductListSwitchService productListSwitchService;
/**
* 获取商品列表-支持个性化降级
*
* @return
*/
@PersionalRateLimit(isOrderUseable = true)
@RequestMapping(method = RequestMethod.GET, value = "/productindex/productList")
@ResponseBody
public SearchApiResult productList(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return productListSwitchService.productList(paramMap);
}
/**
* 获取商品列表-支持个性化降级
*
* @return
*/
@PersionalRateLimit(isOrderUseable = true)
@RequestMapping(method = RequestMethod.GET, value = "/productindex/productList")
@ResponseBody
public SearchApiResult productList(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return productListSwitchService.productList(paramMap);
}
/**
* post的方式获取商品列表-不支持个性化
*
* @return
*/
@RequestMapping(method = RequestMethod.POST, value = "/productindex/productListByPost")
@ResponseBody
public SearchApiResult productListByPost(@RequestBody JSONObject param) {
Map<String, String> paramMap = this.getParamMap(param);
paramMap.remove("uid");
return productListSwitchService.productList(paramMap);
}
/**
* post的方式获取商品列表-不支持个性化
*
* @return
*/
@RequestMapping(method = RequestMethod.POST, value = "/productindex/productListByPost")
@ResponseBody
public SearchApiResult productListByPost(@RequestBody JSONObject param) {
Map<String, String> paramMap = this.getParamMap(param);
paramMap.remove("uid");
return productListSwitchService.productList(paramMap);
}
/**
* 获取商品列表-不支持个性化
*
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/productindex/productListWithPhrase")
@ResponseBody
public SearchApiResult productListWithPhrase(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
paramMap.remove("uid");
return productListService.productListWithPhrase(paramMap);
}
/**
* 获取商品列表-不支持个性化
*
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/productindex/productListWithPhrase")
@ResponseBody
public SearchApiResult productListWithPhrase(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
paramMap.remove("uid");
return productListWithPhraseService.productListWithPhrase(paramMap);
}
private Map<String, String> getParamMap(JSONObject param) {
Map<String, String> paramMap = new HashMap<String, String>();
for (Map.Entry<String, Object> entry : param.entrySet()) {
try {
Object value = entry.getValue();
String valueString = value == null ? null : value.toString();
paramMap.put(entry.getKey(), valueString);
} catch (Exception e) {
}
}
return paramMap;
}
/**
* 打印获取商品列表的ES的dsl的工具接口
*
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/dsl/productList")
@ResponseBody
public SearchApiResult getESDsl(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return productListService.getESDsl(paramMap);
}
private Map<String, String> getParamMap(JSONObject param) {
Map<String, String> paramMap = new HashMap<String, String>();
for (Map.Entry<String, Object> entry : param.entrySet()) {
try {
Object value = entry.getValue();
String valueString = value == null ? null : value.toString();
paramMap.put(entry.getKey(), valueString);
} catch (Exception e) {
}
}
return paramMap;
}
}
... ...
package com.yoho.search.restapi.tools;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.tools.ProductListDslService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@RestController
public class ProductListDslController {
@Autowired
private ProductListDslService productListDslService;
/**
* 打印获取商品列表的ES的dsl的工具接口
*
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/dsl/productList")
@ResponseBody
public SearchApiResult getESDsl(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return productListDslService.getESDsl(paramMap);
}
}
... ...
... ... @@ -6,8 +6,8 @@ import com.yoho.search.models.SearchApiResult;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.common.SceneRecommendBrandsService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -26,7 +26,7 @@ public class BrandSceneService extends AbstractSceneService {
@Autowired
private SceneSelectionsService sceneSelectionsService;
@Autowired
private SceneRecommendBrandsService sceneRecommendBrandsService;
private RecommendBrandsService recommendBrandsService;
@Override
public String pageId() {
... ... @@ -66,7 +66,7 @@ public class BrandSceneService extends AbstractSceneService {
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
sceneRecommendBrandsService.getRecommendBrands(paramMap, result);
recommendBrandsService.getRecommendBrands(paramMap, result);
return result;
} catch (Exception e) {
logger.error("[func=BrandAggregations][params=" + paramMap + "]", e);
... ...
... ... @@ -18,8 +18,8 @@ import com.yoho.search.service.index.SizeIndexBaseService;
import com.yoho.search.service.helper.SearchParamHelper;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.common.SceneRecommendBrandsService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
... ... @@ -53,7 +53,7 @@ public class BreakSizeSceneService extends AbstractSceneService {
@Autowired
private SceneSelectionsService sceneSelectionsService;
@Autowired
private SceneRecommendBrandsService sceneRecommendBrandsService;
private RecommendBrandsService recommendBrandsService;
/**
* 为断码区添加默认的过滤条件
... ... @@ -92,7 +92,7 @@ public class BreakSizeSceneService extends AbstractSceneService {
// 2、返回聚合结果
List<IAggregation> aggregation = sceneSelectionsService.getBreakSizeAggregations(paramMap);
SearchApiResult result = sceneSelectionsService.aggregations(paramMap, aggregation);
sceneRecommendBrandsService.getRecommendBrands(paramMap, result);
recommendBrandsService.getRecommendBrands(paramMap, result);
return result;
} catch (Exception e) {
logger.error("[func=Couponaggregations][params=" + paramMap + "]", e);
... ...
... ... @@ -8,8 +8,8 @@ import com.yoho.search.service.scene.img.SknImgsResponse;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.common.SceneRecommendBrandsService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
import com.yoho.search.service.scene.img.SknImgsCacheBean;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -30,7 +30,7 @@ public class CommonSceneService extends AbstractSceneService {
@Autowired
private SceneSelectionsService sceneSelectionsService;
@Autowired
private SceneRecommendBrandsService sceneRecommendBrandsService;
private RecommendBrandsService recommendBrandsService;
@Autowired
private SknImgsCacheBean sknImgsCacheBean;
... ... @@ -64,7 +64,7 @@ public class CommonSceneService extends AbstractSceneService {
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
sceneRecommendBrandsService.getRecommendBrands(paramMap, result);
recommendBrandsService.getRecommendBrands(paramMap, result);
return result;
} catch (Exception e) {
logger.error("[func=Couponaggregations][params=" + paramMap + "]", e);
... ...
... ... @@ -5,8 +5,8 @@ import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.common.SceneRecommendBrandsService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -24,7 +24,7 @@ public class CouponSceneService extends AbstractSceneService {
@Autowired
private SceneSelectionsService sceneSelectionsService;
@Autowired
private SceneRecommendBrandsService sceneRecommendBrandsService;
private RecommendBrandsService recommendBrandsService;
@Override
public String pageId() {
... ... @@ -57,7 +57,7 @@ public class CouponSceneService extends AbstractSceneService {
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
sceneRecommendBrandsService.getRecommendBrands(paramMap, result);
recommendBrandsService.getRecommendBrands(paramMap, result);
return result;
} catch (Exception e) {
logger.error("[func=Couponaggregations][params=" + paramMap + "]", e);
... ...
... ... @@ -4,7 +4,7 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import com.yoho.search.service.scene.common.SceneRecommendBrandsService;
import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -18,7 +18,7 @@ import com.yoho.search.models.SearchApiResult;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
@Service
public class NewArrivalSceneService extends AbstractSceneService {
... ... @@ -30,7 +30,7 @@ public class NewArrivalSceneService extends AbstractSceneService {
@Autowired
private SceneSelectionsService sceneSelectionsService;
@Autowired
private SceneRecommendBrandsService sceneRecommendBrandsService;
private RecommendBrandsService recommendBrandsService;
@Override
public String pageId() {
... ... @@ -66,7 +66,7 @@ public class NewArrivalSceneService extends AbstractSceneService {
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
sceneRecommendBrandsService.getRecommendBrands(paramMap, result);
recommendBrandsService.getRecommendBrands(paramMap, result);
return result;
} catch (Exception e) {
logger.error("[func=NewArrivalAggregations][params=" + paramMap + "]", e);
... ...
... ... @@ -2,7 +2,7 @@ package com.yoho.search.service.scene;
import java.util.Map;
import com.yoho.search.service.scene.common.SceneRecommendBrandsService;
import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -15,7 +15,7 @@ import com.yoho.search.models.SearchApiResult;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
@Service
public class ProductPoolSceneService extends AbstractSceneService {
... ... @@ -27,7 +27,7 @@ public class ProductPoolSceneService extends AbstractSceneService {
@Autowired
private SceneSelectionsService sceneSelectionsService;
@Autowired
private SceneRecommendBrandsService sceneRecommendBrandsService;
private RecommendBrandsService recommendBrandsService;
/**
*
... ... @@ -91,7 +91,7 @@ public class ProductPoolSceneService extends AbstractSceneService {
try {
this.addParamsToParamMap(paramMap);
SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
sceneRecommendBrandsService.getRecommendBrands(paramMap, result);
recommendBrandsService.getRecommendBrands(paramMap, result);
return result;
} catch (Exception e) {
logger.error("[func=PoolAggregations][params=" + paramMap + "]", e);
... ...
... ... @@ -17,7 +17,7 @@ import com.yoho.search.models.SearchApiResult;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
@Service
public class ReducePriceSceneService extends AbstractSceneService {
... ...
... ... @@ -3,7 +3,7 @@ package com.yoho.search.service.scene;
import java.util.List;
import java.util.Map;
import com.yoho.search.service.scene.common.SceneRecommendBrandsService;
import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -17,7 +17,7 @@ import com.yoho.search.models.SearchApiResult;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
@Service
public class ShopSceneService extends AbstractSceneService {
... ... @@ -29,7 +29,7 @@ public class ShopSceneService extends AbstractSceneService {
@Autowired
private SceneSelectionsService sceneSelectionsService;
@Autowired
private SceneRecommendBrandsService sceneRecommendBrandsService;
private RecommendBrandsService recommendBrandsService;
@Override
public String pageId() {
... ... @@ -69,7 +69,7 @@ public class ShopSceneService extends AbstractSceneService {
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
sceneRecommendBrandsService.getRecommendBrands(paramMap, result);
recommendBrandsService.getRecommendBrands(paramMap, result);
return result;
} catch (Exception e) {
logger.error("[func=ShopAggregations][params=" + paramMap + "]", e);
... ...
... ... @@ -7,8 +7,8 @@ import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.aggregations.SceneAggregationsHelper;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.common.SceneRecommendBrandsService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -32,7 +32,7 @@ public class SortSceneService extends AbstractSceneService {
@Autowired
private SceneAggregationsHelper sceneAggregationsHelper;
@Autowired
private SceneRecommendBrandsService sceneRecommendBrandsService;
private RecommendBrandsService recommendBrandsService;
@Override
public String pageId() {
... ... @@ -112,7 +112,7 @@ public class SortSceneService extends AbstractSceneService {
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
sceneRecommendBrandsService.getRecommendBrands(paramMap, result);
recommendBrandsService.getRecommendBrands(paramMap, result);
return result;
} catch (Exception e) {
logger.error(e.getMessage(), e);
... ...
... ... @@ -2,7 +2,7 @@ package com.yoho.search.service.scene;
import java.util.Map;
import com.yoho.search.service.scene.common.SceneRecommendBrandsService;
import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -15,7 +15,7 @@ import com.yoho.search.models.SearchApiResult;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
@Service
public class ZqSceneService extends AbstractSceneService {
... ... @@ -27,7 +27,7 @@ public class ZqSceneService extends AbstractSceneService {
@Autowired
private SceneSelectionsService sceneSelectionsService;
@Autowired
private SceneRecommendBrandsService sceneRecommendBrandsService;
private RecommendBrandsService recommendBrandsService;
@Override
public String pageId() {
... ... @@ -67,7 +67,7 @@ public class ZqSceneService extends AbstractSceneService {
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
sceneRecommendBrandsService.getRecommendBrands(paramMap, result);
recommendBrandsService.getRecommendBrands(paramMap, result);
return result;
} catch (Exception e) {
logger.error("[func=zqProductList][params=" + paramMap + "]", e);
... ...
package com.yoho.search.service.scene.common;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.cache.log.SearchCacheMatchLogger;
import com.yoho.search.cache.model.SearchCache;
import com.yoho.search.cache.beans.AbstractCacheAbleService;
import com.yoho.search.core.es.agg.IAggregation;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.aggregations.impls.AggregationFactory;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.service.helper.SearchParamHelper;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class SceneSelectionsService extends AbstractCacheAbleService {
private static final Logger logger = LoggerFactory.getLogger(SceneSelectionsService.class);
@Autowired
private SearchParamHelper searchParamHelper;
@Autowired
private SearchCommonService searchCommonService;
@Autowired
private AggregationFactory aggregationFactory;
@Override
public SearchCache getSearchCache() {
return searchCacheFactory.getSceneAggregationsCache();
}
/**
* @新版筛选器的聚合选项:
* @1、全球购
* @2、促销
* @3、全部的品牌 +喜欢的品牌【个性化的】
* @4、人群
* @5、品类
* @6、性别
* @7、价格
* @8、折扣
* @9、颜色
* @10、尺码
* @11、风格
*/
public List<IAggregation> getCommonAggregations(Map<String, String> paramMap) {
List<IAggregation> aggregations = new ArrayList<>();
// 1)专区名称
aggregations.add(aggregationFactory.getZqNameAggregation(1000));
// 2)全球购
aggregations.add(aggregationFactory.getIsGlobalAggregation());
// 3)品牌
aggregations.add(aggregationFactory.getBrandAggregation(paramMap));
// 4)人群
aggregations.add(aggregationFactory.getAgeLevelAggregation());
// 5)品类
aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));
// 6)性别
aggregations.add(aggregationFactory.getGenderNewAggregation());
// 7)价格
aggregations.add(aggregationFactory.getPriceAggregation());
// 8)折扣
aggregations.add(aggregationFactory.getDiscountAggregation());
// 9)颜色
aggregations.add(aggregationFactory.getColorAggregation(paramMap));
// 10)尺码
aggregations.add(aggregationFactory.getSizeAggregation());
// 11)风格
aggregations.add(aggregationFactory.getStyleAggregation(paramMap));
return aggregations;
}
/**
* @断码区的聚合选项:
* @比其他的场景少了品类和尺码的筛选项
*/
public List<IAggregation> getBreakSizeAggregations(Map<String, String> paramMap) {
List<IAggregation> aggregations = new ArrayList<>();
// 1)专区名称
aggregations.add(aggregationFactory.getZqNameAggregation(1000));
// 2)全球购
aggregations.add(aggregationFactory.getIsGlobalAggregation());
// 3)品牌
aggregations.add(aggregationFactory.getBrandAggregation(paramMap));
// 4)人群
aggregations.add(aggregationFactory.getAgeLevelAggregation());
// 5)性别
aggregations.add(aggregationFactory.getGenderNewAggregation());
// 6)价格
aggregations.add(aggregationFactory.getPriceAggregation());
// 7)折扣
aggregations.add(aggregationFactory.getDiscountAggregation());
// 8)颜色
aggregations.add(aggregationFactory.getColorAggregation(paramMap));
// 9)风格
aggregations.add(aggregationFactory.getStyleAggregation(paramMap));
return aggregations;
}
/**
* 最新降价的筛选项
*
* @param paramMap
* @return
*/
public List<IAggregation> getReducePriceAggregations(Map<String, String> paramMap) {
List<IAggregation> aggregations = new ArrayList<>();
// 1)性别
aggregations.add(aggregationFactory.getGenderNewAggregation());
// 2)品牌
aggregations.add(aggregationFactory.getBrandAggregation(paramMap));
// 3)品类
aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));
// 4)颜色
aggregations.add(aggregationFactory.getColorAggregation(paramMap));
// 5)尺码
aggregations.add(aggregationFactory.getSizeAggregation());
// 6)价格
aggregations.add(aggregationFactory.getPriceAggregation());
// 7)折扣
aggregations.add(aggregationFactory.getDiscountAggregation());
// 8)风格
aggregations.add(aggregationFactory.getStyleAggregation(paramMap));
return aggregations;
}
/**
* 老的店铺的筛选项
*
* @param paramMap
* @return
*/
public List<IAggregation> getShopOldAggregations(Map<String, String> paramMap) {
List<IAggregation> aggregations = new ArrayList<>();
// 1)性别
aggregations.add(aggregationFactory.getGenderNewAggregation());
// 2)品牌
aggregations.add(aggregationFactory.getBrandAggregation(paramMap));
// 3)品类
aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));
// 4)颜色
aggregations.add(aggregationFactory.getColorAggregation(paramMap));
// 5)尺码
aggregations.add(aggregationFactory.getSizeAggregation());
// 6)价格
aggregations.add(aggregationFactory.getPriceAggregation());
// 7)折扣
aggregations.add(aggregationFactory.getDiscountAggregation());
// 8)风格
aggregations.add(aggregationFactory.getStyleAggregation(paramMap));
return aggregations;
}
/**
* 老的新品到着的筛选项
*
* @param paramMap
* @return
*/
public List<IAggregation> getNewArrivalOldAggregations(Map<String, String> paramMap) {
List<IAggregation> aggregations = new ArrayList<>();
// 1)性别
aggregations.add(aggregationFactory.getGenderNewAggregation());
// 2)品牌
aggregations.add(aggregationFactory.getBrandAggregation(paramMap));
// 3)品类
aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));
// 4)颜色
aggregations.add(aggregationFactory.getColorAggregation(paramMap));
// 5)尺码
aggregations.add(aggregationFactory.getSizeAggregation());
// 6)价格
aggregations.add(aggregationFactory.getPriceAggregation());
// 7)折扣
aggregations.add(aggregationFactory.getDiscountAggregation());
// 8)风格
aggregations.add(aggregationFactory.getStyleAggregation(paramMap));
return aggregations;
}
private List<AbstractAggregationBuilder<?>> getAggregationBuilders(List<IAggregation> aggregations) {
List<AbstractAggregationBuilder<?>> builders = new ArrayList<>();
for (IAggregation aggregation : aggregations) {
builders.add(aggregation.getBuilder());
}
return builders;
}
private JSONObject genFilterResult(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;
}
private JSONObject getFiltersResults(Map<String, String> paramMap, SearchParam searchParam, List<IAggregation> aggregations) {
try {
// 1)构造聚合报文
searchParam.setAggregationBuilders(this.getAggregationBuilders(aggregations));
// 2)构造其他参数
final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
searchParam.setOffset(100);// just for cache
searchParam.setSize(0);
// 先从缓存里取,取到则处理下缓存结果并直接返回
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(this.searchCache, productIndexName, searchParam);
if (cacheObject != null) {
SearchCacheMatchLogger.doSearchCacheMatchLog("/scene/aggregations.json", paramMap);
return cacheObject;
}
// 调用ES
SearchResult searchResult = searchCommonService.doSearch(productIndexName, searchParam);
Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
if (aggMaps == null) {
return null;
}
// 构造返回结果
JSONObject dataMap = this.genFilterResult(aggregations, aggMaps);
searchCacheService.addJSONObjectToCache(this.searchCache, productIndexName, searchParam, dataMap);
return dataMap;
} catch (Exception e) {
logger.error("[func=getFiltersResults][params=" + paramMap + "]", e);
return new JSONObject();
}
}
private JSONObject getFiltersResult(Map<String, String> paramMap, List<IAggregation> aggregations, BoolQueryBuilder mustFilter) {
try {
Map<String, String> newParamMap = new HashMap<String, String>(paramMap);
SearchParam searchParam = searchParamHelper.buildWithMustFilter(newParamMap, mustFilter);
return this.getFiltersResults(paramMap, searchParam, aggregations);
} catch (Exception e) {
logger.error("[func=SceneSelectionsService][params=" + paramMap + "]", e);
return new JSONObject();
}
}
public SearchApiResult aggregations(Map<String, String> paramMap) throws Exception {
List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap);
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, BoolQueryBuilder mustFilter) throws Exception {
List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap);
return this.aggregations(paramMap, commonAggregations, mustFilter);
}
private SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations, BoolQueryBuilder mustFilter) throws Exception {
// 1、获取通用筛选项
JSONObject commonFilters = this.getFiltersResult(paramMap, aggregations, mustFilter);
Map<String, Object> result = new JSONObject();
result.put("filter", commonFilters);
return new SearchApiResult().setData(result);
}
}
package com.yoho.search.service.scene.aggregations;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.cache.log.SearchCacheMatchLogger;
import com.yoho.search.cache.model.SearchCache;
import com.yoho.search.cache.beans.AbstractCacheAbleService;
import com.yoho.search.core.es.agg.IAggregation;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.aggregations.impls.AggregationFactory;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.service.helper.SearchParamHelper;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class SceneSelectionsService extends AbstractCacheAbleService {
private static final Logger logger = LoggerFactory.getLogger(SceneSelectionsService.class);
@Autowired
private SearchParamHelper searchParamHelper;
@Autowired
private SearchCommonService searchCommonService;
@Autowired
private AggregationFactory aggregationFactory;
@Override
public SearchCache getSearchCache() {
return searchCacheFactory.getSceneAggregationsCache();
}
/**
* @新版筛选器的聚合选项:
* @1、全球购
* @2、促销
* @3、全部的品牌 +喜欢的品牌【个性化的】
* @4、人群
* @5、品类
* @6、性别
* @7、价格
* @8、折扣
* @9、颜色
* @10、尺码
* @11、风格
*/
public List<IAggregation> getCommonAggregations(Map<String, String> paramMap) {
List<IAggregation> aggregations = new ArrayList<>();
// 1)专区名称
aggregations.add(aggregationFactory.getZqNameAggregation(1000));
// 2)全球购
aggregations.add(aggregationFactory.getIsGlobalAggregation());
// 3)品牌
aggregations.add(aggregationFactory.getBrandAggregation(paramMap));
// 4)人群
aggregations.add(aggregationFactory.getAgeLevelAggregation());
// 5)品类
aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));
// 6)性别
aggregations.add(aggregationFactory.getGenderNewAggregation());
// 7)价格
aggregations.add(aggregationFactory.getPriceAggregation());
// 8)折扣
aggregations.add(aggregationFactory.getDiscountAggregation());
// 9)颜色
aggregations.add(aggregationFactory.getColorAggregation(paramMap));
// 10)尺码
aggregations.add(aggregationFactory.getSizeAggregation());
// 11)风格
aggregations.add(aggregationFactory.getStyleAggregation(paramMap));
return aggregations;
}
/**
* @断码区的聚合选项:
* @比其他的场景少了品类和尺码的筛选项
*/
public List<IAggregation> getBreakSizeAggregations(Map<String, String> paramMap) {
List<IAggregation> aggregations = new ArrayList<>();
// 1)专区名称
aggregations.add(aggregationFactory.getZqNameAggregation(1000));
// 2)全球购
aggregations.add(aggregationFactory.getIsGlobalAggregation());
// 3)品牌
aggregations.add(aggregationFactory.getBrandAggregation(paramMap));
// 4)人群
aggregations.add(aggregationFactory.getAgeLevelAggregation());
// 5)性别
aggregations.add(aggregationFactory.getGenderNewAggregation());
// 6)价格
aggregations.add(aggregationFactory.getPriceAggregation());
// 7)折扣
aggregations.add(aggregationFactory.getDiscountAggregation());
// 8)颜色
aggregations.add(aggregationFactory.getColorAggregation(paramMap));
// 9)风格
aggregations.add(aggregationFactory.getStyleAggregation(paramMap));
return aggregations;
}
/**
* 最新降价的筛选项
*
* @param paramMap
* @return
*/
public List<IAggregation> getReducePriceAggregations(Map<String, String> paramMap) {
List<IAggregation> aggregations = new ArrayList<>();
// 1)性别
aggregations.add(aggregationFactory.getGenderNewAggregation());
// 2)品牌
aggregations.add(aggregationFactory.getBrandAggregation(paramMap));
// 3)品类
aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));
// 4)颜色
aggregations.add(aggregationFactory.getColorAggregation(paramMap));
// 5)尺码
aggregations.add(aggregationFactory.getSizeAggregation());
// 6)价格
aggregations.add(aggregationFactory.getPriceAggregation());
// 7)折扣
aggregations.add(aggregationFactory.getDiscountAggregation());
// 8)风格
aggregations.add(aggregationFactory.getStyleAggregation(paramMap));
return aggregations;
}
/**
* 老的店铺的筛选项
*
* @param paramMap
* @return
*/
public List<IAggregation> getShopOldAggregations(Map<String, String> paramMap) {
List<IAggregation> aggregations = new ArrayList<>();
// 1)性别
aggregations.add(aggregationFactory.getGenderNewAggregation());
// 2)品牌
aggregations.add(aggregationFactory.getBrandAggregation(paramMap));
// 3)品类
aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));
// 4)颜色
aggregations.add(aggregationFactory.getColorAggregation(paramMap));
// 5)尺码
aggregations.add(aggregationFactory.getSizeAggregation());
// 6)价格
aggregations.add(aggregationFactory.getPriceAggregation());
// 7)折扣
aggregations.add(aggregationFactory.getDiscountAggregation());
// 8)风格
aggregations.add(aggregationFactory.getStyleAggregation(paramMap));
return aggregations;
}
/**
* 老的新品到着的筛选项
*
* @param paramMap
* @return
*/
public List<IAggregation> getNewArrivalOldAggregations(Map<String, String> paramMap) {
List<IAggregation> aggregations = new ArrayList<>();
// 1)性别
aggregations.add(aggregationFactory.getGenderNewAggregation());
// 2)品牌
aggregations.add(aggregationFactory.getBrandAggregation(paramMap));
// 3)品类
aggregations.add(aggregationFactory.getSortGroupAggregation(paramMap));
// 4)颜色
aggregations.add(aggregationFactory.getColorAggregation(paramMap));
// 5)尺码
aggregations.add(aggregationFactory.getSizeAggregation());
// 6)价格
aggregations.add(aggregationFactory.getPriceAggregation());
// 7)折扣
aggregations.add(aggregationFactory.getDiscountAggregation());
// 8)风格
aggregations.add(aggregationFactory.getStyleAggregation(paramMap));
return aggregations;
}
private List<AbstractAggregationBuilder<?>> getAggregationBuilders(List<IAggregation> aggregations) {
List<AbstractAggregationBuilder<?>> builders = new ArrayList<>();
for (IAggregation aggregation : aggregations) {
builders.add(aggregation.getBuilder());
}
return builders;
}
private JSONObject genFilterResult(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;
}
private JSONObject getFiltersResults(Map<String, String> paramMap, SearchParam searchParam, List<IAggregation> aggregations) {
try {
// 1)构造聚合报文
searchParam.setAggregationBuilders(this.getAggregationBuilders(aggregations));
// 2)构造其他参数
final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
searchParam.setOffset(100);// just for cache
searchParam.setSize(0);
// 先从缓存里取,取到则处理下缓存结果并直接返回
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(this.searchCache, productIndexName, searchParam);
if (cacheObject != null) {
SearchCacheMatchLogger.doSearchCacheMatchLog("/scene/aggregations.json", paramMap);
return cacheObject;
}
// 调用ES
SearchResult searchResult = searchCommonService.doSearch(productIndexName, searchParam);
Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
if (aggMaps == null) {
return null;
}
// 构造返回结果
JSONObject dataMap = this.genFilterResult(aggregations, aggMaps);
searchCacheService.addJSONObjectToCache(this.searchCache, productIndexName, searchParam, dataMap);
return dataMap;
} catch (Exception e) {
logger.error("[func=getFiltersResults][params=" + paramMap + "]", e);
return new JSONObject();
}
}
private JSONObject getFiltersResult(Map<String, String> paramMap, List<IAggregation> aggregations, BoolQueryBuilder mustFilter) {
try {
Map<String, String> newParamMap = new HashMap<String, String>(paramMap);
SearchParam searchParam = searchParamHelper.buildWithMustFilter(newParamMap, mustFilter);
return this.getFiltersResults(paramMap, searchParam, aggregations);
} catch (Exception e) {
logger.error("[func=SceneSelectionsService][params=" + paramMap + "]", e);
return new JSONObject();
}
}
public SearchApiResult aggregations(Map<String, String> paramMap) throws Exception {
List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap);
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, BoolQueryBuilder mustFilter) throws Exception {
List<IAggregation> commonAggregations = this.getCommonAggregations(paramMap);
return this.aggregations(paramMap, commonAggregations, mustFilter);
}
private SearchApiResult aggregations(Map<String, String> paramMap, List<IAggregation> aggregations, BoolQueryBuilder mustFilter) throws Exception {
// 1、获取通用筛选项
JSONObject commonFilters = this.getFiltersResult(paramMap, aggregations, mustFilter);
Map<String, Object> result = new JSONObject();
result.put("filter", commonFilters);
return new SearchApiResult().setData(result);
}
}
... ...
package com.yoho.search.service.scene.common;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.yoho.search.core.personalized.models.SortBrand;
import com.yoho.search.core.personalized.models.UserPersonalFactorRspNew;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.common.SearchRequestParams;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.yoho.search.service.recall.beans.persional.UserPersionalFactorComponent;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
public class SceneRecommendBrandsService {
@Autowired
private UserPersionalFactorComponent userPersionalFactorComponent;
public void getRecommendBrands(Map<String, String> paramMap, SearchApiResult result) {
if (result != null && result.getData() != null) {
JSONObject data = (JSONObject) result.getData();
JSONObject commonFilters = data.getJSONObject("filter");
if (commonFilters != null) {
queryRecommendBrandsNew(commonFilters, paramMap);
}
}
}
private void queryRecommendBrandsNew(JSONObject commonFilters, Map<String, String> paramMap) {
JSONArray recommendBrands = new JSONArray();
JSONArray brandList = commonFilters.getJSONArray("brand");
if (!CollectionUtils.isEmpty(brandList)) {
recommendBrands = queryRecommendBrands(paramMap, brandList);
}
commonFilters.put("recommendBrand", recommendBrands);
}
private JSONArray queryRecommendBrands(Map<String, String> paramMap, JSONArray brandList) {
List<JSONObject> brandListTemp = JSON.parseObject(brandList.toJSONString(), new TypeReference<List<JSONObject>>() {
});
Map<Integer, JSONObject> brandIdMap = brandListTemp.stream().collect(Collectors.toMap(e -> e.getInteger("id"), Function.identity(), (m1, m2) -> m2));
int uid = MapUtils.getIntValue(paramMap, "uid", 0);
String udid = MapUtils.getString(paramMap, "udid", "");
int recommendBrandCount = Integer.parseInt(paramMap.getOrDefault(SearchRequestParams.PARAM_SEARCH_VIEWNUM, "8"));
JSONArray recBrands = new JSONArray(recommendBrandCount);
UserPersonalFactorRspNew userFactor = userPersionalFactorComponent.queryUserPersionalFactor(uid, udid, null);
List<Integer> brandIds = new ArrayList<>();
if (userFactor != null && userFactor.getRealTimeSortBrandList()!=null) {
List<SortBrand> sortBrandList = new ArrayList<>(userFactor.getRealTimeSortBrandList());
for (SortBrand sortBrand : sortBrandList) {
if (recBrands.size() >= recommendBrandCount) {
break;
}
if (brandIds.contains(sortBrand.getBrandId())) {
continue;
}
JSONObject brand = brandIdMap.get(sortBrand.getBrandId());
if (brand != null) {
recBrands.add(brand);
brandIds.add(sortBrand.getBrandId());
}
}
}
if (recBrands.size() < recommendBrandCount) {
for (JSONObject brand : brandListTemp) {
if (recBrands.size() >= recommendBrandCount) {
break;
}
if (!brandIds.contains(brand.getInteger("id"))) {
recBrands.add(brand);
brandIds.add(brand.getInteger("id"));
}
}
}
return recBrands;
}
}
package com.yoho.search.service.scene.brandshop;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.yoho.search.core.personalized.models.SortBrand;
import com.yoho.search.core.personalized.models.UserPersonalFactorRspNew;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.common.SearchRequestParams;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.yoho.search.service.recall.beans.persional.UserPersionalFactorComponent;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
public class RecommendBrandsService {
@Autowired
private UserPersionalFactorComponent userPersionalFactorComponent;
public void getRecommendBrands(Map<String, String> paramMap, SearchApiResult result) {
if (result != null && result.getData() != null) {
JSONObject data = (JSONObject) result.getData();
JSONObject commonFilters = data.getJSONObject("filter");
if (commonFilters != null) {
queryRecommendBrandsNew(commonFilters, paramMap);
}
}
}
private void queryRecommendBrandsNew(JSONObject commonFilters, Map<String, String> paramMap) {
JSONArray recommendBrands = new JSONArray();
JSONArray brandList = commonFilters.getJSONArray("brand");
if (!CollectionUtils.isEmpty(brandList)) {
recommendBrands = queryRecommendBrands(paramMap, brandList);
}
commonFilters.put("recommendBrand", recommendBrands);
}
private JSONArray queryRecommendBrands(Map<String, String> paramMap, JSONArray brandList) {
List<JSONObject> brandListTemp = JSON.parseObject(brandList.toJSONString(), new TypeReference<List<JSONObject>>() {
});
Map<Integer, JSONObject> brandIdMap = brandListTemp.stream().collect(Collectors.toMap(e -> e.getInteger("id"), Function.identity(), (m1, m2) -> m2));
int uid = MapUtils.getIntValue(paramMap, "uid", 0);
String udid = MapUtils.getString(paramMap, "udid", "");
int recommendBrandCount = Integer.parseInt(paramMap.getOrDefault(SearchRequestParams.PARAM_SEARCH_VIEWNUM, "8"));
JSONArray recBrands = new JSONArray(recommendBrandCount);
UserPersonalFactorRspNew userFactor = userPersionalFactorComponent.queryUserPersionalFactor(uid, udid, null);
List<Integer> brandIds = new ArrayList<>();
if (userFactor != null && userFactor.getRealTimeSortBrandList()!=null) {
List<SortBrand> sortBrandList = new ArrayList<>(userFactor.getRealTimeSortBrandList());
for (SortBrand sortBrand : sortBrandList) {
if (recBrands.size() >= recommendBrandCount) {
break;
}
if (brandIds.contains(sortBrand.getBrandId())) {
continue;
}
JSONObject brand = brandIdMap.get(sortBrand.getBrandId());
if (brand != null) {
recBrands.add(brand);
brandIds.add(sortBrand.getBrandId());
}
}
}
if (recBrands.size() < recommendBrandCount) {
for (JSONObject brand : brandListTemp) {
if (recBrands.size() >= recommendBrandCount) {
break;
}
if (!brandIds.contains(brand.getInteger("id"))) {
recBrands.add(brand);
brandIds.add(brand.getInteger("id"));
}
}
}
return recBrands;
}
}
... ...
... ... @@ -11,8 +11,8 @@ import com.yoho.search.service.helper.SearchKeyWordHelper;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.aggregations.SceneAggregationsHelper;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.common.SceneRecommendBrandsService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -42,7 +42,7 @@ public class FuzzySceneService extends AbstractSceneService {
@Autowired
private SceneAggregationsHelper sceneAggregationsHelper;
@Autowired
private SceneRecommendBrandsService sceneRecommendBrandsService;
private RecommendBrandsService recommendBrandsService;
@Autowired
private ProductListSwitchService productListSwitchService;
... ... @@ -118,7 +118,7 @@ public class FuzzySceneService extends AbstractSceneService {
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
sceneRecommendBrandsService.getRecommendBrands(paramMap, result);
recommendBrandsService.getRecommendBrands(paramMap, result);
return result;
} catch (Exception e) {
logger.error(e.getMessage(), e);
... ...
package com.yoho.search.service.scene.guang;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.core.es.utils.SearchParamUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.recall.beans.strategy.NotRecallTypeEnum;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.service.helper.ProductListHelper;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import com.yoho.search.service.recall.beans.strategy.NotRecallTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -21,30 +18,15 @@ import org.springframework.stereotype.Service;
import java.util.Map;
@Service
public class ProductListService {
public class ProductListWithPhraseService {
private static final Logger logger = LoggerFactory.getLogger(ProductListService.class);
private static final Logger logger = LoggerFactory.getLogger(ProductListWithPhraseService.class);
@Autowired
private SearchCommonService searchCommonService;
@Autowired
private ProductListHelper productListHelper;
public SearchApiResult getESDsl(Map<String, String> paramMap) {
logger.info("[func=getESDsl][param={}]", paramMap);
try {
SearchParam searchParam = productListHelper.buildProductListSearchParam(paramMap, true);
SearchSourceBuilder searchSourceBuilder = SearchParamUtils.genSearchSourceBuilderFromSearchParam(searchParam);
SearchApiResult searchApiResult = new SearchApiResult();
String results = searchSourceBuilder.toString();
searchApiResult.setData(JSON.parseObject(results));
logger.info("[func=getESDsl][dsl=\n{}]", searchApiResult.getData());
return searchApiResult;
} catch (Exception e) {
return SearchApiResultUtils.errorSearchApiResult("getESDsl", paramMap, e);
}
}
@SearchCacheAble(cacheInMinute = 10, cacheName = "PRODUCT_LIST_WITH_PHRASE")
public SearchApiResult productListWithPhrase(Map<String, String> paramMap) {
try {
... ...
... ... @@ -10,8 +10,8 @@ import com.yoho.search.service.helper.SearchKeyWordHelper;
import com.yoho.search.service.scene.list.ProductListSwitchService;
import com.yoho.search.service.scene.fuzzy.FuzzySceneService;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.common.SceneRecommendBrandsService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -34,7 +34,7 @@ public class MiniappFuzzySceneService extends AbstractSceneService {
@Autowired
private SceneSelectionsService sceneSelectionsService;
@Autowired
private SceneRecommendBrandsService sceneRecommendBrandsService;
private RecommendBrandsService recommendBrandsService;
@Autowired
private ProductListSwitchService productListSwitchService;
... ... @@ -96,7 +96,7 @@ public class MiniappFuzzySceneService extends AbstractSceneService {
// 2、返回聚合结果
SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
if(result!=null){
sceneRecommendBrandsService.getRecommendBrands(paramMap, result);
recommendBrandsService.getRecommendBrands(paramMap, result);
}
return result;
} catch (Exception e) {
... ...
... ... @@ -7,7 +7,7 @@ import java.util.Map;
import com.yoho.search.base.utils.CollectionUtils;
import com.yoho.search.models.RecommendPromotionAggVO;
import com.yoho.search.service.scene.aggregations.SceneAggregationsHelper;
import com.yoho.search.service.scene.common.SceneRecommendBrandsService;
import com.yoho.search.service.scene.brandshop.RecommendBrandsService;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
... ... @@ -31,7 +31,7 @@ import com.yoho.search.common.SearchCommonService;
import com.yoho.search.service.helper.SearchAfterCacheHelper;
import com.yoho.search.service.helper.SearchParamHelper;
import com.yoho.search.cache.beans.AbstractCacheAbleService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.scene.aggregations.SceneSelectionsService;
import com.yoho.search.service.scene.brandshop.BrandService;
import com.yoho.search.service.scene.aggregations.DiscountService;
import com.yoho.search.service.scene.aggregations.SearchSortGroupService;
... ... @@ -66,7 +66,7 @@ public class PromotionAggregationsService extends AbstractCacheAbleService {
@Autowired
private PromotionSceneHelper promotionSceneHelper;
@Autowired
private SceneRecommendBrandsService sceneRecommendBrandsService;
private RecommendBrandsService recommendBrandsService;
@Autowired
private SceneAggregationsHelper sceneAggregationsHelper;
... ... @@ -196,7 +196,7 @@ public class PromotionAggregationsService extends AbstractCacheAbleService {
// 0、解析promotion的限制条件
BoolQueryBuilder mustFilter = promotionSceneHelper.getMustFilterByPromotion(promotionConditions);
SearchApiResult result = sceneSelectionsService.aggregations(paramMap, mustFilter);
sceneRecommendBrandsService.getRecommendBrands(paramMap, result);
recommendBrandsService.getRecommendBrands(paramMap, result);
return result;
} catch (Exception e) {
logger.error(e.getMessage(), e);
... ...
package com.yoho.search.service.scene.tools;
import com.alibaba.fastjson.JSON;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.utils.SearchParamUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.helper.ProductListHelper;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
@Service
public class ProductListDslService {
private static final Logger logger = LoggerFactory.getLogger(ProductListDslService.class);
@Autowired
private ProductListHelper productListHelper;
public SearchApiResult getESDsl(Map<String, String> paramMap) {
logger.info("[func=getESDsl][param={}]", paramMap);
try {
SearchParam searchParam = productListHelper.buildProductListSearchParam(paramMap, true);
SearchSourceBuilder searchSourceBuilder = SearchParamUtils.genSearchSourceBuilderFromSearchParam(searchParam);
SearchApiResult searchApiResult = new SearchApiResult();
String results = searchSourceBuilder.toString();
searchApiResult.setData(JSON.parseObject(results));
logger.info("[func=getESDsl][dsl=\n{}]", searchApiResult.getData());
return searchApiResult;
} catch (Exception e) {
return SearchApiResultUtils.errorSearchApiResult("getESDsl", paramMap, e);
}
}
}
... ...