|
@@ -21,372 +21,390 @@ import java.util.Map; |
|
@@ -21,372 +21,390 @@ import java.util.Map; |
21
|
@Component
|
21
|
@Component
|
22
|
public class SearchCommonHelper {
|
22
|
public class SearchCommonHelper {
|
23
|
|
23
|
|
24
|
- @Autowired
|
|
|
25
|
- private SearchDynamicConfigService dynamicConfig;
|
|
|
26
|
- @Autowired
|
|
|
27
|
- private SearchServiceConfiger searchServiceConfiger;
|
|
|
28
|
- @Autowired
|
|
|
29
|
- private SearchDynamicConfigService searchDynamicConfigService;
|
|
|
30
|
-
|
|
|
31
|
- public int getPage(Map<String, String> paramMap) {
|
|
|
32
|
- return StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
|
|
|
33
|
- }
|
|
|
34
|
-
|
|
|
35
|
- public int getPageSize(Map<String, String> paramMap) {
|
|
|
36
|
- return StringUtils.isBlank(paramMap.get("viewNum")) ? 60 : Integer.parseInt(paramMap.get("viewNum"));
|
|
|
37
|
- }
|
|
|
38
|
-
|
|
|
39
|
- public boolean isPersionalScene(Map<String, String> paramMap) {
|
|
|
40
|
- if (!searchDynamicConfigService.openPersonalized()) {
|
|
|
41
|
- return false;
|
|
|
42
|
- }
|
|
|
43
|
- if (this.hasUid(paramMap) && this.isOrderEmpty(paramMap)) {
|
|
|
44
|
- return true;
|
|
|
45
|
- }
|
|
|
46
|
- return false;
|
|
|
47
|
- }
|
|
|
48
|
-
|
|
|
49
|
- public long getTotalPage(long total, int size) {
|
|
|
50
|
- return PageUtils.getTotalPage(total,size);
|
|
|
51
|
- }
|
|
|
52
|
-
|
|
|
53
|
- public int getUid(Map<String, String> paramMap) {
|
|
|
54
|
- try {
|
|
|
55
|
- return MapUtils.getIntValue(paramMap, "uid", 0);
|
|
|
56
|
- } catch (Exception e) {
|
|
|
57
|
- return 0;
|
|
|
58
|
- }
|
|
|
59
|
- }
|
|
|
60
|
-
|
|
|
61
|
- public boolean hasUid(Map<String, String> paramMap) {
|
|
|
62
|
- return this.getUid(paramMap) > 0;
|
|
|
63
|
- }
|
|
|
64
|
-
|
|
|
65
|
-
|
|
|
66
|
- /**
|
|
|
67
|
- * 是否是默认的模糊搜索
|
|
|
68
|
- *
|
|
|
69
|
- * @param paramMap
|
|
|
70
|
- * @return
|
|
|
71
|
- */
|
|
|
72
|
- public boolean isFuzzySearchPageDefault(Map<String, String> paramMap) {
|
|
|
73
|
- String query = paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY);
|
|
|
74
|
- if (StringUtils.isBlank(query)) {
|
|
|
75
|
- return false;
|
|
|
76
|
- }
|
|
|
77
|
- if (!this.isOrderEmpty(paramMap)) {
|
|
|
78
|
- return false;
|
|
|
79
|
- }
|
|
|
80
|
- String pageId = paramMap.get(SearchRequestParams.PARAM_SEARCH_PAGEID);
|
|
|
81
|
- if (!SearchPageIdDefine.PAGE_ID_SEARCH.equalsIgnoreCase(pageId)) {
|
|
|
82
|
- return false;
|
|
|
83
|
- }
|
|
|
84
|
- return true;
|
|
|
85
|
- }
|
|
|
86
|
-
|
|
|
87
|
- /**
|
|
|
88
|
- * 是否需要开启个性化
|
|
|
89
|
- *
|
|
|
90
|
- * @param paramMap
|
|
|
91
|
- * @return
|
|
|
92
|
- */
|
|
|
93
|
- public boolean isNeedPersonalSearch(Map<String, String> paramMap) {
|
|
|
94
|
- // 从 zk中动态获取是否使用个性化
|
|
|
95
|
- boolean openPersonalized = dynamicConfig.openPersonalized();
|
|
|
96
|
- if (!openPersonalized) {
|
|
|
97
|
- return false;
|
|
|
98
|
- }
|
|
|
99
|
- if(!this.hasUid(paramMap)){
|
|
|
100
|
- return false;
|
|
|
101
|
- }
|
|
|
102
|
- if (!this.isOrderEmpty(paramMap)) {
|
|
|
103
|
- return false;
|
|
|
104
|
- }
|
|
|
105
|
- return true;
|
|
|
106
|
- }
|
|
|
107
|
-
|
|
|
108
|
- /**
|
|
|
109
|
- * 是否需要对某个SKN加分
|
|
|
110
|
- *
|
|
|
111
|
- * @param paramMap
|
|
|
112
|
- * @return
|
|
|
113
|
- */
|
|
|
114
|
- public boolean isFirstProductSknSearch(Map<String, String> paramMap) {
|
|
|
115
|
- String first_productskn = paramMap.get(SearchRequestParams.PARAM_SEARCH_FIRST_PRODUCRSKN);
|
|
|
116
|
- if (StringUtils.isBlank(first_productskn)) {
|
|
|
117
|
- return false;
|
|
|
118
|
- }
|
|
|
119
|
- if (!this.isOrderEmpty(paramMap)) {
|
|
|
120
|
- return false;
|
|
|
121
|
- }
|
|
|
122
|
- return true;
|
|
|
123
|
- }
|
|
|
124
|
-
|
|
|
125
|
- /**
|
|
|
126
|
- * 是否需要对频道降分
|
|
|
127
|
- *
|
|
|
128
|
- * @param paramMap
|
|
|
129
|
- * @return
|
|
|
130
|
- */
|
|
|
131
|
- public boolean isNeedDeScoreForChannel(Map<String, String> paramMap) {
|
|
|
132
|
- String physicalChannel = paramMap.get(SearchRequestParams.PARAM_SEARCH_PHYSICAL_CHANNEL);
|
|
|
133
|
- if (StringUtils.isBlank(physicalChannel)) {
|
|
|
134
|
- return false;
|
|
|
135
|
- }
|
|
|
136
|
- if (!isFuzzySearchPageDefault(paramMap)) {
|
|
|
137
|
- return false;
|
|
|
138
|
- }
|
|
|
139
|
- if (!dynamicConfig.isDeScorePhysicalChannelOpen()) {
|
|
|
140
|
- return false;
|
|
|
141
|
- }
|
|
|
142
|
- return true;
|
|
|
143
|
- }
|
|
|
144
|
-
|
|
|
145
|
- /**
|
|
|
146
|
- * 判断搜索是否需要包含全球购
|
|
|
147
|
- *
|
|
|
148
|
- * @param paramMap
|
|
|
149
|
- * @return
|
|
|
150
|
- */
|
|
|
151
|
- public boolean containGlobal(Map<String, String> paramMap) {
|
|
|
152
|
- // 1、如果总开关关了,则肯定不包含全球购商品
|
|
|
153
|
- boolean containglobal = dynamicConfig.containglobal();
|
|
|
154
|
- if (!containglobal) {
|
|
|
155
|
- return false;
|
|
|
156
|
- }
|
|
|
157
|
- // 2、如果前端传来的参数中不包含contain_global!=Y,则不包含全球购
|
|
|
158
|
- if (!paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL) || !"Y".equals(paramMap.get(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL))) {
|
|
|
159
|
- return false;
|
|
|
160
|
- }
|
|
|
161
|
- return true;
|
|
|
162
|
- }
|
|
|
163
|
-
|
|
|
164
|
- /**
|
|
|
165
|
- * 当前查询的关键字是否是skn
|
|
|
166
|
- *
|
|
|
167
|
- * @param keyword
|
|
|
168
|
- * @return
|
|
|
169
|
- */
|
|
|
170
|
- public boolean isQuerySknOrSku(String keyword) {
|
|
|
171
|
- try {
|
|
|
172
|
- String key = "";
|
|
|
173
|
- if (keyword.contains(" ")) {
|
|
|
174
|
- key = keyword.split(" ")[0];
|
|
|
175
|
- } else if (keyword.contains(",")) {
|
|
|
176
|
- key = keyword.split(",")[0];
|
|
|
177
|
- } else if (keyword.contains("+")) {
|
|
|
178
|
- key = keyword.split("\\+")[0];
|
|
|
179
|
- }
|
|
|
180
|
- if ((CharUtils.isNumeric(keyword) && keyword.length() >= 6) || (CharUtils.isNumeric(key) && key.length() >= 6)) {
|
|
|
181
|
- return true;
|
|
|
182
|
- }
|
|
|
183
|
- return false;
|
|
|
184
|
- } catch (Exception e) {
|
|
|
185
|
- return false;
|
|
|
186
|
- }
|
|
|
187
|
- }
|
|
|
188
|
-
|
|
|
189
|
- /**
|
|
|
190
|
- * 从搜索的关键词中提取出skn信息
|
|
|
191
|
- *
|
|
|
192
|
- * @param keyword
|
|
|
193
|
- * @return
|
|
|
194
|
- */
|
|
|
195
|
- public List<Integer> getQuerySknList(String keyword) {
|
|
|
196
|
- List<Integer> sknList = new ArrayList<>();
|
|
|
197
|
-
|
|
|
198
|
- try {
|
|
|
199
|
- String[] keys = null;
|
|
|
200
|
- if (keyword.contains(" ")) {
|
|
|
201
|
- keys = keyword.split(" ");
|
|
|
202
|
- } else if (keyword.contains(",")) {
|
|
|
203
|
- keys = keyword.split(",");
|
|
|
204
|
- } else if (keyword.contains("+")) {
|
|
|
205
|
- keys = keyword.split("\\+");
|
|
|
206
|
- }
|
|
|
207
|
-
|
|
|
208
|
- if (keys != null && keys.length > 0) {
|
|
|
209
|
- for (String key : keys) {
|
|
|
210
|
- if (CharUtils.isNumeric(key) && key.length() >= 7) {
|
|
|
211
|
- sknList.add(Integer.valueOf(key));
|
|
|
212
|
- }
|
|
|
213
|
- }
|
|
|
214
|
- }
|
|
|
215
|
-
|
|
|
216
|
- return sknList;
|
|
|
217
|
- } catch (Exception e) {
|
|
|
218
|
- return sknList;
|
|
|
219
|
- }
|
|
|
220
|
- }
|
|
|
221
|
-
|
|
|
222
|
- /**
|
|
|
223
|
- * 是否是新品到着页
|
|
|
224
|
- *
|
|
|
225
|
- * @param paramMap
|
|
|
226
|
- * @return
|
|
|
227
|
- */
|
|
|
228
|
- public boolean isNewRecPage(Map<String, String> paramMap) {
|
|
|
229
|
- String pageId = paramMap.get(SearchRequestParams.PARAM_SEARCH_PAGEID);
|
|
|
230
|
- if (StringUtils.isBlank(pageId) || !pageId.equals(SearchPageIdDefine.PAGE_ID_NEW)) {
|
|
|
231
|
- return false;
|
|
|
232
|
- }
|
|
|
233
|
- return true;
|
|
|
234
|
- }
|
|
|
235
|
-
|
|
|
236
|
- /**
|
|
|
237
|
- * 是否是新品到着默认页
|
|
|
238
|
- *
|
|
|
239
|
- * @param paramMap
|
|
|
240
|
- * @return
|
|
|
241
|
- */
|
|
|
242
|
- public boolean isNewRecPageDefault(Map<String, String> paramMap) {
|
|
|
243
|
- if (!isNewRecPage(paramMap)) {
|
|
|
244
|
- return false;
|
|
|
245
|
- }
|
|
|
246
|
- if (!this.isOrderEmpty(paramMap)) {
|
|
|
247
|
- return false;
|
|
|
248
|
- }
|
|
|
249
|
- return true;
|
|
|
250
|
- }
|
|
|
251
|
-
|
|
|
252
|
- /**
|
|
|
253
|
- * 是否是新品到着页的人气排序
|
|
|
254
|
- *
|
|
|
255
|
- * @param paramMap
|
|
|
256
|
- * @return
|
|
|
257
|
- */
|
|
|
258
|
- public boolean isNewRecHeatValueDescSearch(Map<String, String> paramMap) {
|
|
|
259
|
- if (!this.isNewRecPage(paramMap)) {
|
|
|
260
|
- return false;
|
|
|
261
|
- }
|
|
|
262
|
- String order = paramMap.get(SearchRequestParams.PARAM_SEARCH_ORDER);
|
|
|
263
|
- if (StringUtils.isBlank(order)) {
|
|
|
264
|
- return false;
|
|
|
265
|
- }
|
|
|
266
|
- if (!order.contains("heatValue")) {
|
|
|
267
|
- return false;
|
|
|
268
|
- }
|
|
|
269
|
- return true;
|
|
|
270
|
- }
|
|
|
271
|
-
|
|
|
272
|
- /**
|
|
|
273
|
- * 是否未传order
|
|
|
274
|
- *
|
|
|
275
|
- * @param paramMap
|
|
|
276
|
- * @return
|
|
|
277
|
- */
|
|
|
278
|
- public boolean isOrderEmpty(Map<String, String> paramMap) {
|
|
|
279
|
- String order = paramMap.get(SearchRequestParams.PARAM_SEARCH_ORDER);
|
|
|
280
|
- if (!StringUtils.isBlank(order)) {
|
|
|
281
|
- return false;
|
|
|
282
|
- }
|
|
|
283
|
- return true;
|
|
|
284
|
- }
|
|
|
285
|
-
|
|
|
286
|
- /**
|
|
|
287
|
- * 是否是品类列表的默认页
|
|
|
288
|
- *
|
|
|
289
|
- * @param paramMap
|
|
|
290
|
- * @return
|
|
|
291
|
- */
|
|
|
292
|
- public boolean isSortPageDefault(Map<String, String> paramMap) {
|
|
|
293
|
- String pageId = paramMap.get(SearchRequestParams.PARAM_SEARCH_PAGEID);
|
|
|
294
|
- if (StringUtils.isBlank(pageId) || !pageId.equals(SearchPageIdDefine.PAGE_ID_SORT)) {
|
|
|
295
|
- return false;
|
|
|
296
|
- }
|
|
|
297
|
- if (!this.isOrderEmpty(paramMap)) {
|
|
|
298
|
- return false;
|
|
|
299
|
- }
|
|
|
300
|
- return true;
|
|
|
301
|
- }
|
|
|
302
|
-
|
|
|
303
|
- /**
|
|
|
304
|
- * 关键字中含性别,则加上性别的过滤条件
|
|
|
305
|
- *
|
|
|
306
|
- * @param keyword
|
|
|
307
|
- * @param paramMap
|
|
|
308
|
- */
|
|
|
309
|
- public void dealKeywordOfGender(String keyword, Map<String, String> paramMap) {
|
|
|
310
|
- // 如果参数中已经包含了性别,则不处理
|
|
|
311
|
- String gender = paramMap.get(SearchRequestParams.PARAM_SEARCH_GENDER);
|
|
|
312
|
- if (StringUtils.isNotBlank(gender)) {
|
|
|
313
|
- return;
|
|
|
314
|
- }
|
|
|
315
|
- // 对男女关键字做特殊处理
|
|
|
316
|
- boolean cotainBoy = keyword.contains("男");
|
|
|
317
|
- boolean cotainGirl = keyword.contains("女");
|
|
|
318
|
- // 对性别做特殊处理
|
|
|
319
|
- if (cotainBoy && !cotainGirl) {
|
|
|
320
|
- paramMap.put(SearchRequestParams.PARAM_SEARCH_GENDER, "1,3");
|
|
|
321
|
- return;
|
|
|
322
|
- }
|
|
|
323
|
- if (!cotainBoy && cotainGirl) {
|
|
|
324
|
- paramMap.put(SearchRequestParams.PARAM_SEARCH_GENDER, "2,3");
|
|
|
325
|
- return;
|
|
|
326
|
- }
|
|
|
327
|
- if (cotainBoy && cotainGirl) {
|
|
|
328
|
- paramMap.put(SearchRequestParams.PARAM_SEARCH_GENDER, "1,2,3");
|
|
|
329
|
- return;
|
|
|
330
|
- }
|
|
|
331
|
- }
|
|
|
332
|
-
|
|
|
333
|
- // 获取MultiMatchQueryBuilder的类型
|
|
|
334
|
- public MultiMatchQueryBuilder.Type getMultiMatchQueryBuilderType() {
|
|
|
335
|
- String configMultiMatchQueryType = searchServiceConfiger.getSearchMultiMatchQueryType();
|
|
|
336
|
- return SearchFieldUtils.getMultiMatchQueryBuilderType(configMultiMatchQueryType);
|
|
|
337
|
- }
|
|
|
338
|
-
|
|
|
339
|
- /**
|
|
|
340
|
- * 构造活动相关的过滤条件
|
|
|
341
|
- *
|
|
|
342
|
- * @param paramMap
|
|
|
343
|
- * @return
|
|
|
344
|
- */
|
|
|
345
|
- public BoolQueryBuilder getActivitiesTermsBuilder(Map<String, String> paramMap) {
|
|
|
346
|
- // 增加活动模板相关的过滤条件
|
|
|
347
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ACT_TEMP) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_TEMP))) {
|
|
|
348
|
- BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery();
|
|
|
349
|
- nestedBoolFilter.must(QueryBuilders.termQuery("activities.template_id", paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_TEMP)));
|
|
|
350
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ACT_REC) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_REC))) {
|
|
|
351
|
- nestedBoolFilter.must(QueryBuilders.termQuery("activities.is_recommend", paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_REC)));
|
|
|
352
|
- }
|
|
|
353
|
- if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ACT_STATUS) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_STATUS))) {
|
|
|
354
|
- nestedBoolFilter.must(QueryBuilders.termQuery("activities.status", paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_STATUS)));
|
|
|
355
|
- }
|
|
|
356
|
- return nestedBoolFilter;
|
|
|
357
|
- }
|
|
|
358
|
- return null;
|
|
|
359
|
- }
|
|
|
360
|
-
|
|
|
361
|
- /**
|
|
|
362
|
- * 构造商品池相关的过滤条件
|
|
|
363
|
- *
|
|
|
364
|
- * @param paramMap
|
|
|
365
|
- * @return
|
|
|
366
|
- */
|
|
|
367
|
- public BoolQueryBuilder getPoolIdTermsBuilder(Map<String, String> paramMap) {
|
|
|
368
|
- // 增加商品池相关的过滤条件
|
|
|
369
|
- if (paramMap.containsKey("filter_poolId") && StringUtils.isNotBlank("filter_poolId")) {
|
|
|
370
|
- BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery();
|
|
|
371
|
- nestedBoolFilter.must(QueryBuilders.termQuery("pools.pool_id", paramMap.get("filter_poolId")));
|
|
|
372
|
- return nestedBoolFilter;
|
|
|
373
|
- }
|
|
|
374
|
- return null;
|
|
|
375
|
- }
|
|
|
376
|
-
|
|
|
377
|
- /**
|
|
|
378
|
- * 自定义标签过滤
|
|
|
379
|
- *
|
|
|
380
|
- * @param paramMap
|
|
|
381
|
- * @return
|
|
|
382
|
- */
|
|
|
383
|
- public BoolQueryBuilder getCustomizeTagBuilder(Map<String, String> paramMap) {
|
|
|
384
|
- if (paramMap.containsKey(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG) && StringUtils.isNotBlank(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG)) {
|
|
|
385
|
- int[] ids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG), ",");
|
|
|
386
|
- BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery();
|
|
|
387
|
- nestedBoolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.customizeTagsId, ids));
|
|
|
388
|
- return nestedBoolFilter;
|
|
|
389
|
- }
|
|
|
390
|
- return null;
|
|
|
391
|
- }
|
24
|
+ @Autowired
|
|
|
25
|
+ private SearchDynamicConfigService dynamicConfig;
|
|
|
26
|
+ @Autowired
|
|
|
27
|
+ private SearchServiceConfiger searchServiceConfiger;
|
|
|
28
|
+ @Autowired
|
|
|
29
|
+ private SearchDynamicConfigService searchDynamicConfigService;
|
|
|
30
|
+
|
|
|
31
|
+ public int getPage(Map<String, String> paramMap) {
|
|
|
32
|
+ return StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
|
35
|
+ public int getPageSize(Map<String, String> paramMap) {
|
|
|
36
|
+ return StringUtils.isBlank(paramMap.get("viewNum")) ? 60 : Integer.parseInt(paramMap.get("viewNum"));
|
|
|
37
|
+ }
|
|
|
38
|
+
|
|
|
39
|
+ public boolean isPersionalScene(Map<String, String> paramMap) {
|
|
|
40
|
+ if (!searchDynamicConfigService.openPersonalized()) {
|
|
|
41
|
+ return false;
|
|
|
42
|
+ }
|
|
|
43
|
+ if (!this.isOrderEmpty(paramMap)) {
|
|
|
44
|
+ return false;
|
|
|
45
|
+ }
|
|
|
46
|
+ if (this.hasUid(paramMap)) {
|
|
|
47
|
+ return true;
|
|
|
48
|
+ }
|
|
|
49
|
+ if (this.hasUdid(paramMap)) {
|
|
|
50
|
+ return true;
|
|
|
51
|
+ }
|
|
|
52
|
+ return false;
|
|
|
53
|
+ }
|
|
|
54
|
+
|
|
|
55
|
+ public long getTotalPage(long total, int size) {
|
|
|
56
|
+ return PageUtils.getTotalPage(total, size);
|
|
|
57
|
+ }
|
|
|
58
|
+
|
|
|
59
|
+ public int getUid(Map<String, String> paramMap) {
|
|
|
60
|
+ try {
|
|
|
61
|
+ return MapUtils.getIntValue(paramMap, "uid", 0);
|
|
|
62
|
+ } catch (Exception e) {
|
|
|
63
|
+ return 0;
|
|
|
64
|
+ }
|
|
|
65
|
+ }
|
|
|
66
|
+
|
|
|
67
|
+ public String getUdid(Map<String, String> paramMap) {
|
|
|
68
|
+ try {
|
|
|
69
|
+ return MapUtils.getString(paramMap, "udid", "");
|
|
|
70
|
+ } catch (Exception e) {
|
|
|
71
|
+ return "";
|
|
|
72
|
+ }
|
|
|
73
|
+ }
|
|
|
74
|
+
|
|
|
75
|
+ public boolean hasUid(Map<String, String> paramMap) {
|
|
|
76
|
+ return this.getUid(paramMap) > 0;
|
|
|
77
|
+ }
|
|
|
78
|
+
|
|
|
79
|
+ public boolean hasUdid(Map<String, String> paramMap) {
|
|
|
80
|
+ return StringUtils.isBlank(this.getUdid(paramMap))?false:true;
|
|
|
81
|
+ }
|
|
|
82
|
+
|
|
|
83
|
+
|
|
|
84
|
+ /**
|
|
|
85
|
+ * 是否是默认的模糊搜索
|
|
|
86
|
+ *
|
|
|
87
|
+ * @param paramMap
|
|
|
88
|
+ * @return
|
|
|
89
|
+ */
|
|
|
90
|
+ public boolean isFuzzySearchPageDefault(Map<String, String> paramMap) {
|
|
|
91
|
+ String query = paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY);
|
|
|
92
|
+ if (StringUtils.isBlank(query)) {
|
|
|
93
|
+ return false;
|
|
|
94
|
+ }
|
|
|
95
|
+ if (!this.isOrderEmpty(paramMap)) {
|
|
|
96
|
+ return false;
|
|
|
97
|
+ }
|
|
|
98
|
+ String pageId = paramMap.get(SearchRequestParams.PARAM_SEARCH_PAGEID);
|
|
|
99
|
+ if (!SearchPageIdDefine.PAGE_ID_SEARCH.equalsIgnoreCase(pageId)) {
|
|
|
100
|
+ return false;
|
|
|
101
|
+ }
|
|
|
102
|
+ return true;
|
|
|
103
|
+ }
|
|
|
104
|
+
|
|
|
105
|
+ /**
|
|
|
106
|
+ * 是否需要开启个性化
|
|
|
107
|
+ *
|
|
|
108
|
+ * @param paramMap
|
|
|
109
|
+ * @return
|
|
|
110
|
+ */
|
|
|
111
|
+ public boolean isNeedPersonalSearch(Map<String, String> paramMap) {
|
|
|
112
|
+ // 从 zk中动态获取是否使用个性化
|
|
|
113
|
+ boolean openPersonalized = dynamicConfig.openPersonalized();
|
|
|
114
|
+ if (!openPersonalized) {
|
|
|
115
|
+ return false;
|
|
|
116
|
+ }
|
|
|
117
|
+ if (!this.hasUid(paramMap)) {
|
|
|
118
|
+ return false;
|
|
|
119
|
+ }
|
|
|
120
|
+ if (!this.isOrderEmpty(paramMap)) {
|
|
|
121
|
+ return false;
|
|
|
122
|
+ }
|
|
|
123
|
+ return true;
|
|
|
124
|
+ }
|
|
|
125
|
+
|
|
|
126
|
+ /**
|
|
|
127
|
+ * 是否需要对某个SKN加分
|
|
|
128
|
+ *
|
|
|
129
|
+ * @param paramMap
|
|
|
130
|
+ * @return
|
|
|
131
|
+ */
|
|
|
132
|
+ public boolean isFirstProductSknSearch(Map<String, String> paramMap) {
|
|
|
133
|
+ String first_productskn = paramMap.get(SearchRequestParams.PARAM_SEARCH_FIRST_PRODUCRSKN);
|
|
|
134
|
+ if (StringUtils.isBlank(first_productskn)) {
|
|
|
135
|
+ return false;
|
|
|
136
|
+ }
|
|
|
137
|
+ if (!this.isOrderEmpty(paramMap)) {
|
|
|
138
|
+ return false;
|
|
|
139
|
+ }
|
|
|
140
|
+ return true;
|
|
|
141
|
+ }
|
|
|
142
|
+
|
|
|
143
|
+ /**
|
|
|
144
|
+ * 是否需要对频道降分
|
|
|
145
|
+ *
|
|
|
146
|
+ * @param paramMap
|
|
|
147
|
+ * @return
|
|
|
148
|
+ */
|
|
|
149
|
+ public boolean isNeedDeScoreForChannel(Map<String, String> paramMap) {
|
|
|
150
|
+ String physicalChannel = paramMap.get(SearchRequestParams.PARAM_SEARCH_PHYSICAL_CHANNEL);
|
|
|
151
|
+ if (StringUtils.isBlank(physicalChannel)) {
|
|
|
152
|
+ return false;
|
|
|
153
|
+ }
|
|
|
154
|
+ if (!isFuzzySearchPageDefault(paramMap)) {
|
|
|
155
|
+ return false;
|
|
|
156
|
+ }
|
|
|
157
|
+ if (!dynamicConfig.isDeScorePhysicalChannelOpen()) {
|
|
|
158
|
+ return false;
|
|
|
159
|
+ }
|
|
|
160
|
+ return true;
|
|
|
161
|
+ }
|
|
|
162
|
+
|
|
|
163
|
+ /**
|
|
|
164
|
+ * 判断搜索是否需要包含全球购
|
|
|
165
|
+ *
|
|
|
166
|
+ * @param paramMap
|
|
|
167
|
+ * @return
|
|
|
168
|
+ */
|
|
|
169
|
+ public boolean containGlobal(Map<String, String> paramMap) {
|
|
|
170
|
+ // 1、如果总开关关了,则肯定不包含全球购商品
|
|
|
171
|
+ boolean containglobal = dynamicConfig.containglobal();
|
|
|
172
|
+ if (!containglobal) {
|
|
|
173
|
+ return false;
|
|
|
174
|
+ }
|
|
|
175
|
+ // 2、如果前端传来的参数中不包含contain_global!=Y,则不包含全球购
|
|
|
176
|
+ if (!paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL) || !"Y".equals(paramMap.get(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL))) {
|
|
|
177
|
+ return false;
|
|
|
178
|
+ }
|
|
|
179
|
+ return true;
|
|
|
180
|
+ }
|
|
|
181
|
+
|
|
|
182
|
+ /**
|
|
|
183
|
+ * 当前查询的关键字是否是skn
|
|
|
184
|
+ *
|
|
|
185
|
+ * @param keyword
|
|
|
186
|
+ * @return
|
|
|
187
|
+ */
|
|
|
188
|
+ public boolean isQuerySknOrSku(String keyword) {
|
|
|
189
|
+ try {
|
|
|
190
|
+ String key = "";
|
|
|
191
|
+ if (keyword.contains(" ")) {
|
|
|
192
|
+ key = keyword.split(" ")[0];
|
|
|
193
|
+ } else if (keyword.contains(",")) {
|
|
|
194
|
+ key = keyword.split(",")[0];
|
|
|
195
|
+ } else if (keyword.contains("+")) {
|
|
|
196
|
+ key = keyword.split("\\+")[0];
|
|
|
197
|
+ }
|
|
|
198
|
+ if ((CharUtils.isNumeric(keyword) && keyword.length() >= 6) || (CharUtils.isNumeric(key) && key.length() >= 6)) {
|
|
|
199
|
+ return true;
|
|
|
200
|
+ }
|
|
|
201
|
+ return false;
|
|
|
202
|
+ } catch (Exception e) {
|
|
|
203
|
+ return false;
|
|
|
204
|
+ }
|
|
|
205
|
+ }
|
|
|
206
|
+
|
|
|
207
|
+ /**
|
|
|
208
|
+ * 从搜索的关键词中提取出skn信息
|
|
|
209
|
+ *
|
|
|
210
|
+ * @param keyword
|
|
|
211
|
+ * @return
|
|
|
212
|
+ */
|
|
|
213
|
+ public List<Integer> getQuerySknList(String keyword) {
|
|
|
214
|
+ List<Integer> sknList = new ArrayList<>();
|
|
|
215
|
+
|
|
|
216
|
+ try {
|
|
|
217
|
+ String[] keys = null;
|
|
|
218
|
+ if (keyword.contains(" ")) {
|
|
|
219
|
+ keys = keyword.split(" ");
|
|
|
220
|
+ } else if (keyword.contains(",")) {
|
|
|
221
|
+ keys = keyword.split(",");
|
|
|
222
|
+ } else if (keyword.contains("+")) {
|
|
|
223
|
+ keys = keyword.split("\\+");
|
|
|
224
|
+ }
|
|
|
225
|
+
|
|
|
226
|
+ if (keys != null && keys.length > 0) {
|
|
|
227
|
+ for (String key : keys) {
|
|
|
228
|
+ if (CharUtils.isNumeric(key) && key.length() >= 7) {
|
|
|
229
|
+ sknList.add(Integer.valueOf(key));
|
|
|
230
|
+ }
|
|
|
231
|
+ }
|
|
|
232
|
+ }
|
|
|
233
|
+
|
|
|
234
|
+ return sknList;
|
|
|
235
|
+ } catch (Exception e) {
|
|
|
236
|
+ return sknList;
|
|
|
237
|
+ }
|
|
|
238
|
+ }
|
|
|
239
|
+
|
|
|
240
|
+ /**
|
|
|
241
|
+ * 是否是新品到着页
|
|
|
242
|
+ *
|
|
|
243
|
+ * @param paramMap
|
|
|
244
|
+ * @return
|
|
|
245
|
+ */
|
|
|
246
|
+ public boolean isNewRecPage(Map<String, String> paramMap) {
|
|
|
247
|
+ String pageId = paramMap.get(SearchRequestParams.PARAM_SEARCH_PAGEID);
|
|
|
248
|
+ if (StringUtils.isBlank(pageId) || !pageId.equals(SearchPageIdDefine.PAGE_ID_NEW)) {
|
|
|
249
|
+ return false;
|
|
|
250
|
+ }
|
|
|
251
|
+ return true;
|
|
|
252
|
+ }
|
|
|
253
|
+
|
|
|
254
|
+ /**
|
|
|
255
|
+ * 是否是新品到着默认页
|
|
|
256
|
+ *
|
|
|
257
|
+ * @param paramMap
|
|
|
258
|
+ * @return
|
|
|
259
|
+ */
|
|
|
260
|
+ public boolean isNewRecPageDefault(Map<String, String> paramMap) {
|
|
|
261
|
+ if (!isNewRecPage(paramMap)) {
|
|
|
262
|
+ return false;
|
|
|
263
|
+ }
|
|
|
264
|
+ if (!this.isOrderEmpty(paramMap)) {
|
|
|
265
|
+ return false;
|
|
|
266
|
+ }
|
|
|
267
|
+ return true;
|
|
|
268
|
+ }
|
|
|
269
|
+
|
|
|
270
|
+ /**
|
|
|
271
|
+ * 是否是新品到着页的人气排序
|
|
|
272
|
+ *
|
|
|
273
|
+ * @param paramMap
|
|
|
274
|
+ * @return
|
|
|
275
|
+ */
|
|
|
276
|
+ public boolean isNewRecHeatValueDescSearch(Map<String, String> paramMap) {
|
|
|
277
|
+ if (!this.isNewRecPage(paramMap)) {
|
|
|
278
|
+ return false;
|
|
|
279
|
+ }
|
|
|
280
|
+ String order = paramMap.get(SearchRequestParams.PARAM_SEARCH_ORDER);
|
|
|
281
|
+ if (StringUtils.isBlank(order)) {
|
|
|
282
|
+ return false;
|
|
|
283
|
+ }
|
|
|
284
|
+ if (!order.contains("heatValue")) {
|
|
|
285
|
+ return false;
|
|
|
286
|
+ }
|
|
|
287
|
+ return true;
|
|
|
288
|
+ }
|
|
|
289
|
+
|
|
|
290
|
+ /**
|
|
|
291
|
+ * 是否未传order
|
|
|
292
|
+ *
|
|
|
293
|
+ * @param paramMap
|
|
|
294
|
+ * @return
|
|
|
295
|
+ */
|
|
|
296
|
+ public boolean isOrderEmpty(Map<String, String> paramMap) {
|
|
|
297
|
+ String order = paramMap.get(SearchRequestParams.PARAM_SEARCH_ORDER);
|
|
|
298
|
+ if (!StringUtils.isBlank(order)) {
|
|
|
299
|
+ return false;
|
|
|
300
|
+ }
|
|
|
301
|
+ return true;
|
|
|
302
|
+ }
|
|
|
303
|
+
|
|
|
304
|
+ /**
|
|
|
305
|
+ * 是否是品类列表的默认页
|
|
|
306
|
+ *
|
|
|
307
|
+ * @param paramMap
|
|
|
308
|
+ * @return
|
|
|
309
|
+ */
|
|
|
310
|
+ public boolean isSortPageDefault(Map<String, String> paramMap) {
|
|
|
311
|
+ String pageId = paramMap.get(SearchRequestParams.PARAM_SEARCH_PAGEID);
|
|
|
312
|
+ if (StringUtils.isBlank(pageId) || !pageId.equals(SearchPageIdDefine.PAGE_ID_SORT)) {
|
|
|
313
|
+ return false;
|
|
|
314
|
+ }
|
|
|
315
|
+ if (!this.isOrderEmpty(paramMap)) {
|
|
|
316
|
+ return false;
|
|
|
317
|
+ }
|
|
|
318
|
+ return true;
|
|
|
319
|
+ }
|
|
|
320
|
+
|
|
|
321
|
+ /**
|
|
|
322
|
+ * 关键字中含性别,则加上性别的过滤条件
|
|
|
323
|
+ *
|
|
|
324
|
+ * @param keyword
|
|
|
325
|
+ * @param paramMap
|
|
|
326
|
+ */
|
|
|
327
|
+ public void dealKeywordOfGender(String keyword, Map<String, String> paramMap) {
|
|
|
328
|
+ // 如果参数中已经包含了性别,则不处理
|
|
|
329
|
+ String gender = paramMap.get(SearchRequestParams.PARAM_SEARCH_GENDER);
|
|
|
330
|
+ if (StringUtils.isNotBlank(gender)) {
|
|
|
331
|
+ return;
|
|
|
332
|
+ }
|
|
|
333
|
+ // 对男女关键字做特殊处理
|
|
|
334
|
+ boolean cotainBoy = keyword.contains("男");
|
|
|
335
|
+ boolean cotainGirl = keyword.contains("女");
|
|
|
336
|
+ // 对性别做特殊处理
|
|
|
337
|
+ if (cotainBoy && !cotainGirl) {
|
|
|
338
|
+ paramMap.put(SearchRequestParams.PARAM_SEARCH_GENDER, "1,3");
|
|
|
339
|
+ return;
|
|
|
340
|
+ }
|
|
|
341
|
+ if (!cotainBoy && cotainGirl) {
|
|
|
342
|
+ paramMap.put(SearchRequestParams.PARAM_SEARCH_GENDER, "2,3");
|
|
|
343
|
+ return;
|
|
|
344
|
+ }
|
|
|
345
|
+ if (cotainBoy && cotainGirl) {
|
|
|
346
|
+ paramMap.put(SearchRequestParams.PARAM_SEARCH_GENDER, "1,2,3");
|
|
|
347
|
+ return;
|
|
|
348
|
+ }
|
|
|
349
|
+ }
|
|
|
350
|
+
|
|
|
351
|
+ // 获取MultiMatchQueryBuilder的类型
|
|
|
352
|
+ public MultiMatchQueryBuilder.Type getMultiMatchQueryBuilderType() {
|
|
|
353
|
+ String configMultiMatchQueryType = searchServiceConfiger.getSearchMultiMatchQueryType();
|
|
|
354
|
+ return SearchFieldUtils.getMultiMatchQueryBuilderType(configMultiMatchQueryType);
|
|
|
355
|
+ }
|
|
|
356
|
+
|
|
|
357
|
+ /**
|
|
|
358
|
+ * 构造活动相关的过滤条件
|
|
|
359
|
+ *
|
|
|
360
|
+ * @param paramMap
|
|
|
361
|
+ * @return
|
|
|
362
|
+ */
|
|
|
363
|
+ public BoolQueryBuilder getActivitiesTermsBuilder(Map<String, String> paramMap) {
|
|
|
364
|
+ // 增加活动模板相关的过滤条件
|
|
|
365
|
+ if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ACT_TEMP) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_TEMP))) {
|
|
|
366
|
+ BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery();
|
|
|
367
|
+ nestedBoolFilter.must(QueryBuilders.termQuery("activities.template_id", paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_TEMP)));
|
|
|
368
|
+ if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ACT_REC) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_REC))) {
|
|
|
369
|
+ nestedBoolFilter.must(QueryBuilders.termQuery("activities.is_recommend", paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_REC)));
|
|
|
370
|
+ }
|
|
|
371
|
+ if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ACT_STATUS) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_STATUS))) {
|
|
|
372
|
+ nestedBoolFilter.must(QueryBuilders.termQuery("activities.status", paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_STATUS)));
|
|
|
373
|
+ }
|
|
|
374
|
+ return nestedBoolFilter;
|
|
|
375
|
+ }
|
|
|
376
|
+ return null;
|
|
|
377
|
+ }
|
|
|
378
|
+
|
|
|
379
|
+ /**
|
|
|
380
|
+ * 构造商品池相关的过滤条件
|
|
|
381
|
+ *
|
|
|
382
|
+ * @param paramMap
|
|
|
383
|
+ * @return
|
|
|
384
|
+ */
|
|
|
385
|
+ public BoolQueryBuilder getPoolIdTermsBuilder(Map<String, String> paramMap) {
|
|
|
386
|
+ // 增加商品池相关的过滤条件
|
|
|
387
|
+ if (paramMap.containsKey("filter_poolId") && StringUtils.isNotBlank("filter_poolId")) {
|
|
|
388
|
+ BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery();
|
|
|
389
|
+ nestedBoolFilter.must(QueryBuilders.termQuery("pools.pool_id", paramMap.get("filter_poolId")));
|
|
|
390
|
+ return nestedBoolFilter;
|
|
|
391
|
+ }
|
|
|
392
|
+ return null;
|
|
|
393
|
+ }
|
|
|
394
|
+
|
|
|
395
|
+ /**
|
|
|
396
|
+ * 自定义标签过滤
|
|
|
397
|
+ *
|
|
|
398
|
+ * @param paramMap
|
|
|
399
|
+ * @return
|
|
|
400
|
+ */
|
|
|
401
|
+ public BoolQueryBuilder getCustomizeTagBuilder(Map<String, String> paramMap) {
|
|
|
402
|
+ if (paramMap.containsKey(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG) && StringUtils.isNotBlank(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG)) {
|
|
|
403
|
+ int[] ids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG), ",");
|
|
|
404
|
+ BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery();
|
|
|
405
|
+ nestedBoolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.customizeTagsId, ids));
|
|
|
406
|
+ return nestedBoolFilter;
|
|
|
407
|
+ }
|
|
|
408
|
+ return null;
|
|
|
409
|
+ }
|
392
|
} |
410
|
} |