Authored by unknown

优化过滤参数

... ... @@ -22,7 +22,7 @@ import com.yoho.search.service.scene.ProductPoolSceneService;
*
*/
@Controller
public class ProductPoolSceneControoler {
public class ProductPoolSceneController {
@Autowired
private ProductPoolSceneService productPoolService;
... ...
... ... @@ -58,7 +58,7 @@ public class SearchRequestParams {
public static final String PARAM_SEARCH_SERIESID = "series_id"; //
public static final String PARAM_SEARCH_COUPONLIMITSTATUS = "couponLimitStatus"; //
public static final String PARAM_SEARCH_ATTRIBUTE_NOT = "attribute_not"; // ◆品属性
public static final String PARAM_SEARCH_ATTRIBUTE_NOT = "attribute_not"; // ◆品属性
public static final String PARAM_SEARCH_STATUS = "status"; // 查询是否上架
public static final String PARAM_SEARCH_ORDER = "order";// 排序值
... ... @@ -86,6 +86,11 @@ public class SearchRequestParams {
public static final String PARAM_SEARCH_LAST_REDUCE_PRICE_TIME = "lastReducePriceTime"; // 降价时间
public static final String PARAM_SEARCH_IS_FOR_MARKET_PROMOTION = "isForMarketPromotion"; // 市场推广参数
public static final String PARAM_SEARCH_FILTER_POOLID = "filter_poolId";
public static final String PARAM_SEARCH_NOT_PRODUCT_SKN = "not_productSkn";
public static final String PARAM_SEARCH_NOT_BRAND_ID = "not_brandId";
public static final String PARAM_SEARCH_NOT_SHOP_ID = "not_shopId";
// 活动模板相关过滤条件
public static final String PARAM_SEARCH_ACT_TEMP = "act_temp"; // 模板id
... ...
... ... @@ -461,22 +461,44 @@ public class SearchServiceHelper {
boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.isFobbiden, 1));
}
// 通用的过滤请求
for (String key : paramMap.keySet()) {
if (key.startsWith("not_")) {
String[] values = paramMap.get(key).split(",");
boolFilter.mustNot(QueryBuilders.termsQuery(key.substring(4, key.length()), values));
}
if (key.startsWith("filter_")) {
String field = key.substring(7, key.length());
boolFilter.must(QueryBuilders.termsQuery(field, paramMap.get(key).split(",")));
}
if (key.startsWith("missing_")) {
String field = key.substring(8, key.length());
boolFilter.mustNot(QueryBuilders.existsQuery(field));
}
// 处理filter_poolId
if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_FILTER_POOLID)) {
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.poolId, paramMap.get(SearchRequestParams.PARAM_SEARCH_FILTER_POOLID).split(",")));
}
// 处理not_productSkn
if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_NOT_PRODUCT_SKN)) {
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, paramMap.get(SearchRequestParams.PARAM_SEARCH_NOT_PRODUCT_SKN).split(",")));
}
// 处理not_brandId
if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_NOT_BRAND_ID)) {
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.brandId, paramMap.get(SearchRequestParams.PARAM_SEARCH_NOT_BRAND_ID).split(",")));
}
// 处理not_shopId
if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_NOT_SHOP_ID)) {
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.shopId, paramMap.get(SearchRequestParams.PARAM_SEARCH_NOT_SHOP_ID).split(",")));
}
// // 通用的过滤请求
// for (String key : paramMap.keySet()) {
// if (key.startsWith("not_")) {
// String[] values = paramMap.get(key).split(",");
// boolFilter.mustNot(QueryBuilders.termsQuery(key.substring(4,
// key.length()), values));
// }
// if (key.startsWith("filter_")) {
// String field = key.substring(7, key.length());
// boolFilter.must(QueryBuilders.termsQuery(field,
// paramMap.get(key).split(",")));
// }
// if (key.startsWith("missing_")) {
// String field = key.substring(8, key.length());
// boolFilter.mustNot(QueryBuilders.existsQuery(field));
// }
// }
// 规则
if (!"parameter".equals(filterParamName)) {
Iterator<String> itParamKeys = paramMap.keySet().iterator();
... ...
... ... @@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.base.SearchRequestParams;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.common.SceneProductListService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
... ... @@ -39,7 +40,7 @@ public class ProductPoolSceneService extends AbstractSceneService {
long begin = System.currentTimeMillis();
logger.info("[func=searchProductPool][param={}][begin={}]", paramMap.toString(), begin);
// 1)如果poolId为空返回
if (StringUtils.isBlank(paramMap.get("filter_poolId"))) {
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_FILTER_POOLID))) {
return new SearchApiResult().setCode(400).setMessage("filter_poolId参数为空");
}
// 2)排序接口兼容【按商品池导入顺序排序】
... ... @@ -77,7 +78,7 @@ public class ProductPoolSceneService extends AbstractSceneService {
public SearchApiResult productList(Map<String, String> paramMap) {
// 1)如果poolId为空返回
if (StringUtils.isBlank(paramMap.get("filter_poolId"))) {
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_FILTER_POOLID))) {
return new SearchApiResult().setCode(400).setMessage("filter_poolId参数为空");
}
// 2)获取商品列表
... ... @@ -93,7 +94,7 @@ public class ProductPoolSceneService extends AbstractSceneService {
@Override
public SearchApiResult aggregations(Map<String, String> paramMap) {
// 1)如果poolId为空返回
if (StringUtils.isBlank(paramMap.get("filter_poolId"))) {
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_FILTER_POOLID))){
return new SearchApiResult().setCode(400).setMessage("filter_poolId参数为空");
}
// 2)获取商品池筛选项
... ...