...
|
...
|
@@ -81,10 +81,14 @@ public class SearchLikeServiceImpl implements ISearchLikeService { |
|
|
if (pageSize > 60 || pageSize <= 0) {
|
|
|
pageSize = 60;
|
|
|
}
|
|
|
|
|
|
//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);
|
|
|
JSONArray inBrandProductList = this.getProductListInBrand(productInfoInEs, paramMap, pageSize > maxCountInBrand ? maxCountInBrand : pageSize,isGlobal);
|
|
|
|
|
|
// 5、获取不同品牌下的余下数量的商品[通过聚合的方式来查找]
|
|
|
List<String> notInProductSkns = new ArrayList<String>();
|
...
|
...
|
@@ -93,7 +97,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());
|
|
|
JSONArray notInBrandProductList = this.getProductListNotInBrand(productInfoInEs, paramMap, notInProductSkns, pageSize - inBrandProductList.size(),isGlobal);
|
|
|
|
|
|
// 6、构造返回结果
|
|
|
Map<String, Object> dataMap = new HashMap<String, Object>();
|
...
|
...
|
@@ -118,14 +122,14 @@ public class SearchLikeServiceImpl implements ISearchLikeService { |
|
|
* @param limit
|
|
|
* @return
|
|
|
*/
|
|
|
private JSONArray getProductListInBrand(JSONObject productInfoInEs, Map<String, String> paramMap, int limit) {
|
|
|
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);
|
|
|
QueryBuilder queryBuilder = this.genQueryBuilder(productInfoInEs, paramMap, true,isGlobal);
|
|
|
searchParam.setQuery(queryBuilder);
|
|
|
|
|
|
// 2、设置过滤条件
|
|
|
BoolQueryBuilder booleanQueryBuilder = this.genBoolQueryBuilder(productInfoInEs, paramMap, Arrays.asList(paramMap.get(SearchRequestParams.PARAM_SYNC_SKN)), true);
|
|
|
BoolQueryBuilder booleanQueryBuilder = this.genBoolQueryBuilder(productInfoInEs, paramMap, Arrays.asList(paramMap.get(SearchRequestParams.PARAM_SYNC_SKN)), true,isGlobal);
|
|
|
searchParam.setFiter(booleanQueryBuilder);
|
|
|
|
|
|
// 3、设置排序规则[按打分排序]
|
...
|
...
|
@@ -164,17 +168,17 @@ public class SearchLikeServiceImpl implements ISearchLikeService { |
|
|
* @param limit
|
|
|
* @return
|
|
|
*/
|
|
|
private JSONArray getProductListNotInBrand(JSONObject productInfoInEs, Map<String, String> paramMap, List<String> notInProductSkns, int limit) {
|
|
|
if(limit<=0){
|
|
|
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);
|
|
|
QueryBuilder queryBuilder = this.genQueryBuilder(productInfoInEs, paramMap, false,isGlobal);
|
|
|
searchParam.setQuery(queryBuilder);
|
|
|
|
|
|
// 2、设置过滤条件
|
|
|
BoolQueryBuilder booleanQueryBuilder = this.genBoolQueryBuilder(productInfoInEs, paramMap, notInProductSkns, false);
|
|
|
BoolQueryBuilder booleanQueryBuilder = this.genBoolQueryBuilder(productInfoInEs, paramMap, notInProductSkns, false,isGlobal);
|
|
|
searchParam.setFiter(booleanQueryBuilder);
|
|
|
|
|
|
// 3、设置聚合条件
|
...
|
...
|
@@ -220,32 +224,41 @@ public class SearchLikeServiceImpl implements ISearchLikeService { |
|
|
return productJSONArray;
|
|
|
}
|
|
|
|
|
|
private QueryBuilder genQueryBuilder(JSONObject productInfoInEs, Map<String, String> paramMap, boolean isInBrand) {
|
|
|
// 1、设置查询的值
|
|
|
String productName = productInfoInEs.getString("productName");
|
|
|
String standardOnlyNames = productInfoInEs.getString("standardOnlyNames");
|
|
|
String style = productInfoInEs.getString("style");
|
|
|
String pattern = productInfoInEs.getString("pattern");
|
|
|
String attributeNames = productInfoInEs.getString("attributeNames");
|
|
|
private QueryBuilder genQueryBuilder(JSONObject productInfoInEs, Map<String, String> paramMap, boolean isInBrand, boolean isGlobal) {
|
|
|
StringBuilder query = new StringBuilder();
|
|
|
// 1、如果是全球购,则直接用商品名称+品类名称去查
|
|
|
if (isGlobal) {
|
|
|
this.append(query, productInfoInEs.getString("productName"));
|
|
|
this.append(query, productInfoInEs.getString("smallSort"));
|
|
|
this.append(query, productInfoInEs.getString("middleSort"));
|
|
|
this.append(query, productInfoInEs.getString("maxSort"));
|
|
|
return searchLikeHelper.genSearchLikeQueryBuilder(query.toString(), "25%", null);
|
|
|
}
|
|
|
// 2、设置有货的查询的值
|
|
|
this.append(query, productInfoInEs.getString("productName"));
|
|
|
this.append(query, productInfoInEs.getString("style"));
|
|
|
this.append(query, productInfoInEs.getString("pattern"));
|
|
|
this.append(query, productInfoInEs.getString("attributeNames"));
|
|
|
this.append(query, productInfoInEs.getString("standardOnlyNames"));
|
|
|
String brandName = productInfoInEs.getString("brandName");
|
|
|
String productFeatureFactor = productInfoInEs.getString("productFeatureFactor");
|
|
|
String query = standardOnlyNames + " " + style + " " + pattern + " " + attributeNames;
|
|
|
String queryString = query.toString();
|
|
|
if (isInBrand) {
|
|
|
query = brandName + " " + productName + " " + query;
|
|
|
queryString = queryString + " " + brandName;
|
|
|
} else {
|
|
|
query = productName.replaceAll(brandName, "") + " " + query;
|
|
|
queryString = queryString.replaceAll(brandName, "");
|
|
|
}
|
|
|
query = query.replaceAll("null", "");
|
|
|
|
|
|
//生成QueryBuilder
|
|
|
return searchLikeHelper.genSearchLikeQueryBuilder(query, isInBrand?"40%":"30%", productFeatureFactor);
|
|
|
// 2、生成QueryBuilder
|
|
|
return searchLikeHelper.genSearchLikeQueryBuilder(queryString, isInBrand ? "40%" : "30%", productInfoInEs.getString("productFeatureFactor"));
|
|
|
}
|
|
|
|
|
|
private BoolQueryBuilder genBoolQueryBuilder(JSONObject productInfoInEs, Map<String, String> paramMap, List<String> notProductSkns, boolean isInBrand) {
|
|
|
String isGlobalInEs = productInfoInEs.getString("isGlobal");
|
|
|
boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs);
|
|
|
|
|
|
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultQueryBuilder(notProductSkns,isGlobal);
|
|
|
private void append(StringBuilder stringBuilder, String word) {
|
|
|
if (StringUtils.isNotBlank(word)) {
|
|
|
stringBuilder.append(word).append(" ");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private BoolQueryBuilder genBoolQueryBuilder(JSONObject productInfoInEs, Map<String, String> paramMap, List<String> notProductSkns, boolean isInBrand,boolean isGlobal) {
|
|
|
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultQueryBuilder(notProductSkns, isGlobal);
|
|
|
// 1)设置此SKN相关的过滤条件
|
|
|
String gender = productInfoInEs.getString("gender");
|
|
|
List<String> genderList = searchLikeHelper.getGenderInfo(gender);
|
...
|
...
|
@@ -256,21 +269,21 @@ 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){
|
|
|
if (middle_sort_id != null) {
|
|
|
sortFilter.should(QueryBuilders.termQuery("middleSortId", middle_sort_id));
|
|
|
}
|
|
|
if(small_sort_id!=null){
|
|
|
if (small_sort_id != null) {
|
|
|
sortFilter.should(QueryBuilders.termQuery("smallSortId", small_sort_id));
|
|
|
}
|
|
|
if(sortFilter.hasClauses()){
|
|
|
if (sortFilter.hasClauses()) {
|
|
|
boolFilter.must(sortFilter);
|
|
|
}
|
|
|
// 3)设置品牌
|
|
|
Integer brandId = productInfoInEs.getInteger("brandId");
|
|
|
if(brandId !=null && isInBrand){
|
|
|
if (brandId != null && isInBrand) {
|
|
|
boolFilter.must(QueryBuilders.termQuery("brandId", brandId));
|
|
|
}
|
|
|
if(brandId !=null && !isInBrand){
|
|
|
if (brandId != null && !isInBrand) {
|
|
|
boolFilter.mustNot(QueryBuilders.termQuery("brandId", brandId));
|
|
|
}
|
|
|
return boolFilter;
|
...
|
...
|
|