Authored by wangnan9279

ufo推荐列表bug fix

... ... @@ -153,6 +153,7 @@ public class SearchRequestParams {
//ufo
public static final String UFOPRODUCTINDEX_SEARCH_QUERY = "query";
public static final String UFOPRODUCTINDEX_PARAM_ID = "id";
public static final String UFOPRODUCTINDEX_PARAM_NOT_ID = "not_id";
public static final String UFOPRODUCTINDEX_PARAM_MAXSORT = "maxSort";
public static final String UFOPRODUCTINDEX_PARAM_MIDSORT = "midSort";
public static final String UFOPRODUCTINDEX_PARAM_GENDER = "gender";
... ...
... ... @@ -61,10 +61,15 @@ public class UfoSearchQueryHelper extends BaseService {
public BoolQueryBuilder constructFilterBuilder(Map<String, String> paramMap, String filterParamName) throws Exception {
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
//只id过滤
if ("Y".equals(paramMap.get(SearchRequestParams.UFOPRODUCTINDEX_PARAM_IS_ID_FILTER))) {
this.addMustIntTermsQuery(boolFilter, paramMap, filterParamName, SearchRequestParams.UFOPRODUCTINDEX_PARAM_ID, UfoProductIndexEsField.id);
return boolFilter;
}
//硬过滤
if (!"Y".equals(paramMap.get(SearchRequestParams.UFOPRODUCTINDEX_PARAM_IS_ID_FILTER))) {
boolFilter.must(QueryBuilders.termQuery(UfoProductIndexEsField.delStatus, 0));
boolFilter.must(QueryBuilders.termQuery(UfoProductIndexEsField.shelveStatus, 1));
//是否是即将发售列表
long now = DateUtil.getCurrentTimeSecond();
if ("Y".equals(paramMap.get(SearchRequestParams.UFOPRODUCTINDEX_PARAM_IS_SOON_SALE))) {
boolFilter.must(QueryBuilders.rangeQuery(UfoProductIndexEsField.saleTime).gt(now));
... ... @@ -72,7 +77,6 @@ public class UfoSearchQueryHelper extends BaseService {
} else {
boolFilter.must(QueryBuilders.rangeQuery(UfoProductIndexEsField.saleTime).lte(now));
}
}
//参数过滤
this.addMustIntTermsQuery(boolFilter, paramMap, filterParamName, SearchRequestParams.UFOPRODUCTINDEX_PARAM_ID, UfoProductIndexEsField.id);
this.addMustIntTermsQuery(boolFilter, paramMap, filterParamName, SearchRequestParams.UFOPRODUCTINDEX_PARAM_MAXSORT, UfoProductIndexEsField.maxSortId);
... ... @@ -83,6 +87,11 @@ public class UfoSearchQueryHelper extends BaseService {
this.addMustIntTermsQuery(boolFilter, paramMap, filterParamName, SearchRequestParams.UFOPRODUCTINDEX_PARAM_SIZE, UfoProductIndexEsField.sizeIds);
this.addMustIntTermsQuery(boolFilter, paramMap, filterParamName, SearchRequestParams.UFOPRODUCTINDEX_PARAM_COLOR, UfoProductIndexEsField.colorIds);
this.addMustIntTermsQuery(boolFilter, paramMap, filterParamName, SearchRequestParams.UFOPRODUCTINDEX_PARAM_POOL, UfoProductIndexEsField.poolIds);
//推荐列表中去掉自身
String not_id = paramMap.get(SearchRequestParams.UFOPRODUCTINDEX_PARAM_NOT_ID);
if (StringUtils.isNotBlank(not_id)) {
boolFilter.mustNot(QueryBuilders.termQuery(UfoProductIndexEsField.id, not_id));
}
return boolFilter;
}
... ...
... ... @@ -110,7 +110,7 @@ public class UfoProductListService {
return new SearchApiResult().setCode(400).setMessage("参数不合法,缺少必传参数");
}
//第一次查询
paramMap.put("viewNum", "1000");
paramMap.put("viewNum", "100");
SearchApiResult searchApiResult = this.productList(paramMap);
if (searchApiResult.getData() == null) {
return new SearchApiResult().setData(null).setCode(500);
... ... @@ -123,20 +123,13 @@ public class UfoProductListService {
Set<Integer> idList = new HashSet<>();
if (returnInfoList.size() < RECOMMEND_LIMIT) {
returnInfoList.stream().map(p -> MapUtils.getIntValue(p, "id")).forEach(id -> idList.add(id));
//可能的第二次查询
paramMap = new HashMap<>();
paramMap.put("brand", brandId.toString());
paramMap.put("midSort", midSortId.toString());
paramMap.put("not_id", not_id.toString());
paramMap.put("viewNum", "1000");
//可能的第二次查询,去掉query去查
paramMap.remove("query");
this.addReturnInfoList(paramMap, idList, returnInfoList);
}
if (returnInfoList.size() < RECOMMEND_LIMIT) {
//可能的第三次查询
paramMap = new HashMap<>();
paramMap.put("brand", brandId.toString());
paramMap.put("viewNum", "1000");
paramMap.put("not_id", not_id.toString());
//可能的第三次查询,去掉中分类去查
paramMap.remove("midSort");
this.addReturnInfoList(paramMap, idList, returnInfoList);
}
dataMap.put("total", returnInfoList.size());
... ... @@ -168,7 +161,7 @@ public class UfoProductListService {
public SearchApiResult productListForPlatform(Map<String, String> paramMap) {
try {
// 2. 构建SearchParam
// 构建SearchParam
SearchParam searchParam = new SearchParam();
searchParam.setQuery(QueryBuilders.matchAllQuery());
BoolQueryBuilder boolFilter = ufoSearchQueryHelper.constructFilterBuilderForPlatform(paramMap, null);
... ...