|
@@ -181,6 +181,16 @@ public class SearchServiceHelper { |
|
@@ -181,6 +181,16 @@ public class SearchServiceHelper { |
181
|
}
|
181
|
}
|
182
|
}
|
182
|
}
|
183
|
|
183
|
|
|
|
184
|
+ private boolean checkParamNotFiltered(Map<String, String> paramMap, String filterParamName, String paramName) {
|
|
|
185
|
+ if (!paramMap.containsKey(paramName) || StringUtils.isBlank(paramMap.get(paramName))) {
|
|
|
186
|
+ return false;
|
|
|
187
|
+ }
|
|
|
188
|
+ if (StringUtils.isNotBlank(filterParamName) && paramName.equals(filterParamName)) {
|
|
|
189
|
+ return false;
|
|
|
190
|
+ }
|
|
|
191
|
+ return true;
|
|
|
192
|
+ }
|
|
|
193
|
+
|
184
|
/**
|
194
|
/**
|
185
|
* 构造通用的过滤条件
|
195
|
* 构造通用的过滤条件
|
186
|
*
|
196
|
*
|
|
@@ -192,43 +202,54 @@ public class SearchServiceHelper { |
|
@@ -192,43 +202,54 @@ public class SearchServiceHelper { |
192
|
*/
|
202
|
*/
|
193
|
public BoolQueryBuilder constructFilterBuilder(Map<String, String> paramMap, String filterParamName) throws Exception {
|
203
|
public BoolQueryBuilder constructFilterBuilder(Map<String, String> paramMap, String filterParamName) throws Exception {
|
194
|
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
204
|
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
195
|
-
|
|
|
196
|
- // 品牌
|
|
|
197
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_BRAND) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_BRAND))
|
|
|
198
|
- && !SearchRequestParams.PARAM_SEARCH_BRAND.equals(filterParamName)) {
|
205
|
+ // //////////////////////////////////////////支持传多个参数,以逗号分隔///////////////////////////////////////////////////////////
|
|
|
206
|
+ // 性别
|
|
|
207
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_GENDER)) {
|
|
|
208
|
+ int[] genders = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_GENDER), ",");
|
|
|
209
|
+ boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.gender, genders));
|
|
|
210
|
+ }
|
|
|
211
|
+ // 过滤品牌
|
|
|
212
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_BRAND)) {
|
199
|
int[] brandids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_BRAND), ",");
|
213
|
int[] brandids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_BRAND), ",");
|
200
|
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.brandId, brandids));
|
214
|
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.brandId, brandids));
|
201
|
}
|
215
|
}
|
202
|
-
|
|
|
203
|
- if ("Y".equals(paramMap.get(SearchRequestParams.PARAM_SEARCH_GLOBAL_FILTER_BRAND)) && StringUtils.isNotBlank(paramMap.get("pageId"))) {
|
|
|
204
|
- boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.forbiddenPageIds, paramMap.get("pageId")));
|
216
|
+ // 人群
|
|
|
217
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_AGELEVEL)) {
|
|
|
218
|
+ int[] ageLevels = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_AGELEVEL), ",");
|
|
|
219
|
+ boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.ageLevel, ageLevels));
|
205
|
}
|
220
|
}
|
206
|
-
|
|
|
207
|
- // 店铺
|
|
|
208
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_SHOP) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SHOP))
|
|
|
209
|
- && !SearchRequestParams.PARAM_SEARCH_SHOP.equals(filterParamName)) {
|
|
|
210
|
- int[] shopids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_SHOP), ",");
|
|
|
211
|
- boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.shopId, shopids));
|
221
|
+ // 颜色
|
|
|
222
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_COLOR)) {
|
|
|
223
|
+ int[] colorids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_COLOR), ",");
|
|
|
224
|
+ boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.colorIds, colorids));
|
|
|
225
|
+ }
|
|
|
226
|
+ // 尺码
|
|
|
227
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_SIZE)) {
|
|
|
228
|
+ int[] sizeids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_SIZE), ",");
|
|
|
229
|
+ boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.sizeIds, sizeids));
|
|
|
230
|
+ }
|
|
|
231
|
+ // 风格
|
|
|
232
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_STYLE)) {
|
|
|
233
|
+ int[] styleIds = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_STYLE), ",");
|
|
|
234
|
+ boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.styleIds, styleIds));
|
212
|
}
|
235
|
}
|
213
|
- // 大分类
|
|
|
214
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_MAXSORT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_MAXSORT))
|
|
|
215
|
- && !SearchRequestParams.PARAM_SEARCH_MAXSORT.equals(filterParamName)) {
|
236
|
+ // 过滤大分类
|
|
|
237
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_MAXSORT)) {
|
216
|
int[] maxsortids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_MAXSORT), ",");
|
238
|
int[] maxsortids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_MAXSORT), ",");
|
217
|
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.maxSortId, maxsortids));
|
239
|
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.maxSortId, maxsortids));
|
218
|
}
|
240
|
}
|
219
|
- // 中类
|
|
|
220
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_MIDDLESORT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_MIDDLESORT))
|
|
|
221
|
- && !SearchRequestParams.PARAM_SEARCH_MAXSORT.equals(filterParamName)) {
|
241
|
+ // 过滤中分类
|
|
|
242
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_MIDDLESORT)) {
|
222
|
int[] middlesortids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_MIDDLESORT), ",");
|
243
|
int[] middlesortids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_MIDDLESORT), ",");
|
223
|
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.middleSortId, middlesortids));
|
244
|
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.middleSortId, middlesortids));
|
224
|
}
|
245
|
}
|
225
|
- // 小类
|
|
|
226
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_SMALLSORT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SMALLSORT))) {
|
246
|
+ // 过滤小分类
|
|
|
247
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_SMALLSORT)) {
|
227
|
int[] smallsortids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_SMALLSORT), ",");
|
248
|
int[] smallsortids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_SMALLSORT), ",");
|
228
|
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.smallSortId, smallsortids));
|
249
|
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.smallSortId, smallsortids));
|
229
|
}
|
250
|
}
|
230
|
- // 大中小分类
|
|
|
231
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_COMMONSORT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_COMMONSORT))) {
|
251
|
+ // 过滤通用分类
|
|
|
252
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_COMMONSORT)) {
|
232
|
int[] commonSortIds = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_COMMONSORT), ",");
|
253
|
int[] commonSortIds = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_COMMONSORT), ",");
|
233
|
BoolQueryBuilder commonSortIdFilter = QueryBuilders.boolQuery();
|
254
|
BoolQueryBuilder commonSortIdFilter = QueryBuilders.boolQuery();
|
234
|
commonSortIdFilter.should(QueryBuilders.termsQuery(ProductIndexEsField.maxSortId, commonSortIds));
|
255
|
commonSortIdFilter.should(QueryBuilders.termsQuery(ProductIndexEsField.maxSortId, commonSortIds));
|
|
@@ -236,256 +257,217 @@ public class SearchServiceHelper { |
|
@@ -236,256 +257,217 @@ public class SearchServiceHelper { |
236
|
commonSortIdFilter.should(QueryBuilders.termsQuery(ProductIndexEsField.smallSortId, commonSortIds));
|
257
|
commonSortIdFilter.should(QueryBuilders.termsQuery(ProductIndexEsField.smallSortId, commonSortIds));
|
237
|
boolFilter.must(commonSortIdFilter);
|
258
|
boolFilter.must(commonSortIdFilter);
|
238
|
}
|
259
|
}
|
239
|
- // 颜色
|
|
|
240
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_COLOR) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_COLOR))
|
|
|
241
|
- && !SearchRequestParams.PARAM_SEARCH_COLOR.equals(filterParamName)) {
|
|
|
242
|
- int[] colorids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_COLOR), ",");
|
|
|
243
|
- boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.colorIds, colorids));
|
|
|
244
|
- }
|
|
|
245
|
- // 尺码
|
|
|
246
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_SIZE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SIZE))
|
|
|
247
|
- && !SearchRequestParams.PARAM_SEARCH_SIZE.equals(filterParamName)) {
|
|
|
248
|
- int[] sizeids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_SIZE), ",");
|
|
|
249
|
- boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.sizeIds, sizeids));
|
260
|
+ // 过滤店铺
|
|
|
261
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_SHOP)) {
|
|
|
262
|
+ int[] shopids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_SHOP), ",");
|
|
|
263
|
+ boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.shopId, shopids));
|
250
|
}
|
264
|
}
|
251
|
- // 销售价格
|
|
|
252
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_PRICE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_PRICE))
|
|
|
253
|
- && !SearchRequestParams.PARAM_SEARCH_PRICE.equals(filterParamName)) {
|
|
|
254
|
- String[] prices = paramMap.get(SearchRequestParams.PARAM_SEARCH_PRICE).split(",");
|
|
|
255
|
- if (prices.length < 2) {
|
|
|
256
|
- throw new IllegalArgumentException("价格[price]参数(" + paramMap.get(SearchRequestParams.PARAM_SEARCH_PRICE) + ")为非区间值!");
|
265
|
+ // 促销标记
|
|
|
266
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_ISPROMOTION)) {
|
|
|
267
|
+ int[] ispromotions = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISPROMOTION), ",");
|
|
|
268
|
+ boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.ispromotion, ispromotions));
|
257
|
}
|
269
|
}
|
258
|
- double begin = Double.parseDouble(prices[0]);
|
|
|
259
|
- double end = Double.parseDouble(prices[1]);
|
|
|
260
|
- boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.salesPrice).gte(begin).lte(end));
|
270
|
+ // APP类型
|
|
|
271
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_APPTYPE)) {
|
|
|
272
|
+ int[] appTypes = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_APPTYPE), ",");
|
|
|
273
|
+ boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.appType, appTypes));
|
261
|
}
|
274
|
}
|
262
|
- // 性别
|
|
|
263
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_GENDER) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_GENDER))
|
|
|
264
|
- && !SearchRequestParams.PARAM_SEARCH_GENDER.equals(filterParamName)) {
|
|
|
265
|
- int[] genders = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_GENDER), ",");
|
|
|
266
|
- boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.gender, genders));
|
275
|
+ // SKN
|
|
|
276
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SYNC_SKN)) {
|
|
|
277
|
+ boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, paramMap.get(SearchRequestParams.PARAM_SYNC_SKN.split(","))));
|
267
|
}
|
278
|
}
|
|
|
279
|
+
|
|
|
280
|
+ // //////////////////////////////////////////不支持多个参数///////////////////////////////////////////////////////////
|
268
|
// 是否特价
|
281
|
// 是否特价
|
269
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_SPECIALOFFER) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SPECIALOFFER))) {
|
282
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_SPECIALOFFER)) {
|
270
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.specialoffer, paramMap.get(SearchRequestParams.PARAM_SEARCH_SPECIALOFFER)));
|
283
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.specialoffer, paramMap.get(SearchRequestParams.PARAM_SEARCH_SPECIALOFFER)));
|
271
|
}
|
284
|
}
|
272
|
// 是否打折
|
285
|
// 是否打折
|
273
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISDISCOUNT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISDISCOUNT))) {
|
286
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_ISDISCOUNT)) {
|
274
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isDiscount, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISDISCOUNT)));
|
287
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isDiscount, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISDISCOUNT)));
|
275
|
}
|
288
|
}
|
276
|
// 是否为学生价
|
289
|
// 是否为学生价
|
277
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_STUDENTPRICE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_STUDENTPRICE))) {
|
290
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_STUDENTPRICE)) {
|
278
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isStudentPrice, paramMap.get(SearchRequestParams.PARAM_SEARCH_STUDENTPRICE)));
|
291
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isStudentPrice, paramMap.get(SearchRequestParams.PARAM_SEARCH_STUDENTPRICE)));
|
279
|
}
|
292
|
}
|
280
|
// 是否学生返币
|
293
|
// 是否学生返币
|
281
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_STUDENTREBATE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_STUDENTREBATE))) {
|
294
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_STUDENTREBATE)) {
|
282
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isstudentrebate, paramMap.get(SearchRequestParams.PARAM_SEARCH_STUDENTREBATE)));
|
295
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isstudentrebate, paramMap.get(SearchRequestParams.PARAM_SEARCH_STUDENTREBATE)));
|
283
|
}
|
296
|
}
|
284
|
// 是否支持分期
|
297
|
// 是否支持分期
|
285
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISINSTALMENT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISINSTALMENT))) {
|
298
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_ISINSTALMENT)) {
|
286
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isInstalment, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISINSTALMENT)));
|
299
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isInstalment, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISINSTALMENT)));
|
287
|
}
|
300
|
}
|
288
|
- // 属性(待研究)
|
|
|
289
|
- if (!"parameter".equals(filterParamName)) {
|
|
|
290
|
- Iterator<String> itParamKeys = paramMap.keySet().iterator();
|
|
|
291
|
- StringBuilder standardValues = new StringBuilder();
|
|
|
292
|
- while (itParamKeys.hasNext()) {
|
|
|
293
|
- String paramKey = itParamKeys.next();
|
|
|
294
|
- if (paramKey.contains("parameter")) {
|
|
|
295
|
- if (paramKey.contains("_")) {
|
|
|
296
|
- standardValues.append(",").append(paramKey.split("_")[1]).append(paramMap.get(paramKey));
|
|
|
297
|
- }
|
|
|
298
|
- }
|
|
|
299
|
- }
|
|
|
300
|
- if (standardValues.length() > 0) {
|
|
|
301
|
- long[] standards = ConvertUtils.stringToLongArray(standardValues.toString().replaceFirst(",", ""), ",");
|
|
|
302
|
- for (long standard : standards) {
|
|
|
303
|
- // boolFilter.must(FilterBuilders.termFilter("standardIds",
|
|
|
304
|
- // standard));
|
|
|
305
|
- boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.standardIds, standard));
|
|
|
306
|
- }
|
|
|
307
|
- }
|
|
|
308
|
- }
|
|
|
309
|
// 是否在售
|
301
|
// 是否在售
|
310
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISSALES) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISSALES))) {
|
302
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_ISSALES)) {
|
311
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isSales, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISSALES)));
|
303
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isSales, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISSALES)));
|
312
|
}
|
304
|
}
|
313
|
- // 促销标记
|
|
|
314
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISPROMOTION) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISPROMOTION))) {
|
|
|
315
|
- int[] ispromotions = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISPROMOTION), ",");
|
|
|
316
|
- boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.ispromotion, ispromotions));
|
|
|
317
|
- }
|
|
|
318
|
// vip折扣类型
|
305
|
// vip折扣类型
|
319
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_VIPDISCOUNTTYPE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_VIPDISCOUNTTYPE))) {
|
306
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_VIPDISCOUNTTYPE)) {
|
320
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.vipDiscountType, paramMap.get(SearchRequestParams.PARAM_SEARCH_VIPDISCOUNTTYPE)));
|
307
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.vipDiscountType, paramMap.get(SearchRequestParams.PARAM_SEARCH_VIPDISCOUNTTYPE)));
|
321
|
}
|
308
|
}
|
322
|
- // 促销折扣
|
|
|
323
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_PD) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_PD))) {
|
|
|
324
|
- String[] discounts = paramMap.get(SearchRequestParams.PARAM_SEARCH_PD).split(",");
|
|
|
325
|
- if (discounts.length < 2) {
|
|
|
326
|
- throw new IllegalArgumentException("折扣[pd]参数(" + paramMap.get(SearchRequestParams.PARAM_SEARCH_PD) + ")为非区间值!");
|
|
|
327
|
- }
|
|
|
328
|
- double begin = Double.parseDouble(discounts[0]);
|
|
|
329
|
- double end = Double.parseDouble(discounts[1]);
|
|
|
330
|
- boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.promotionDiscount).gte(begin).lte(end));
|
|
|
331
|
- }
|
|
|
332
|
// 商品属性 1正常商品 2赠品
|
309
|
// 商品属性 1正常商品 2赠品
|
333
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE))) {
|
310
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_ATTRIBUTE)) {
|
334
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.attribute, paramMap.get(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE)));
|
311
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.attribute, paramMap.get(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE)));
|
335
|
}
|
312
|
}
|
336
|
// 商品属性 1赠品 2正常商品
|
313
|
// 商品属性 1赠品 2正常商品
|
337
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT))) {
|
314
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT)) {
|
338
|
boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.attribute, paramMap.get(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT)));
|
315
|
boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.attribute, paramMap.get(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT)));
|
339
|
}
|
316
|
}
|
340
|
- // 库存
|
|
|
341
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_STOCKNUM) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_STOCKNUM))) {
|
|
|
342
|
- // 获取今天往后n天的unix时间戳;
|
|
|
343
|
- long now = DateUtil.getTimeSecondByDate(new Date());
|
|
|
344
|
- int begin = Integer.parseInt(paramMap.get(SearchRequestParams.PARAM_SEARCH_STOCKNUM));
|
|
|
345
|
- if (begin == 0) {
|
|
|
346
|
- boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.storageNum, begin));
|
|
|
347
|
- } else {
|
|
|
348
|
- if (StringUtils.isNotBlank(paramMap.get("showSoldOut")) && paramMap.get("showSoldOut").equals("1")) {
|
|
|
349
|
- boolFilter.should(QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).gte(begin)).should(
|
|
|
350
|
- QueryBuilders.boolQuery().must(QueryBuilders.termQuery(ProductIndexEsField.storageNum, 0))
|
|
|
351
|
- .must(QueryBuilders.rangeQuery(ProductIndexEsField.storageUpdateTime).gte(now)));
|
|
|
352
|
- } else {
|
|
|
353
|
- boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).gte(begin));
|
|
|
354
|
- }
|
|
|
355
|
- }
|
|
|
356
|
- }
|
|
|
357
|
// 是否限量
|
317
|
// 是否限量
|
358
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISLIMITED) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISLIMITED))) {
|
318
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_ISLIMITED)) {
|
359
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.islimited, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISLIMITED)));
|
319
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.islimited, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISLIMITED)));
|
360
|
}
|
320
|
}
|
361
|
// 是否限购
|
321
|
// 是否限购
|
362
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISLIMITEDBUY) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISLIMITEDBUY))) {
|
322
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_ISLIMITEDBUY)) {
|
363
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isLimitbuy, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISLIMITEDBUY)));
|
323
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isLimitbuy, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISLIMITEDBUY)));
|
364
|
}
|
324
|
}
|
365
|
// 是否预售
|
325
|
// 是否预售
|
366
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISADVANCE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISADVANCE))) {
|
326
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_ISADVANCE)) {
|
367
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isAdvance, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISADVANCE)));
|
327
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isAdvance, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISADVANCE)));
|
368
|
- }// 是否定金预售
|
|
|
369
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISDESPOSITADVANCE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISDESPOSITADVANCE))) {
|
328
|
+ }
|
|
|
329
|
+ // 是否定金预售
|
|
|
330
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_ISDESPOSITADVANCE)) {
|
370
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isDepositAdvance, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISDESPOSITADVANCE)));
|
331
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isDepositAdvance, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISDESPOSITADVANCE)));
|
371
|
}
|
332
|
}
|
372
|
// 是否新品
|
333
|
// 是否新品
|
373
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISNEW) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISNEW))) {
|
334
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_ISNEW)) {
|
374
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isnew, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISNEW)));
|
335
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isnew, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISNEW)));
|
375
|
}
|
336
|
}
|
376
|
// 是否奥莱
|
337
|
// 是否奥莱
|
377
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISOUTLETS) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISOUTLETS))) {
|
338
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_ISOUTLETS)) {
|
378
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isOutlets, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISOUTLETS)));
|
339
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isOutlets, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISOUTLETS)));
|
379
|
}
|
340
|
}
|
380
|
// 状态是否上架
|
341
|
// 状态是否上架
|
381
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_STATUS) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_STATUS))) {
|
342
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_STATUS)) {
|
382
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.status, paramMap.get(SearchRequestParams.PARAM_SEARCH_STATUS)));
|
343
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.status, paramMap.get(SearchRequestParams.PARAM_SEARCH_STATUS)));
|
383
|
}
|
344
|
}
|
384
|
- // APP类型
|
|
|
385
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_APPTYPE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_APPTYPE))
|
|
|
386
|
- && !SearchRequestParams.PARAM_SEARCH_APPTYPE.equals(filterParamName)) {
|
|
|
387
|
- int[] appTypes = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_APPTYPE), ",");
|
|
|
388
|
- boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.appType, appTypes));
|
|
|
389
|
- }
|
|
|
390
|
- // 风格
|
|
|
391
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_STYLE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_STYLE))
|
|
|
392
|
- && !SearchRequestParams.PARAM_SEARCH_STYLE.equals(filterParamName)) {
|
|
|
393
|
- int[] styleids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_STYLE), ",");
|
|
|
394
|
- boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.styleIds, styleids));
|
|
|
395
|
- }
|
|
|
396
|
// 销售平台 (网站、APP、现场)
|
345
|
// 销售平台 (网站、APP、现场)
|
397
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_SELLCHANNELS) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SELLCHANNELS))) {
|
346
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_SELLCHANNELS)) {
|
398
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.sellChannels, paramMap.get(SearchRequestParams.PARAM_SEARCH_SELLCHANNELS)));
|
347
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.sellChannels, paramMap.get(SearchRequestParams.PARAM_SEARCH_SELLCHANNELS)));
|
399
|
}
|
348
|
}
|
400
|
- if (paramMap.containsKey("folder_id") && StringUtils.isNotBlank(paramMap.get("folder_id"))) {
|
|
|
401
|
- boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.folderId, paramMap.get("folder_id")));
|
349
|
+ // folderId
|
|
|
350
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_FOLDERID)) {
|
|
|
351
|
+ boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.folderId, paramMap.get(SearchRequestParams.PARAM_SEARCH_FOLDERID)));
|
|
|
352
|
+ }
|
|
|
353
|
+ // series_id
|
|
|
354
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_SERIESID)) {
|
|
|
355
|
+ boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.seriesId, paramMap.get(SearchRequestParams.PARAM_SEARCH_SERIESID)));
|
|
|
356
|
+ }
|
|
|
357
|
+ // 判断是否需要是筛选全球购[全球购的筛选项]
|
|
|
358
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_IS_GLOBAL)) {
|
|
|
359
|
+ boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.isGlobal, paramMap.get(SearchRequestParams.PARAM_SEARCH_IS_GLOBAL)));
|
|
|
360
|
+ }
|
|
|
361
|
+ // 用户VIP级别过滤
|
|
|
362
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.USER_VIP_LEVEL)) {
|
|
|
363
|
+ List<String> userVipLevels = this.getUserVipLevels(paramMap.get(SearchRequestParams.USER_VIP_LEVEL));
|
|
|
364
|
+ if (userVipLevels != null) {
|
|
|
365
|
+ boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.vipLevels, userVipLevels));
|
|
|
366
|
+ }
|
|
|
367
|
+ }
|
|
|
368
|
+ // 断码(breakingRate>=50 || basePinRatio>=3.5)
|
|
|
369
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_BREAKING) && "1".equals(paramMap.get(SearchRequestParams.PARAM_SEARCH_BREAKING))) {
|
|
|
370
|
+ BoolQueryBuilder breakingFilter = QueryBuilders.boolQuery();
|
|
|
371
|
+ breakingFilter.should(QueryBuilders.rangeQuery(ProductIndexEsField.breakingRate).from(50));
|
|
|
372
|
+ breakingFilter.should(QueryBuilders.rangeQuery(ProductIndexEsField.basePinRatio).from(3.5));
|
|
|
373
|
+ boolFilter.must(breakingFilter);
|
|
|
374
|
+ }
|
|
|
375
|
+ // 屏蔽页面判断
|
|
|
376
|
+ if ("Y".equals(paramMap.get(SearchRequestParams.PARAM_SEARCH_GLOBAL_FILTER_BRAND)) && StringUtils.isNotBlank(paramMap.get("pageId"))) {
|
|
|
377
|
+ boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.forbiddenPageIds, paramMap.get("pageId")));
|
|
|
378
|
+ }
|
|
|
379
|
+
|
|
|
380
|
+ // //////////////////////////////////////////////////范围过滤////////////////////////////////////////////////////////////
|
|
|
381
|
+ // 销售价格
|
|
|
382
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_PRICE)) {
|
|
|
383
|
+ try {
|
|
|
384
|
+ String[] prices = paramMap.get(SearchRequestParams.PARAM_SEARCH_PRICE).split(",");
|
|
|
385
|
+ double begin = Double.parseDouble(prices[0]);
|
|
|
386
|
+ double end = Double.parseDouble(prices[1]);
|
|
|
387
|
+ boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.salesPrice).gte(begin).lte(end));
|
|
|
388
|
+ } catch (Exception e) {
|
|
|
389
|
+ logger.error(e.getMessage(), e);
|
402
|
}
|
390
|
}
|
403
|
- if (paramMap.containsKey("series_id") && StringUtils.isNotBlank(paramMap.get("series_id"))) {
|
|
|
404
|
- boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.seriesId, paramMap.get("series_id")));
|
|
|
405
|
}
|
391
|
}
|
406
|
// 促销折扣
|
392
|
// 促销折扣
|
407
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_PDINT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_PDINT))) {
|
|
|
408
|
- String[] discounts = paramMap.get(SearchRequestParams.PARAM_SEARCH_PDINT).split(",");
|
|
|
409
|
- if (discounts.length < 2) {
|
|
|
410
|
- throw new IllegalArgumentException("折扣[p_d_int]参数(" + paramMap.get(SearchRequestParams.PARAM_SEARCH_PDINT) + ")为非区间值!");
|
393
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_PD)) {
|
|
|
394
|
+ try {
|
|
|
395
|
+ String[] discounts = paramMap.get(SearchRequestParams.PARAM_SEARCH_PD).split(",");
|
|
|
396
|
+ double begin = Double.parseDouble(discounts[0]);
|
|
|
397
|
+ double end = Double.parseDouble(discounts[1]);
|
|
|
398
|
+ boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.promotionDiscount).gte(begin).lte(end));
|
|
|
399
|
+ } catch (Exception e) {
|
|
|
400
|
+ logger.error(e.getMessage(), e);
|
411
|
}
|
401
|
}
|
|
|
402
|
+ }
|
|
|
403
|
+ // 促销折扣
|
|
|
404
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_PDINT)) {
|
|
|
405
|
+ try {
|
|
|
406
|
+ String[] discounts = paramMap.get(SearchRequestParams.PARAM_SEARCH_PDINT).split(",");
|
412
|
double begin = Double.parseDouble(discounts[0]);
|
407
|
double begin = Double.parseDouble(discounts[0]);
|
413
|
double end = Double.parseDouble(discounts[1]);
|
408
|
double end = Double.parseDouble(discounts[1]);
|
414
|
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.promotionDiscountInt).gte(begin).lte(end));
|
409
|
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.promotionDiscountInt).gte(begin).lte(end));
|
|
|
410
|
+ } catch (Exception e) {
|
|
|
411
|
+ logger.error(e.getMessage(), e);
|
|
|
412
|
+ }
|
415
|
}
|
413
|
}
|
416
|
// 首次上架时间间隔
|
414
|
// 首次上架时间间隔
|
417
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_FIRST_SHELVE_TIME) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_FIRST_SHELVE_TIME))
|
|
|
418
|
- && !SearchRequestParams.PARAM_SEARCH_FIRST_SHELVE_TIME.equals(filterParamName)) {
|
415
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_FIRST_SHELVE_TIME)) {
|
|
|
416
|
+ try {
|
419
|
String[] times = paramMap.get(SearchRequestParams.PARAM_SEARCH_FIRST_SHELVE_TIME).split(",");
|
417
|
String[] times = paramMap.get(SearchRequestParams.PARAM_SEARCH_FIRST_SHELVE_TIME).split(",");
|
420
|
- if (times.length < 2) {
|
|
|
421
|
- throw new IllegalArgumentException("首次上架时间[first_shelve_time]参数(" + paramMap.get(SearchRequestParams.PARAM_SEARCH_FIRST_SHELVE_TIME) + ")为非区间值!");
|
|
|
422
|
- }
|
|
|
423
|
double begin = Double.parseDouble(times[0]);
|
418
|
double begin = Double.parseDouble(times[0]);
|
424
|
double end = Double.parseDouble(times[1]);
|
419
|
double end = Double.parseDouble(times[1]);
|
425
|
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.firstShelveTime).from(begin).to(end));
|
420
|
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.firstShelveTime).from(begin).to(end));
|
|
|
421
|
+ } catch (Exception e) {
|
|
|
422
|
+ logger.error(e.getMessage(), e);
|
|
|
423
|
+ }
|
426
|
}
|
424
|
}
|
427
|
// 上架日期间隔
|
425
|
// 上架日期间隔
|
428
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_SHELVETIME) && !SearchRequestParams.PARAM_SEARCH_SHELVETIME.equals(filterParamName)) {
|
426
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_SHELVETIME)) {
|
|
|
427
|
+ try {
|
429
|
String[] times = paramMap.get(SearchRequestParams.PARAM_SEARCH_SHELVETIME).split(",");
|
428
|
String[] times = paramMap.get(SearchRequestParams.PARAM_SEARCH_SHELVETIME).split(",");
|
430
|
- if (times.length < 2) {
|
|
|
431
|
- throw new IllegalArgumentException("上架时间[shelve_time]参数(" + paramMap.get(SearchRequestParams.PARAM_SEARCH_SHELVETIME) + ")为非区间值!");
|
|
|
432
|
- }
|
|
|
433
|
double begin = Double.parseDouble(times[0]);
|
429
|
double begin = Double.parseDouble(times[0]);
|
434
|
double end = Double.parseDouble(times[1]);
|
430
|
double end = Double.parseDouble(times[1]);
|
435
|
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.shelveTime).from(begin).to(end));
|
431
|
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.shelveTime).from(begin).to(end));
|
|
|
432
|
+ } catch (Exception e) {
|
|
|
433
|
+ logger.error(e.getMessage(), e);
|
|
|
434
|
+ }
|
436
|
}
|
435
|
}
|
437
|
// 上架日期
|
436
|
// 上架日期
|
438
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_DAY) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_DAY))) {
|
437
|
+ if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_DAY)) {
|
|
|
438
|
+ try {
|
439
|
String recentDay = paramMap.get(SearchRequestParams.PARAM_SEARCH_DAY);
|
439
|
String recentDay = paramMap.get(SearchRequestParams.PARAM_SEARCH_DAY);
|
440
|
if (!DateUtil.isDate(recentDay)) {
|
440
|
if (!DateUtil.isDate(recentDay)) {
|
441
|
throw new IllegalArgumentException("wrong date format");
|
441
|
throw new IllegalArgumentException("wrong date format");
|
442
|
}
|
442
|
}
|
443
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.shelveDay, recentDay));
|
443
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.shelveDay, recentDay));
|
|
|
444
|
+ } catch (Exception e) {
|
|
|
445
|
+ logger.error(e.getMessage(), e);
|
|
|
446
|
+ }
|
|
|
447
|
+ }
|
|
|
448
|
+
|
|
|
449
|
+ // ///////////////////////////////////////////特殊过滤/////////////////////////////////////////////////////////
|
|
|
450
|
+ // 库存相关的过滤条件
|
|
|
451
|
+ QueryBuilder stocknumberQueryBuilder = this.getStorageNumQueryBuilder(paramMap, filterParamName);
|
|
|
452
|
+ if (stocknumberQueryBuilder != null) {
|
|
|
453
|
+ boolFilter.must(stocknumberQueryBuilder);
|
444
|
}
|
454
|
}
|
445
|
- // 增加活动模板相关的过滤条件
|
455
|
+
|
|
|
456
|
+ // 活动模板相关的过滤条件
|
446
|
BoolQueryBuilder activitiesTermsBuilder = searchCommonHelper.getActivitiesTermsBuilder(paramMap);
|
457
|
BoolQueryBuilder activitiesTermsBuilder = searchCommonHelper.getActivitiesTermsBuilder(paramMap);
|
447
|
if (activitiesTermsBuilder != null) {
|
458
|
if (activitiesTermsBuilder != null) {
|
448
|
boolFilter.must(QueryBuilders.nestedQuery(ProductIndexEsField.activities, activitiesTermsBuilder));
|
459
|
boolFilter.must(QueryBuilders.nestedQuery(ProductIndexEsField.activities, activitiesTermsBuilder));
|
449
|
}
|
460
|
}
|
450
|
- // 断码(breakingRate>=50 || basePinRatio>=3.5)
|
|
|
451
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_BREAKING) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_BREAKING))) {
|
|
|
452
|
- String breaking = paramMap.get(SearchRequestParams.PARAM_SEARCH_BREAKING);
|
|
|
453
|
- if ("1".equals(breaking)) {
|
|
|
454
|
- boolFilter.must(QueryBuilders.boolQuery().should(QueryBuilders.rangeQuery(ProductIndexEsField.breakingRate).from(50))
|
|
|
455
|
- .should(QueryBuilders.rangeQuery(ProductIndexEsField.basePinRatio).from(3.5)));
|
|
|
456
|
- }
|
|
|
457
|
- }
|
|
|
458
|
- // SKN
|
|
|
459
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SYNC_SKN) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SYNC_SKN))) {
|
|
|
460
|
- String sknString = paramMap.get(SearchRequestParams.PARAM_SYNC_SKN);
|
|
|
461
|
- boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, sknString.split(",")));
|
|
|
462
|
- }
|
|
|
463
|
- // 年龄层
|
|
|
464
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_AGELEVEL) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_AGELEVEL))
|
|
|
465
|
- && !SearchRequestParams.PARAM_SEARCH_AGELEVEL.equals(filterParamName)) {
|
|
|
466
|
- int[] ageLevels = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_AGELEVEL), ",");
|
|
|
467
|
- boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.ageLevel, ageLevels));
|
|
|
468
|
- }
|
461
|
+
|
469
|
// 判断是否需要包含全球购[全球购的开关]
|
462
|
// 判断是否需要包含全球购[全球购的开关]
|
470
|
if (!searchCommonHelper.containGlobal(paramMap)) {
|
463
|
if (!searchCommonHelper.containGlobal(paramMap)) {
|
471
|
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isGlobal, "Y"));
|
464
|
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isGlobal, "Y"));
|
472
|
}
|
465
|
}
|
473
|
- // 判断是否需要是筛选全球购[全球购的筛选项]
|
|
|
474
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_IS_GLOBAL) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_IS_GLOBAL))) {
|
|
|
475
|
- boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.isGlobal, paramMap.get(SearchRequestParams.PARAM_SEARCH_IS_GLOBAL)));
|
|
|
476
|
- }
|
|
|
477
|
// 如果contain_seckill!=Y,则过滤掉秒杀商品
|
466
|
// 如果contain_seckill!=Y,则过滤掉秒杀商品
|
478
|
if (!paramMap.containsKey("contain_seckill") || !"Y".equals(paramMap.get("contain_seckill"))) {
|
467
|
if (!paramMap.containsKey("contain_seckill") || !"Y".equals(paramMap.get("contain_seckill"))) {
|
479
|
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isSeckill, "Y"));
|
468
|
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isSeckill, "Y"));
|
480
|
}
|
469
|
}
|
481
|
- // 用户VIP级别过滤
|
|
|
482
|
- String userVipLevel = (paramMap.get(SearchRequestParams.USER_VIP_LEVEL));
|
|
|
483
|
- if (StringUtils.isNotBlank(userVipLevel)) {
|
|
|
484
|
- List<String> userVipLevels = this.getUserVipLevels(userVipLevel);
|
|
|
485
|
- if (userVipLevels != null) {
|
|
|
486
|
- boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.vipLevels, userVipLevels));
|
|
|
487
|
- }
|
|
|
488
|
- }
|
470
|
+
|
489
|
// 通用的过滤请求
|
471
|
// 通用的过滤请求
|
490
|
for (String key : paramMap.keySet()) {
|
472
|
for (String key : paramMap.keySet()) {
|
491
|
if (key.startsWith("not_")) {
|
473
|
if (key.startsWith("not_")) {
|
|
@@ -501,6 +483,29 @@ public class SearchServiceHelper { |
|
@@ -501,6 +483,29 @@ public class SearchServiceHelper { |
501
|
boolFilter.mustNot(QueryBuilders.existsQuery(field));
|
483
|
boolFilter.mustNot(QueryBuilders.existsQuery(field));
|
502
|
}
|
484
|
}
|
503
|
}
|
485
|
}
|
|
|
486
|
+
|
|
|
487
|
+ // 规则
|
|
|
488
|
+ if (!"parameter".equals(filterParamName)) {
|
|
|
489
|
+ Iterator<String> itParamKeys = paramMap.keySet().iterator();
|
|
|
490
|
+ StringBuilder standardValues = new StringBuilder();
|
|
|
491
|
+ while (itParamKeys.hasNext()) {
|
|
|
492
|
+ String paramKey = itParamKeys.next();
|
|
|
493
|
+ if (paramKey.contains("parameter")) {
|
|
|
494
|
+ if (paramKey.contains("_")) {
|
|
|
495
|
+ standardValues.append(",").append(paramKey.split("_")[1]).append(paramMap.get(paramKey));
|
|
|
496
|
+ }
|
|
|
497
|
+ }
|
|
|
498
|
+ }
|
|
|
499
|
+ if (standardValues.length() > 0) {
|
|
|
500
|
+ long[] standards = ConvertUtils.stringToLongArray(standardValues.toString().replaceFirst(",", ""), ",");
|
|
|
501
|
+ for (long standard : standards) {
|
|
|
502
|
+ // boolFilter.must(FilterBuilders.termFilter("standardIds",
|
|
|
503
|
+ // standard));
|
|
|
504
|
+ boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.standardIds, standard));
|
|
|
505
|
+ }
|
|
|
506
|
+ }
|
|
|
507
|
+ }
|
|
|
508
|
+
|
504
|
if (boolFilter.hasClauses()) {
|
509
|
if (boolFilter.hasClauses()) {
|
505
|
return boolFilter;
|
510
|
return boolFilter;
|
506
|
} else {
|
511
|
} else {
|
|
@@ -508,6 +513,26 @@ public class SearchServiceHelper { |
|
@@ -508,6 +513,26 @@ public class SearchServiceHelper { |
508
|
}
|
513
|
}
|
509
|
}
|
514
|
}
|
510
|
|
515
|
|
|
|
516
|
+ private QueryBuilder getStorageNumQueryBuilder(Map<String, String> paramMap, String filterParamName) {
|
|
|
517
|
+ if (!this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_STOCKNUM)) {
|
|
|
518
|
+ return null;
|
|
|
519
|
+ }
|
|
|
520
|
+ int begin = Integer.parseInt(paramMap.get(SearchRequestParams.PARAM_SEARCH_STOCKNUM));
|
|
|
521
|
+ if (begin == 0) {
|
|
|
522
|
+ return QueryBuilders.termQuery(ProductIndexEsField.storageNum, 0);
|
|
|
523
|
+ }
|
|
|
524
|
+ if (!"1".equals(paramMap.get("showSoldOut"))) {
|
|
|
525
|
+ return QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).gte(begin);
|
|
|
526
|
+ }
|
|
|
527
|
+ // 延期显示[( 库存>=begin) ||(storageNum<begin & storageUpdateTime>now)]
|
|
|
528
|
+ BoolQueryBuilder storageNumFilter = QueryBuilders.boolQuery();
|
|
|
529
|
+ storageNumFilter.should(QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).gte(begin));
|
|
|
530
|
+ storageNumFilter.should(QueryBuilders.boolQuery().must(QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).to(begin))
|
|
|
531
|
+ .must(QueryBuilders.rangeQuery(ProductIndexEsField.storageUpdateTime).gte(DateUtil.getTimeSecondByDate(new Date()))));
|
|
|
532
|
+ return storageNumFilter;
|
|
|
533
|
+
|
|
|
534
|
+ }
|
|
|
535
|
+
|
511
|
private List<String> getUserVipLevels(String userVipLevel) {
|
536
|
private List<String> getUserVipLevels(String userVipLevel) {
|
512
|
if ("1".equals(userVipLevel)) {
|
537
|
if ("1".equals(userVipLevel)) {
|
513
|
return Arrays.asList("1");
|
538
|
return Arrays.asList("1");
|