...
|
...
|
@@ -85,13 +85,13 @@ public class SearchLikeServiceImpl implements ISearchLikeService { |
|
|
pageSize = 60;
|
|
|
}
|
|
|
|
|
|
//3.1是否是全球购
|
|
|
// 3.1是否是全球购
|
|
|
String isGlobalInEs = productInfoInEs.getString("isGlobal");
|
|
|
boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs);
|
|
|
|
|
|
|
|
|
// 4、获取同一个品牌下最多5个商品
|
|
|
int maxCountInBrand = 5;
|
|
|
JSONArray inBrandProductList = this.getProductListInBrand(productInfoInEs, paramMap, pageSize > maxCountInBrand ? maxCountInBrand : pageSize,isGlobal);
|
|
|
JSONArray inBrandProductList = this.getProductListInBrand(productInfoInEs, paramMap, pageSize > maxCountInBrand ? maxCountInBrand : pageSize, isGlobal);
|
|
|
|
|
|
// 5、获取不同品牌下的余下数量的商品[通过聚合的方式来查找]
|
|
|
List<String> notInProductSkns = new ArrayList<String>();
|
...
|
...
|
@@ -100,7 +100,7 @@ public class SearchLikeServiceImpl implements ISearchLikeService { |
|
|
notInProductSkns.add(product.getString("product_skn"));
|
|
|
}
|
|
|
notInProductSkns.add(productSkn);
|
|
|
JSONArray notInBrandProductList = this.getProductListNotInBrand(productInfoInEs, paramMap, notInProductSkns, pageSize - inBrandProductList.size(),isGlobal);
|
|
|
JSONArray notInBrandProductList = this.getProductListNotInBrand(productInfoInEs, paramMap, notInProductSkns, pageSize - inBrandProductList.size(), isGlobal);
|
|
|
|
|
|
// 6、构造返回结果
|
|
|
Map<String, Object> dataMap = new HashMap<String, Object>();
|
...
|
...
|
@@ -125,14 +125,15 @@ public class SearchLikeServiceImpl implements ISearchLikeService { |
|
|
* @param limit
|
|
|
* @return
|
|
|
*/
|
|
|
private JSONArray getProductListInBrand(JSONObject productInfoInEs, Map<String, String> paramMap, int limit,boolean isGlobal) {
|
|
|
private JSONArray getProductListInBrand(JSONObject productInfoInEs, Map<String, String> paramMap, int limit, boolean isGlobal) {
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
// 1、构建Query
|
|
|
QueryBuilder queryBuilder = this.genQueryBuilder(productInfoInEs, paramMap, true,isGlobal);
|
|
|
QueryBuilder queryBuilder = this.genQueryBuilder(productInfoInEs, paramMap, true, isGlobal);
|
|
|
searchParam.setQuery(queryBuilder);
|
|
|
|
|
|
// 2、设置过滤条件
|
|
|
BoolQueryBuilder booleanQueryBuilder = this.genBoolQueryBuilder(productInfoInEs, paramMap, Arrays.asList(paramMap.get(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN)), true,isGlobal);
|
|
|
BoolQueryBuilder booleanQueryBuilder = this.genBoolQueryBuilder(productInfoInEs, paramMap, Arrays.asList(paramMap.get(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN)), true,
|
|
|
isGlobal);
|
|
|
searchParam.setFiter(booleanQueryBuilder);
|
|
|
|
|
|
// 3、设置排序规则[按打分排序]
|
...
|
...
|
@@ -171,17 +172,17 @@ public class SearchLikeServiceImpl implements ISearchLikeService { |
|
|
* @param limit
|
|
|
* @return
|
|
|
*/
|
|
|
private JSONArray getProductListNotInBrand(JSONObject productInfoInEs, Map<String, String> paramMap, List<String> notInProductSkns, int limit,boolean isGlobal) {
|
|
|
private JSONArray getProductListNotInBrand(JSONObject productInfoInEs, Map<String, String> paramMap, List<String> notInProductSkns, int limit, boolean isGlobal) {
|
|
|
if (limit <= 0) {
|
|
|
return new JSONArray();
|
|
|
}
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
// 1、构建Query
|
|
|
QueryBuilder queryBuilder = this.genQueryBuilder(productInfoInEs, paramMap, false,isGlobal);
|
|
|
QueryBuilder queryBuilder = this.genQueryBuilder(productInfoInEs, paramMap, false, isGlobal);
|
|
|
searchParam.setQuery(queryBuilder);
|
|
|
|
|
|
// 2、设置过滤条件
|
|
|
BoolQueryBuilder booleanQueryBuilder = this.genBoolQueryBuilder(productInfoInEs, paramMap, notInProductSkns, false,isGlobal);
|
|
|
BoolQueryBuilder booleanQueryBuilder = this.genBoolQueryBuilder(productInfoInEs, paramMap, notInProductSkns, false, isGlobal);
|
|
|
searchParam.setFiter(booleanQueryBuilder);
|
|
|
|
|
|
// 3、设置聚合条件
|
...
|
...
|
@@ -243,14 +244,17 @@ public class SearchLikeServiceImpl implements ISearchLikeService { |
|
|
this.append(query, productInfoInEs.getString("pattern"));
|
|
|
this.append(query, productInfoInEs.getString("attributeNames"));
|
|
|
this.append(query, productInfoInEs.getString("standardOnlyNames"));
|
|
|
String brandName = productInfoInEs.getString("brandName");
|
|
|
String queryString = query.toString();
|
|
|
if (isInBrand) {
|
|
|
queryString = queryString + " " + brandName;
|
|
|
} else {
|
|
|
queryString = queryString.replaceAll(brandName, "");
|
|
|
|
|
|
String brandName = productInfoInEs.getString("brandName");
|
|
|
if (StringUtils.isNotBlank(brandName)) {
|
|
|
if (isInBrand) {
|
|
|
queryString = queryString + " " + brandName;
|
|
|
} else {
|
|
|
queryString = queryString.replaceAll(brandName, "");
|
|
|
}
|
|
|
}
|
|
|
// 2、生成QueryBuilder
|
|
|
// 3、生成QueryBuilder
|
|
|
return searchLikeHelper.genSearchLikeQueryBuilder(queryString, isInBrand ? "40%" : "30%", productInfoInEs.getString("productFeatureFactor"));
|
|
|
}
|
|
|
|
...
|
...
|
@@ -260,8 +264,8 @@ public class SearchLikeServiceImpl implements ISearchLikeService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
private BoolQueryBuilder genBoolQueryBuilder(JSONObject productInfoInEs, Map<String, String> paramMap, List<String> notProductSkns, boolean isInBrand,boolean isGlobal) {
|
|
|
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultQueryBuilder(notProductSkns, isInBrand?isGlobal:false);//前几个是全球购,后面找有货的就好
|
|
|
private BoolQueryBuilder genBoolQueryBuilder(JSONObject productInfoInEs, Map<String, String> paramMap, List<String> notProductSkns, boolean isInBrand, boolean isGlobal) {
|
|
|
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultQueryBuilder(notProductSkns, isInBrand ? isGlobal : false);// 前几个是全球购,后面找有货的就好
|
|
|
// 1)设置此SKN相关的过滤条件
|
|
|
String gender = productInfoInEs.getString("gender");
|
|
|
List<String> genderList = searchLikeHelper.getGenderInfo(gender);
|
...
|
...
|
@@ -272,10 +276,10 @@ public class SearchLikeServiceImpl implements ISearchLikeService { |
|
|
BoolQueryBuilder sortFilter = QueryBuilders.boolQuery();
|
|
|
Integer middle_sort_id = productInfoInEs.getInteger("middleSortId");
|
|
|
Integer small_sort_id = productInfoInEs.getInteger("smallSortId");
|
|
|
if (middle_sort_id != null && middle_sort_id!=0) {
|
|
|
if (middle_sort_id != null && middle_sort_id != 0) {
|
|
|
sortFilter.should(QueryBuilders.termQuery("middleSortId", middle_sort_id));
|
|
|
}
|
|
|
if (small_sort_id != null && small_sort_id!=0) {
|
|
|
if (small_sort_id != null && small_sort_id != 0) {
|
|
|
sortFilter.should(QueryBuilders.termQuery("smallSortId", small_sort_id));
|
|
|
}
|
|
|
if (sortFilter.hasClauses()) {
|
...
|
...
|
@@ -283,10 +287,10 @@ public class SearchLikeServiceImpl implements ISearchLikeService { |
|
|
}
|
|
|
// 3)设置品牌
|
|
|
Integer brandId = productInfoInEs.getInteger("brandId");
|
|
|
if (brandId != null && brandId!=0 && isInBrand) {
|
|
|
if (brandId != null && brandId != 0 && isInBrand) {
|
|
|
boolFilter.must(QueryBuilders.termQuery("brandId", brandId));
|
|
|
}
|
|
|
if (brandId != null && brandId!=0 && !isInBrand) {
|
|
|
if (brandId != null && brandId != 0 && !isInBrand) {
|
|
|
boolFilter.mustNot(QueryBuilders.termQuery("brandId", brandId));
|
|
|
}
|
|
|
return boolFilter;
|
...
|
...
|
|