Showing
11 changed files
with
72 additions
and
68 deletions
@@ -7,18 +7,19 @@ public class UfoSearchRequestParams { | @@ -7,18 +7,19 @@ public class UfoSearchRequestParams { | ||
7 | public static final String UFO_PARAM_SEARCH_VIEWNUM = "viewNum"; // 数量 | 7 | public static final String UFO_PARAM_SEARCH_VIEWNUM = "viewNum"; // 数量 |
8 | 8 | ||
9 | //ufo | 9 | //ufo |
10 | - public static final String UFOPRODUCTINDEX_SEARCH_QUERY = "query"; | ||
11 | - public static final String UFOPRODUCTINDEX_PARAM_ID = "id"; | ||
12 | - public static final String UFOPRODUCTINDEX_PARAM_NOT_ID = "not_id"; | ||
13 | - public static final String UFOPRODUCTINDEX_PARAM_MAXSORT = "maxSort"; | ||
14 | - public static final String UFOPRODUCTINDEX_PARAM_MIDSORT = "midSort"; | ||
15 | - public static final String UFOPRODUCTINDEX_PARAM_GENDER = "gender"; | ||
16 | - public static final String UFOPRODUCTINDEX_PARAM_BRAND = "brand"; | ||
17 | - public static final String UFOPRODUCTINDEX_PARAM_NOT_BRAND = "not_brand"; | ||
18 | - public static final String UFOPRODUCTINDEX_PARAM_SERIES = "series"; | ||
19 | - public static final String UFOPRODUCTINDEX_PARAM_SIZE = "size"; | ||
20 | - public static final String UFOPRODUCTINDEX_PARAM_COLOR = "color"; | ||
21 | - public static final String UFOPRODUCTINDEX_PARAM_POOL = "pool"; | 10 | + public static final String UFO_PARAM_SEARCH_QUERY = "query"; |
11 | + public static final String UFO_PARAM_ID = "id"; | ||
12 | + public static final String UFO_PARAM_NOT_ID = "not_id"; | ||
13 | + public static final String UFO_PARAM_MAXSORT = "maxSort"; | ||
14 | + public static final String UFO_PARAM_MIDSORT = "midSort"; | ||
15 | + public static final String UFO_PARAM_GENDER = "gender"; | ||
16 | + public static final String UFO_PARAM_BRAND = "brand"; | ||
17 | + public static final String UFO_PARAM_NOT_BRAND = "not_brand"; | ||
18 | + public static final String UFO_PARAM_SERIES = "series"; | ||
19 | + public static final String UFO_PARAM_SIZE = "size"; | ||
20 | + public static final String UFO_PARAM_COLOR = "color"; | ||
21 | + public static final String UFO_PARAM_POOL = "pool"; | ||
22 | + public static final String UFO_PARAM_SHOW_CHANNEL = "showChannel"; | ||
22 | 23 | ||
23 | // ufo发售日历 商品类型 | 24 | // ufo发售日历 商品类型 |
24 | public static final String UFO_PARAM_SEARCH_SALE_CALENDAR_PRODUCT_TYPE = "product_type"; | 25 | public static final String UFO_PARAM_SEARCH_SALE_CALENDAR_PRODUCT_TYPE = "product_type"; |
@@ -31,4 +32,8 @@ public class UfoSearchRequestParams { | @@ -31,4 +32,8 @@ public class UfoSearchRequestParams { | ||
31 | // ufo 融入有货 | 32 | // ufo 融入有货 |
32 | public static final String UFO_PARAM_SEARCH_CONTAIN_YOHO = "contain_yoho"; | 33 | public static final String UFO_PARAM_SEARCH_CONTAIN_YOHO = "contain_yoho"; |
33 | 34 | ||
35 | + //二手列表 | ||
36 | + public static final String UFO_PARAM_MAXSTORAGEPRICE_ID = "maxStoragePriceId"; | ||
37 | + public static final String UFO_PARAM_PRE_SALE_FLAG = "preSaleFlag"; | ||
38 | + | ||
34 | } | 39 | } |
1 | package com.yoho.search.restapi.ufo; | 1 | package com.yoho.search.restapi.ufo; |
2 | 2 | ||
3 | +import com.yoho.search.common.UfoSearchRequestParams; | ||
3 | import com.yoho.search.common.utils.HttpServletRequestUtils; | 4 | import com.yoho.search.common.utils.HttpServletRequestUtils; |
4 | import com.yoho.search.models.SearchApiResult; | 5 | import com.yoho.search.models.SearchApiResult; |
5 | import com.yoho.search.service.scene.ufo.UfoMaxStoragePriceIdService; | 6 | import com.yoho.search.service.scene.ufo.UfoMaxStoragePriceIdService; |
@@ -24,7 +25,8 @@ public class UfoSecondhandController { | @@ -24,7 +25,8 @@ public class UfoSecondhandController { | ||
24 | public SearchApiResult secondHandSkupList(HttpServletRequest request) { | 25 | public SearchApiResult secondHandSkupList(HttpServletRequest request) { |
25 | Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); | 26 | Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); |
26 | int maxStoragePriceId = ufoMaxStoragePriceIdService.queryUfoMaxStoragePriceId(); | 27 | int maxStoragePriceId = ufoMaxStoragePriceIdService.queryUfoMaxStoragePriceId(); |
27 | - paramMap.put("maxStoragePriceId",maxStoragePriceId+""); | 28 | + paramMap.put(UfoSearchRequestParams.UFO_PARAM_MAXSTORAGEPRICE_ID, maxStoragePriceId + ""); |
28 | return ufoSecondhandSkupService.secondHandSkupList(paramMap); | 29 | return ufoSecondhandSkupService.secondHandSkupList(paramMap); |
29 | } | 30 | } |
31 | + | ||
30 | } | 32 | } |
@@ -63,17 +63,18 @@ public class UfoSearchQueryHelper extends BaseService { | @@ -63,17 +63,18 @@ public class UfoSearchQueryHelper extends BaseService { | ||
63 | public BoolQueryBuilder constructFilterBuilder(Map<String, String> paramMap) throws Exception { | 63 | public BoolQueryBuilder constructFilterBuilder(Map<String, String> paramMap) throws Exception { |
64 | BoolQueryBuilder boolFilter = QueryBuilders.boolQuery(); | 64 | BoolQueryBuilder boolFilter = QueryBuilders.boolQuery(); |
65 | //参数过滤 | 65 | //参数过滤 |
66 | - this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_ID, UfoProductIndexEsField.id); | ||
67 | - this.addMustNotIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_NOT_ID, UfoProductIndexEsField.id); | ||
68 | - this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_MAXSORT, UfoProductIndexEsField.maxSortId); | ||
69 | - this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_MIDSORT, UfoProductIndexEsField.midSortId); | ||
70 | - this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_GENDER, UfoProductIndexEsField.gender); | ||
71 | - this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_BRAND, UfoProductIndexEsField.brandId); | ||
72 | - this.addMustNotIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_NOT_BRAND, UfoProductIndexEsField.brandId); | ||
73 | - this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_SERIES, UfoProductIndexEsField.seriesId); | ||
74 | - this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_SIZE, UfoProductIndexEsField.sizeIds); | ||
75 | - this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_COLOR, UfoProductIndexEsField.colorIds); | ||
76 | - this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_POOL, UfoProductIndexEsField.poolIds); | 66 | + this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_ID, UfoProductIndexEsField.id); |
67 | + this.addMustNotIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_NOT_ID, UfoProductIndexEsField.id); | ||
68 | + this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_MAXSORT, UfoProductIndexEsField.maxSortId); | ||
69 | + this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_MIDSORT, UfoProductIndexEsField.midSortId); | ||
70 | + this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_GENDER, UfoProductIndexEsField.gender); | ||
71 | + this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_BRAND, UfoProductIndexEsField.brandId); | ||
72 | + this.addMustNotIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_NOT_BRAND, UfoProductIndexEsField.brandId); | ||
73 | + this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_SERIES, UfoProductIndexEsField.seriesId); | ||
74 | + this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_SIZE, UfoProductIndexEsField.sizeIds); | ||
75 | + this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_COLOR, UfoProductIndexEsField.colorIds); | ||
76 | + this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_POOL, UfoProductIndexEsField.poolIds); | ||
77 | + this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_SHOW_CHANNEL, UfoProductIndexEsField.showChannel); | ||
77 | 78 | ||
78 | //是否包含有货 | 79 | //是否包含有货 |
79 | if (!this.containYoho(paramMap)) { | 80 | if (!this.containYoho(paramMap)) { |
@@ -110,7 +111,7 @@ public class UfoSearchQueryHelper extends BaseService { | @@ -110,7 +111,7 @@ public class UfoSearchQueryHelper extends BaseService { | ||
110 | 111 | ||
111 | public BoolQueryBuilder constructFilterBuilderIdFilter(Map<String, String> paramMap) throws Exception { | 112 | public BoolQueryBuilder constructFilterBuilderIdFilter(Map<String, String> paramMap) throws Exception { |
112 | BoolQueryBuilder boolFilter = QueryBuilders.boolQuery(); | 113 | BoolQueryBuilder boolFilter = QueryBuilders.boolQuery(); |
113 | - this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_ID, UfoProductIndexEsField.id); | 114 | + this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_ID, UfoProductIndexEsField.id); |
114 | return boolFilter; | 115 | return boolFilter; |
115 | } | 116 | } |
116 | 117 | ||
@@ -130,25 +131,25 @@ public class UfoSearchQueryHelper extends BaseService { | @@ -130,25 +131,25 @@ public class UfoSearchQueryHelper extends BaseService { | ||
130 | boolFilter.mustNot(QueryBuilders.termsQuery(esField, values)); | 131 | boolFilter.mustNot(QueryBuilders.termsQuery(esField, values)); |
131 | } | 132 | } |
132 | 133 | ||
133 | - | ||
134 | public QueryBuilder constructQueryBuilder(Map<String, String> paramMap) { | 134 | public QueryBuilder constructQueryBuilder(Map<String, String> paramMap) { |
135 | - // 0、处理查询关键字 | ||
136 | - String query = SearchKeyWordUtils.getUfoParamKeyword(paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY); | 135 | + // 1、处理查询关键字 |
136 | + String query = SearchKeyWordUtils.getUfoParamKeyword(paramMap, UfoSearchRequestParams.UFO_PARAM_SEARCH_QUERY); | ||
137 | if (StringUtils.isBlank(query)) { | 137 | if (StringUtils.isBlank(query)) { |
138 | return QueryBuilders.matchAllQuery(); | 138 | return QueryBuilders.matchAllQuery(); |
139 | } | 139 | } |
140 | - paramMap.put(UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY, query); | 140 | + paramMap.put(UfoSearchRequestParams.UFO_PARAM_SEARCH_QUERY, query); |
141 | 141 | ||
142 | - // 1、处理查询中包含性别的情况 | 142 | + // 2、处理查询中包含性别的情况 |
143 | searchCommonHelper.dealKeywordOfGender(query, paramMap); | 143 | searchCommonHelper.dealKeywordOfGender(query, paramMap); |
144 | 144 | ||
145 | - // 2、构建多字段匹配 | 145 | + // 3、构建多字段匹配 |
146 | MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(query); | 146 | MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(query); |
147 | MultiMatchQueryBuilder.Type multiMatchQueryBuilderType = searchCommonHelper.getMultiMatchQueryBuilderType(); | 147 | MultiMatchQueryBuilder.Type multiMatchQueryBuilderType = searchCommonHelper.getMultiMatchQueryBuilderType(); |
148 | if (multiMatchQueryBuilderType != null) { | 148 | if (multiMatchQueryBuilderType != null) { |
149 | queryBuilder.type(multiMatchQueryBuilderType); | 149 | queryBuilder.type(multiMatchQueryBuilderType); |
150 | } | 150 | } |
151 | - // 3.如果查询的是skn或skuIds | 151 | + |
152 | + // 4.如果查询的是skn或skuIds | ||
152 | if (searchCommonHelper.isQueryUfoProductId(query)) { | 153 | if (searchCommonHelper.isQueryUfoProductId(query)) { |
153 | queryBuilder.field(UfoProductIndexEsField.idString); | 154 | queryBuilder.field(UfoProductIndexEsField.idString); |
154 | queryBuilder.field(UfoProductIndexEsField.productCode); | 155 | queryBuilder.field(UfoProductIndexEsField.productCode); |
@@ -156,14 +157,16 @@ public class UfoSearchQueryHelper extends BaseService { | @@ -156,14 +157,16 @@ public class UfoSearchQueryHelper extends BaseService { | ||
156 | queryBuilder.minimumShouldMatch("1"); | 157 | queryBuilder.minimumShouldMatch("1"); |
157 | return queryBuilder; | 158 | return queryBuilder; |
158 | } | 159 | } |
159 | - // 4.设置查询字段和比重 | 160 | + |
161 | + // 5.设置查询字段和比重 | ||
160 | List<SearchField> searchFields = SearchFieldUtils.getUfoFuzzySearchFields(); | 162 | List<SearchField> searchFields = SearchFieldUtils.getUfoFuzzySearchFields(); |
161 | if (CollectionUtils.isNotEmpty(searchFields)) { | 163 | if (CollectionUtils.isNotEmpty(searchFields)) { |
162 | for (SearchField searchField : searchFields) { | 164 | for (SearchField searchField : searchFields) { |
163 | queryBuilder.field(searchField.getEsField(), searchField.getBoost()); | 165 | queryBuilder.field(searchField.getEsField(), searchField.getBoost()); |
164 | } | 166 | } |
165 | } | 167 | } |
166 | - // 5.设置 | 168 | + |
169 | + // 6.设置 | ||
167 | if ("or".equalsIgnoreCase(configurer.getSearchOperator())) { | 170 | if ("or".equalsIgnoreCase(configurer.getSearchOperator())) { |
168 | queryBuilder.operator(Operator.OR); | 171 | queryBuilder.operator(Operator.OR); |
169 | queryBuilder.minimumShouldMatch(configurer.getUfoSearchMinimumShouldMatch()); | 172 | queryBuilder.minimumShouldMatch(configurer.getUfoSearchMinimumShouldMatch()); |
@@ -74,7 +74,7 @@ public class UfoProductIndexBaseService { | @@ -74,7 +74,7 @@ public class UfoProductIndexBaseService { | ||
74 | return productMap; | 74 | return productMap; |
75 | } | 75 | } |
76 | 76 | ||
77 | - public Map<Integer,Map<String,Object>> queryMapByProductIds(final Collection<?> ufoProductIds) { | 77 | + public Map<Integer,Map<String,Object>> queryUfoProductMapByProductIds(final Collection<?> ufoProductIds) { |
78 | List<Map<String, Object>> resultList = this.queryListByProductIds(ufoProductIds); | 78 | List<Map<String, Object>> resultList = this.queryListByProductIds(ufoProductIds); |
79 | return resultList.stream().collect(Collectors.toMap(a->MapUtils.getIntValue(a,"id",0),p->p)); | 79 | return resultList.stream().collect(Collectors.toMap(a->MapUtils.getIntValue(a,"id",0),p->p)); |
80 | } | 80 | } |
@@ -49,7 +49,7 @@ public class UfoFavoriteService { | @@ -49,7 +49,7 @@ public class UfoFavoriteService { | ||
49 | public SearchApiResult productList(Map<String, String> paramMap) { | 49 | public SearchApiResult productList(Map<String, String> paramMap) { |
50 | try { | 50 | try { |
51 | // 1、参数校验 | 51 | // 1、参数校验 |
52 | - if (StringUtils.isBlank(paramMap.get(UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_ID))) { | 52 | + if (StringUtils.isBlank(paramMap.get(UfoSearchRequestParams.UFO_PARAM_ID))) { |
53 | return new SearchApiResult().setCode(400).setMessage("id参数必传"); | 53 | return new SearchApiResult().setCode(400).setMessage("id参数必传"); |
54 | } | 54 | } |
55 | int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum")); | 55 | int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum")); |
@@ -82,7 +82,7 @@ public class UfoFavoriteService { | @@ -82,7 +82,7 @@ public class UfoFavoriteService { | ||
82 | dataMap.put("page_total", searchResult.getTotalPage()); | 82 | dataMap.put("page_total", searchResult.getTotalPage()); |
83 | Map<String, Map<String, Object>> productReturnInfoMap = returnInfoList.stream().collect(Collectors.toMap(p -> p.get("id").toString(), p -> p)); | 83 | Map<String, Map<String, Object>> productReturnInfoMap = returnInfoList.stream().collect(Collectors.toMap(p -> p.get("id").toString(), p -> p)); |
84 | List<Map<String, Object>> productReturnInfoListSorted = new ArrayList<>(productReturnInfoMap.size()); | 84 | List<Map<String, Object>> productReturnInfoListSorted = new ArrayList<>(productReturnInfoMap.size()); |
85 | - List<String> idList = Arrays.asList(paramMap.get(UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_ID).split(",")); | 85 | + List<String> idList = Arrays.asList(paramMap.get(UfoSearchRequestParams.UFO_PARAM_ID).split(",")); |
86 | for (String id : idList) { | 86 | for (String id : idList) { |
87 | Map<String, Object> sknInfo = productReturnInfoMap.get(id); | 87 | Map<String, Object> sknInfo = productReturnInfoMap.get(id); |
88 | if (sknInfo != null) { | 88 | if (sknInfo != null) { |
@@ -138,7 +138,7 @@ public class UfoFuzzySceneService { | @@ -138,7 +138,7 @@ public class UfoFuzzySceneService { | ||
138 | public SearchParam buildSearchParamForProductCodeSearch(Map<String, String> paramMap, int pageSize, int page) throws Exception { | 138 | public SearchParam buildSearchParamForProductCodeSearch(Map<String, String> paramMap, int pageSize, int page) throws Exception { |
139 | SearchParam searchParam = new SearchParam(); | 139 | SearchParam searchParam = new SearchParam(); |
140 | // QUERY | 140 | // QUERY |
141 | - String query = SearchKeyWordUtils.getUfoParamKeyword(paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY); | 141 | + String query = SearchKeyWordUtils.getUfoParamKeyword(paramMap, UfoSearchRequestParams.UFO_PARAM_SEARCH_QUERY); |
142 | if (StringUtils.isBlank(query)) { | 142 | if (StringUtils.isBlank(query)) { |
143 | searchParam.setQuery(QueryBuilders.matchAllQuery()); | 143 | searchParam.setQuery(QueryBuilders.matchAllQuery()); |
144 | } else { | 144 | } else { |
@@ -53,7 +53,7 @@ public class UfoPoolSceneService { | @@ -53,7 +53,7 @@ public class UfoPoolSceneService { | ||
53 | public SearchApiResult productList(Map<String, String> paramMap) { | 53 | public SearchApiResult productList(Map<String, String> paramMap) { |
54 | try { | 54 | try { |
55 | // 1、参数校验 | 55 | // 1、参数校验 |
56 | - if (!paramMap.containsKey(UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_POOL)) { | 56 | + if (!paramMap.containsKey(UfoSearchRequestParams.UFO_PARAM_POOL)) { |
57 | return new SearchApiResult().setCode(400).setMessage("缺少必传pool参数"); | 57 | return new SearchApiResult().setCode(400).setMessage("缺少必传pool参数"); |
58 | } | 58 | } |
59 | int page = MapUtils.getIntValue(paramMap, "page", 1); | 59 | int page = MapUtils.getIntValue(paramMap, "page", 1); |
@@ -137,7 +137,7 @@ public class UfoPoolSceneService { | @@ -137,7 +137,7 @@ public class UfoPoolSceneService { | ||
137 | 137 | ||
138 | private int getPoolOrderBy(Map<String, Object> map, Map<String, String> paramMap) { | 138 | private int getPoolOrderBy(Map<String, Object> map, Map<String, String> paramMap) { |
139 | try { | 139 | try { |
140 | - String inputPoolId = MapUtils.getString(paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_POOL, ""); | 140 | + String inputPoolId = MapUtils.getString(paramMap, UfoSearchRequestParams.UFO_PARAM_POOL, ""); |
141 | if (StringUtils.isBlank(inputPoolId)) { | 141 | if (StringUtils.isBlank(inputPoolId)) { |
142 | return 0; | 142 | return 0; |
143 | } | 143 | } |
@@ -91,9 +91,10 @@ public class UfoProductListService { | @@ -91,9 +91,10 @@ public class UfoProductListService { | ||
91 | // QUERY | 91 | // QUERY |
92 | QueryBuilder queryBuilder = ufoSearchQueryHelper.constructQueryBuilder(paramMap); | 92 | QueryBuilder queryBuilder = ufoSearchQueryHelper.constructQueryBuilder(paramMap); |
93 | searchParam.setQuery(queryBuilder); | 93 | searchParam.setQuery(queryBuilder); |
94 | - //Filter | 94 | + // Filter |
95 | BoolQueryBuilder boolFilter = ufoSearchQueryHelper.constructFilterBuilder(paramMap); | 95 | BoolQueryBuilder boolFilter = ufoSearchQueryHelper.constructFilterBuilder(paramMap); |
96 | searchParam.setFiter(boolFilter); | 96 | searchParam.setFiter(boolFilter); |
97 | + // 聚合和分页 | ||
97 | searchParam.setAggregationBuilders(null); | 98 | searchParam.setAggregationBuilders(null); |
98 | searchParam.setSize(pageSize); | 99 | searchParam.setSize(pageSize); |
99 | searchParam.setOffset((page - 1) * pageSize); | 100 | searchParam.setOffset((page - 1) * pageSize); |
@@ -181,7 +182,7 @@ public class UfoProductListService { | @@ -181,7 +182,7 @@ public class UfoProductListService { | ||
181 | this.addReturnInfoList(paramMap, idList, returnInfoList, RECOMMEND_BY_SERIES_BRAND_LIMIT); | 182 | this.addReturnInfoList(paramMap, idList, returnInfoList, RECOMMEND_BY_SERIES_BRAND_LIMIT); |
182 | } | 183 | } |
183 | // 添加自定义标签 | 184 | // 添加自定义标签 |
184 | - customizeTagBaseService.fillCustomizeTag(returnInfoList,false); | 185 | + customizeTagBaseService.fillCustomizeTag(returnInfoList, false); |
185 | 186 | ||
186 | dataMap.put("total", returnInfoList.size()); | 187 | dataMap.put("total", returnInfoList.size()); |
187 | return searchApiResult; | 188 | return searchApiResult; |
@@ -52,23 +52,18 @@ public class UfoSecondhandSkupService { | @@ -52,23 +52,18 @@ public class UfoSecondhandSkupService { | ||
52 | if (page < 1 || pageSize < 0 || page * pageSize > 100000) { | 52 | if (page < 1 || pageSize < 0 || page * pageSize > 100000) { |
53 | return new SearchApiResult().setCode(400).setMessage("分页参数不合法"); | 53 | return new SearchApiResult().setCode(400).setMessage("分页参数不合法"); |
54 | } | 54 | } |
55 | - | ||
56 | // 2、构造SearchParam | 55 | // 2、构造SearchParam |
57 | SearchParam searchParam = new SearchParam(); | 56 | SearchParam searchParam = new SearchParam(); |
58 | BoolQueryBuilder boolFilter = this.builderFilter(paramMap); | 57 | BoolQueryBuilder boolFilter = this.builderFilter(paramMap); |
59 | searchParam.setFiter(boolFilter); | 58 | searchParam.setFiter(boolFilter); |
60 | searchParam.setQuery(QueryBuilders.matchAllQuery()); | 59 | searchParam.setQuery(QueryBuilders.matchAllQuery()); |
61 | - | ||
62 | // 3、构建分页参数 | 60 | // 3、构建分页参数 |
63 | searchParam.setSize(pageSize); | 61 | searchParam.setSize(pageSize); |
64 | searchParam.setOffset((page - 1) * pageSize); | 62 | searchParam.setOffset((page - 1) * pageSize); |
65 | - | ||
66 | // 4、设置排序字段 | 63 | // 4、设置排序字段 |
67 | searchParam.setSortBuilders(Arrays.asList(SortBuilders.fieldSort("id").order(SortOrder.DESC))); | 64 | searchParam.setSortBuilders(Arrays.asList(SortBuilders.fieldSort("id").order(SortOrder.DESC))); |
68 | - | ||
69 | // 5、执行搜索 | 65 | // 5、执行搜索 |
70 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_STORAGE_PRICE, searchParam); | 66 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_STORAGE_PRICE, searchParam); |
71 | - | ||
72 | // 6、构造搜索结果 | 67 | // 6、构造搜索结果 |
73 | List<Map<String, Object>> skupResultList = new ArrayList<>(); | 68 | List<Map<String, Object>> skupResultList = new ArrayList<>(); |
74 | List<Integer> ufoProductIds = new ArrayList<>(); | 69 | List<Integer> ufoProductIds = new ArrayList<>(); |
@@ -76,27 +71,26 @@ public class UfoSecondhandSkupService { | @@ -76,27 +71,26 @@ public class UfoSecondhandSkupService { | ||
76 | skupResultList.add(ufoStoragePriceIndexBaseService.buildStoragePriceMap(skupEsSource)); | 71 | skupResultList.add(ufoStoragePriceIndexBaseService.buildStoragePriceMap(skupEsSource)); |
77 | ufoProductIds.add(MapUtils.getIntValue(skupEsSource, "productId", 0)); | 72 | ufoProductIds.add(MapUtils.getIntValue(skupEsSource, "productId", 0)); |
78 | } | 73 | } |
79 | - | ||
80 | // 7、根据productIds查询商品信息 | 74 | // 7、根据productIds查询商品信息 |
81 | - Map<Integer, Map<String, Object>> results = ufoProductIndexBaseService.queryMapByProductIds(ufoProductIds); | 75 | + Map<Integer, Map<String, Object>> ufoProductMap = ufoProductIndexBaseService.queryUfoProductMapByProductIds(ufoProductIds); |
82 | skupResultList.stream().forEach(skupResult -> { | 76 | skupResultList.stream().forEach(skupResult -> { |
83 | int productId = MapUtils.getIntValue(skupResult, "product_id", 0); | 77 | int productId = MapUtils.getIntValue(skupResult, "product_id", 0); |
84 | - Map<String, Object> productInfo = results.get(productId); | ||
85 | - if (productInfo == null) { | 78 | + Map<String, Object> ufoProductInfo = ufoProductMap.get(productId); |
79 | + if (ufoProductInfo == null) { | ||
86 | skupResult.put("product_name", ""); | 80 | skupResult.put("product_name", ""); |
87 | skupResult.put("save_price", null); | 81 | skupResult.put("save_price", null); |
88 | return; | 82 | return; |
89 | } | 83 | } |
90 | - // 商品名称处理 | ||
91 | - skupResult.put("product_name", MapUtils.getString(productInfo, "product_name", "")); | ||
92 | - // 图片处理,二手图片不存在用默认的商品图片代替 | ||
93 | - String product_default_images = MapUtils.getString(productInfo, "default_images", ""); | 84 | + // 1) 商品名称处理 |
85 | + skupResult.put("product_name", MapUtils.getString(ufoProductInfo, "product_name", "")); | ||
86 | + // 2) 图片处理,二手图片不存在用默认的商品图片代替 | ||
87 | + String product_default_images = MapUtils.getString(ufoProductInfo, "default_images", ""); | ||
94 | if (StringUtils.isEmpty(MapUtils.getString(skupResult, "secondhand_image")) && StringUtils.isNotEmpty(product_default_images)) { | 88 | if (StringUtils.isEmpty(MapUtils.getString(skupResult, "secondhand_image")) && StringUtils.isNotEmpty(product_default_images)) { |
95 | skupResult.put("secondhand_image", product_default_images); | 89 | skupResult.put("secondhand_image", product_default_images); |
96 | } | 90 | } |
97 | - // 价格处理 | 91 | + // 3) 价格处理[现货最低价-skupPrice] |
98 | double skupPrice = MapUtils.getDoubleValue(skupResult, "skup_price", 0); | 92 | double skupPrice = MapUtils.getDoubleValue(skupResult, "skup_price", 0); |
99 | - double available_now_price = MapUtils.getDoubleValue(productInfo, "available_now_price", 0); | 93 | + double available_now_price = MapUtils.getDoubleValue(ufoProductInfo, "available_now_price", 0); |
100 | if (skupPrice > 0 && available_now_price > 0 && skupPrice < available_now_price) { | 94 | if (skupPrice > 0 && available_now_price > 0 && skupPrice < available_now_price) { |
101 | skupResult.put("save_price", available_now_price - skupPrice); | 95 | skupResult.put("save_price", available_now_price - skupPrice); |
102 | } else { | 96 | } else { |
@@ -104,7 +98,7 @@ public class UfoSecondhandSkupService { | @@ -104,7 +98,7 @@ public class UfoSecondhandSkupService { | ||
104 | } | 98 | } |
105 | }); | 99 | }); |
106 | 100 | ||
107 | - // 7、构造返回结果 | 101 | + // 8、构造返回结果 |
108 | JSONObject dataMap = new JSONObject(); | 102 | JSONObject dataMap = new JSONObject(); |
109 | dataMap.put("total", searchResult.getTotal()); | 103 | dataMap.put("total", searchResult.getTotal()); |
110 | dataMap.put("page", searchResult.getPage()); | 104 | dataMap.put("page", searchResult.getPage()); |
@@ -119,10 +113,11 @@ public class UfoSecondhandSkupService { | @@ -119,10 +113,11 @@ public class UfoSecondhandSkupService { | ||
119 | 113 | ||
120 | private BoolQueryBuilder builderFilter(Map<String, String> paramMap) { | 114 | private BoolQueryBuilder builderFilter(Map<String, String> paramMap) { |
121 | BoolQueryBuilder filter = QueryBuilders.boolQuery(); | 115 | BoolQueryBuilder filter = QueryBuilders.boolQuery(); |
122 | - filter.must(QueryBuilders.rangeQuery("id").lte(MapUtils.getIntValue(paramMap, "maxStoragePriceId", Integer.MAX_VALUE))); | 116 | + filter.must(QueryBuilders.rangeQuery("id").lte(MapUtils.getIntValue(paramMap, UfoSearchRequestParams.UFO_PARAM_MAXSTORAGEPRICE_ID, Integer.MAX_VALUE))); |
123 | filter.must(QueryBuilders.termQuery("isHide", 0)); | 117 | filter.must(QueryBuilders.termQuery("isHide", 0)); |
124 | filter.must(QueryBuilders.termQuery("status", 1)); | 118 | filter.must(QueryBuilders.termQuery("status", 1)); |
125 | - List<Integer> preSaleFlags = SearchConvertUtils.stringToIntList(MapUtils.getString(paramMap, "preSaleFlag"), ","); | 119 | + // 过滤preSaleFlag,默认5,6 |
120 | + List<Integer> preSaleFlags = SearchConvertUtils.stringToIntList(MapUtils.getString(paramMap, UfoSearchRequestParams.UFO_PARAM_PRE_SALE_FLAG), ","); | ||
126 | if (CollectionUtils.isNotEmpty(preSaleFlags)) { | 121 | if (CollectionUtils.isNotEmpty(preSaleFlags)) { |
127 | filter.must(QueryBuilders.termsQuery("preSaleFlag", preSaleFlags)); | 122 | filter.must(QueryBuilders.termsQuery("preSaleFlag", preSaleFlags)); |
128 | } else { | 123 | } else { |
@@ -6,7 +6,6 @@ import com.yoho.search.aop.cache.SearchCacheAble; | @@ -6,7 +6,6 @@ import com.yoho.search.aop.cache.SearchCacheAble; | ||
6 | import com.yoho.search.base.constants.ISearchConstants; | 6 | import com.yoho.search.base.constants.ISearchConstants; |
7 | import com.yoho.search.cache.CacheInMinute; | 7 | import com.yoho.search.cache.CacheInMinute; |
8 | import com.yoho.search.common.SearchCommonService; | 8 | import com.yoho.search.common.SearchCommonService; |
9 | -import com.yoho.search.common.SearchRequestParams; | ||
10 | import com.yoho.search.common.UfoSearchRequestParams; | 9 | import com.yoho.search.common.UfoSearchRequestParams; |
11 | import com.yoho.search.common.utils.SearchApiResultUtils; | 10 | import com.yoho.search.common.utils.SearchApiResultUtils; |
12 | import com.yoho.search.core.es.agg.IAggregation; | 11 | import com.yoho.search.core.es.agg.IAggregation; |
@@ -80,7 +79,7 @@ public class UfoSelectionListService { | @@ -80,7 +79,7 @@ public class UfoSelectionListService { | ||
80 | // 调用ES | 79 | // 调用ES |
81 | SearchResult searchResult = searchCommonService.doSearch(productIndexName, searchParam); | 80 | SearchResult searchResult = searchCommonService.doSearch(productIndexName, searchParam); |
82 | // 正常查询结果为空,调用模糊纠错货号的逻辑去查 | 81 | // 正常查询结果为空,调用模糊纠错货号的逻辑去查 |
83 | - if (searchResult.getTotal() == 0 && paramMap.containsKey(UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY)) { | 82 | + if (searchResult.getTotal() == 0 && paramMap.containsKey(UfoSearchRequestParams.UFO_PARAM_SEARCH_QUERY)) { |
84 | searchParam = ufoFuzzySceneService.buildSearchParamForProductCodeSearch(paramMap, 0, 0); | 83 | searchParam = ufoFuzzySceneService.buildSearchParamForProductCodeSearch(paramMap, 0, 0); |
85 | searchParam.setAggregationBuilders(this.getAllAggregationBuilders(paramMap)); | 84 | searchParam.setAggregationBuilders(this.getAllAggregationBuilders(paramMap)); |
86 | searchParam.setSize(0); | 85 | searchParam.setSize(0); |
@@ -5,7 +5,6 @@ import com.yoho.search.aop.cache.SearchCacheAble; | @@ -5,7 +5,6 @@ import com.yoho.search.aop.cache.SearchCacheAble; | ||
5 | import com.yoho.search.base.constants.ISearchConstants; | 5 | import com.yoho.search.base.constants.ISearchConstants; |
6 | import com.yoho.search.base.constants.ProductIndexEsField; | 6 | import com.yoho.search.base.constants.ProductIndexEsField; |
7 | import com.yoho.search.common.SearchCommonService; | 7 | import com.yoho.search.common.SearchCommonService; |
8 | -import com.yoho.search.common.SearchRequestParams; | ||
9 | import com.yoho.search.common.UfoSearchRequestParams; | 8 | import com.yoho.search.common.UfoSearchRequestParams; |
10 | import com.yoho.search.common.utils.SearchKeyWordUtils; | 9 | import com.yoho.search.common.utils.SearchKeyWordUtils; |
11 | import com.yoho.search.core.es.model.SearchParam; | 10 | import com.yoho.search.core.es.model.SearchParam; |
@@ -53,7 +52,7 @@ public class UfoSuggestService { | @@ -53,7 +52,7 @@ public class UfoSuggestService { | ||
53 | logger.info("[func=suggest][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis()); | 52 | logger.info("[func=suggest][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis()); |
54 | 53 | ||
55 | // 1)关键参数验证 | 54 | // 1)关键参数验证 |
56 | - String keyword = SearchKeyWordUtils.getUfoParamKeyword(paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY); | 55 | + String keyword = SearchKeyWordUtils.getUfoParamKeyword(paramMap, UfoSearchRequestParams.UFO_PARAM_SEARCH_QUERY); |
57 | if (StringUtils.isBlank(keyword)) { | 56 | if (StringUtils.isBlank(keyword)) { |
58 | return new SearchApiResult().setCode(400).setMessage("关键字[query]参数为空!"); | 57 | return new SearchApiResult().setCode(400).setMessage("关键字[query]参数为空!"); |
59 | } | 58 | } |
@@ -61,7 +60,7 @@ public class UfoSuggestService { | @@ -61,7 +60,7 @@ public class UfoSuggestService { | ||
61 | if (keyword.length() > 30) { | 60 | if (keyword.length() > 30) { |
62 | return new SearchApiResult().setCode(400).setMessage("关键字[query]参数非法!"); | 61 | return new SearchApiResult().setCode(400).setMessage("关键字[query]参数非法!"); |
63 | } | 62 | } |
64 | - paramMap.put(UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY, keyword); | 63 | + paramMap.put(UfoSearchRequestParams.UFO_PARAM_SEARCH_QUERY, keyword); |
65 | 64 | ||
66 | // 2)构建查询参数 | 65 | // 2)构建查询参数 |
67 | SearchParam searchParam = this.buildSuggestSearchParam(paramMap); | 66 | SearchParam searchParam = this.buildSuggestSearchParam(paramMap); |
@@ -101,7 +100,7 @@ public class UfoSuggestService { | @@ -101,7 +100,7 @@ public class UfoSuggestService { | ||
101 | * 通过纠错的方式,查询建议词列表 | 100 | * 通过纠错的方式,查询建议词列表 |
102 | */ | 101 | */ |
103 | private SearchResult suggestByCorrectSpelling(Map<String, String> paramMap) { | 102 | private SearchResult suggestByCorrectSpelling(Map<String, String> paramMap) { |
104 | - String keyword = paramMap.get(UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY).toLowerCase(); | 103 | + String keyword = paramMap.get(UfoSearchRequestParams.UFO_PARAM_SEARCH_QUERY).toLowerCase(); |
105 | String newKeyword = (String) this.correctSpellingKeyword(paramMap).getData(); | 104 | String newKeyword = (String) this.correctSpellingKeyword(paramMap).getData(); |
106 | if (StringUtils.isEmpty(newKeyword)) { | 105 | if (StringUtils.isEmpty(newKeyword)) { |
107 | return null; | 106 | return null; |
@@ -110,7 +109,7 @@ public class UfoSuggestService { | @@ -110,7 +109,7 @@ public class UfoSuggestService { | ||
110 | logger.info("Switch the suggest keyword from [{}] to [{}].", keyword, newKeyword); | 109 | logger.info("Switch the suggest keyword from [{}] to [{}].", keyword, newKeyword); |
111 | Map<String, String> newParamMap = new HashMap<>(paramMap.size()); | 110 | Map<String, String> newParamMap = new HashMap<>(paramMap.size()); |
112 | newParamMap.putAll(paramMap); | 111 | newParamMap.putAll(paramMap); |
113 | - newParamMap.put(UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY, newKeyword); | 112 | + newParamMap.put(UfoSearchRequestParams.UFO_PARAM_SEARCH_QUERY, newKeyword); |
114 | SearchParam newSearchParam = this.buildSuggestSearchParam(newParamMap); | 113 | SearchParam newSearchParam = this.buildSuggestSearchParam(newParamMap); |
115 | return searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_SUGGEST, newSearchParam); | 114 | return searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_SUGGEST, newSearchParam); |
116 | } catch (Exception e) { | 115 | } catch (Exception e) { |
@@ -123,7 +122,7 @@ public class UfoSuggestService { | @@ -123,7 +122,7 @@ public class UfoSuggestService { | ||
123 | * 构建查询参数 | 122 | * 构建查询参数 |
124 | */ | 123 | */ |
125 | private SearchParam buildSuggestSearchParam(Map<String, String> paramMap) { | 124 | private SearchParam buildSuggestSearchParam(Map<String, String> paramMap) { |
126 | - String keyword = paramMap.get(UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY).toLowerCase(); | 125 | + String keyword = paramMap.get(UfoSearchRequestParams.UFO_PARAM_SEARCH_QUERY).toLowerCase(); |
127 | SearchParam searchParam = new SearchParam(); | 126 | SearchParam searchParam = new SearchParam(); |
128 | QueryBuilder query = QueryBuilders.boolQuery().should(QueryBuilders.prefixQuery("keyword", keyword)).should(QueryBuilders.prefixQuery("keyword.keyword_pinyin", keyword)) | 127 | QueryBuilder query = QueryBuilders.boolQuery().should(QueryBuilders.prefixQuery("keyword", keyword)).should(QueryBuilders.prefixQuery("keyword.keyword_pinyin", keyword)) |
129 | .should(QueryBuilders.prefixQuery("keyword.keyword_jianpin", keyword)); | 128 | .should(QueryBuilders.prefixQuery("keyword.keyword_jianpin", keyword)); |
-
Please register or login to post a comment