修改sort_size_products的接口
Showing
3 changed files
with
29 additions
and
24 deletions
@@ -41,7 +41,7 @@ public class SearchController { | @@ -41,7 +41,7 @@ public class SearchController { | ||
41 | public Map<String, Object> searchNew(HttpServletRequest request) { | 41 | public Map<String, Object> searchNew(HttpServletRequest request) { |
42 | Map<String, Object> paramMap = request.getParameterMap(); | 42 | Map<String, Object> paramMap = request.getParameterMap(); |
43 | try { | 43 | try { |
44 | - Map<String, Object> jsonMap = searchService.searchNew(transParamType(paramMap)); | 44 | + Map<String, Object> jsonMap = searchService.searchNew(transParamType(paramMap),null); |
45 | return jsonMap; | 45 | return jsonMap; |
46 | } catch (Exception e) { | 46 | } catch (Exception e) { |
47 | return errorReturn("searchNew", paramMap, e.getMessage()); | 47 | return errorReturn("searchNew", paramMap, e.getMessage()); |
@@ -2,6 +2,7 @@ package com.yoho.search.service; | @@ -2,6 +2,7 @@ package com.yoho.search.service; | ||
2 | 2 | ||
3 | import java.util.ArrayList; | 3 | import java.util.ArrayList; |
4 | import java.util.Arrays; | 4 | import java.util.Arrays; |
5 | +import java.util.Collection; | ||
5 | import java.util.Collections; | 6 | import java.util.Collections; |
6 | import java.util.Comparator; | 7 | import java.util.Comparator; |
7 | import java.util.HashMap; | 8 | import java.util.HashMap; |
@@ -680,9 +681,17 @@ public class SearchService { | @@ -680,9 +681,17 @@ public class SearchService { | ||
680 | * @return | 681 | * @return |
681 | * @throws Exception | 682 | * @throws Exception |
682 | */ | 683 | */ |
683 | - public Map<String, Object> searchNew(Map<String, String> paramMap) throws Exception { | 684 | + public Map<String, Object> searchNew(Map<String, String> paramMap,Collection<String> producSkns) throws Exception { |
684 | long begin = System.currentTimeMillis(); | 685 | long begin = System.currentTimeMillis(); |
685 | - logger.info("[model=SearchService][func=searchWithWeight][param={}][begin={}]", paramMap.toString(), begin); | 686 | + logger.info("[model=SearchService][func=searchNew][param={}][begin={}][producSkns.size={}]", paramMap.toString(), begin, producSkns == null ? "null" : producSkns.size()); |
687 | + if (producSkns != null) { | ||
688 | + StringBuilder sb = new StringBuilder(); | ||
689 | + for (String productSkn : producSkns) { | ||
690 | + sb.append(productSkn).append(","); | ||
691 | + } | ||
692 | + String productIds = sb.toString(); | ||
693 | + paramMap.put(ISearchConstans.PARAM_SYNC_SKN, productIds); | ||
694 | + } | ||
686 | // 首先解析参数转化为检索条件--SearchParam | 695 | // 首先解析参数转化为检索条件--SearchParam |
687 | SearchParam searchParam = new SearchParam(); | 696 | SearchParam searchParam = new SearchParam(); |
688 | // 构造query | 697 | // 构造query |
@@ -709,7 +718,7 @@ public class SearchService { | @@ -709,7 +718,7 @@ public class SearchService { | ||
709 | String resultFields = paramMap.get("resultFields"); | 718 | String resultFields = paramMap.get("resultFields"); |
710 | searchParam.setResultFields(Arrays.asList(resultFields.split(","))); | 719 | searchParam.setResultFields(Arrays.asList(resultFields.split(","))); |
711 | } | 720 | } |
712 | - | 721 | + |
713 | // 设置排序字段 | 722 | // 设置排序字段 |
714 | searchParam.setSortFields(buildSort(paramMap)); | 723 | searchParam.setSortFields(buildSort(paramMap)); |
715 | // 进行检索 | 724 | // 进行检索 |
@@ -717,25 +726,23 @@ public class SearchService { | @@ -717,25 +726,23 @@ public class SearchService { | ||
717 | SearchResult searchResult = doSearch(indexName, searchParam); | 726 | SearchResult searchResult = doSearch(indexName, searchParam); |
718 | 727 | ||
719 | // 将searchResult转化为map返回--需要把aggregation转化为需要的结构 | 728 | // 将searchResult转化为map返回--需要把aggregation转化为需要的结构 |
720 | - if (searchResult == null) | 729 | + if (searchResult == null){ |
721 | return null; | 730 | return null; |
722 | - | 731 | + } |
732 | + | ||
723 | Map<String, Object> dataMap = new HashMap<String, Object>(); | 733 | Map<String, Object> dataMap = new HashMap<String, Object>(); |
724 | dataMap.put("total", searchResult.getTotal()); | 734 | dataMap.put("total", searchResult.getTotal()); |
725 | dataMap.put("page", searchResult.getPage()); | 735 | dataMap.put("page", searchResult.getPage()); |
726 | dataMap.put("page_total", searchResult.getTotalPage()); | 736 | dataMap.put("page_total", searchResult.getTotalPage()); |
727 | dataMap.put("product_list", makePageList(searchResult.getResultList())); | 737 | dataMap.put("product_list", makePageList(searchResult.getResultList())); |
728 | - | ||
729 | if (searchResult.getAggMaps() != null) { | 738 | if (searchResult.getAggMaps() != null) { |
730 | Map<String, Aggregation> aggMaps = searchResult.getAggMaps(); | 739 | Map<String, Aggregation> aggMaps = searchResult.getAggMaps(); |
731 | dataMap.put("filter", buildFilterResult(aggMaps, preAggregationResult, paramMap)); | 740 | dataMap.put("filter", buildFilterResult(aggMaps, preAggregationResult, paramMap)); |
732 | } | 741 | } |
733 | - | ||
734 | Map<String, Object> jsonMap = new HashMap<String, Object>(); | 742 | Map<String, Object> jsonMap = new HashMap<String, Object>(); |
735 | jsonMap.put("message", "Search List."); | 743 | jsonMap.put("message", "Search List."); |
736 | jsonMap.put("code", 200); | 744 | jsonMap.put("code", 200); |
737 | jsonMap.put("data", dataMap); | 745 | jsonMap.put("data", dataMap); |
738 | - logger.info("[model=SearchService][func=searchWithWeight][param={}][cost={}ms]", paramMap.toString(), System.currentTimeMillis() - begin); | ||
739 | return jsonMap; | 746 | return jsonMap; |
740 | } | 747 | } |
741 | 748 | ||
@@ -1925,6 +1932,11 @@ public class SearchService { | @@ -1925,6 +1932,11 @@ public class SearchService { | ||
1925 | .should(FilterBuilders.rangeFilter("basePinRatio").from(3.5))); | 1932 | .should(FilterBuilders.rangeFilter("basePinRatio").from(3.5))); |
1926 | } | 1933 | } |
1927 | } | 1934 | } |
1935 | + | ||
1936 | + if (paramMap.containsKey(ISearchConstans.PARAM_SYNC_SKN) && StringUtils.isNotBlank(paramMap.get(ISearchConstans.PARAM_SYNC_SKN))) { | ||
1937 | + String sknString = paramMap.get(ISearchConstans.PARAM_SYNC_SKN); | ||
1938 | + boolFilter.must(FilterBuilders.termsFilter("productSkn", sknString.split(","))); | ||
1939 | + } | ||
1928 | 1940 | ||
1929 | // 增加过滤的请求 | 1941 | // 增加过滤的请求 |
1930 | for (String key : paramMap.keySet()) { | 1942 | for (String key : paramMap.keySet()) { |
@@ -185,10 +185,8 @@ public class SearchSortSizeService { | @@ -185,10 +185,8 @@ public class SearchSortSizeService { | ||
185 | if (!aggMaps.containsKey("productSknAgg")) { | 185 | if (!aggMaps.containsKey("productSknAgg")) { |
186 | return new HashMap<String, Object>(); | 186 | return new HashMap<String, Object>(); |
187 | } | 187 | } |
188 | - | ||
189 | // 构建聚合结果 | 188 | // 构建聚合结果 |
190 | Set<String> productSkns = new HashSet<String>(); | 189 | Set<String> productSkns = new HashSet<String>(); |
191 | - | ||
192 | MultiBucketsAggregation aggreation = (MultiBucketsAggregation) aggMaps.get("productSknAgg"); | 190 | MultiBucketsAggregation aggreation = (MultiBucketsAggregation) aggMaps.get("productSknAgg"); |
193 | Iterator<? extends Bucket> iterator = aggreation.getBuckets().iterator(); | 191 | Iterator<? extends Bucket> iterator = aggreation.getBuckets().iterator(); |
194 | while (iterator.hasNext()) { | 192 | while (iterator.hasNext()) { |
@@ -196,13 +194,7 @@ public class SearchSortSizeService { | @@ -196,13 +194,7 @@ public class SearchSortSizeService { | ||
196 | productSkns.add(String.valueOf(sortBucket.getKey())); | 194 | productSkns.add(String.valueOf(sortBucket.getKey())); |
197 | } | 195 | } |
198 | logger.info("get productSkn from storagesku index productSkn size is{}", productSkns.size()); | 196 | logger.info("get productSkn from storagesku index productSkn size is{}", productSkns.size()); |
199 | - StringBuilder sb = new StringBuilder(); | ||
200 | - for (String productSkn : productSkns) { | ||
201 | - sb.append(productSkn).append(","); | ||
202 | - } | ||
203 | - String productIds = sb.toString(); | ||
204 | - paramMap.put(ISearchConstans.PARAM_SYNC_SKN, productIds); | ||
205 | - return searchService.searchNew(paramMap); | 197 | + return searchService.searchNew(paramMap, productSkns); |
206 | } | 198 | } |
207 | 199 | ||
208 | /** | 200 | /** |
@@ -255,14 +247,14 @@ public class SearchSortSizeService { | @@ -255,14 +247,14 @@ public class SearchSortSizeService { | ||
255 | 247 | ||
256 | boolFilter.must(FilterBuilders.termFilter("status", 1)); | 248 | boolFilter.must(FilterBuilders.termFilter("status", 1)); |
257 | 249 | ||
258 | - if (StringUtils.isNotBlank(sizeSortReqBO.getIsdiscount())) { | ||
259 | - boolFilter.must(FilterBuilders.termFilter("isDiscount", sizeSortReqBO.getIsdiscount())); | ||
260 | - } | ||
261 | - | ||
262 | if (StringUtils.isNotBlank(sizeSortReqBO.getProductStatus())) { | 250 | if (StringUtils.isNotBlank(sizeSortReqBO.getProductStatus())) { |
263 | boolFilter.must(FilterBuilders.termFilter("productStatus", sizeSortReqBO.getProductStatus())); | 251 | boolFilter.must(FilterBuilders.termFilter("productStatus", sizeSortReqBO.getProductStatus())); |
264 | } | 252 | } |
265 | 253 | ||
254 | + if (StringUtils.isNotBlank(sizeSortReqBO.getIsdiscount())) { | ||
255 | + boolFilter.must(FilterBuilders.termFilter("isDiscount", sizeSortReqBO.getIsdiscount())); | ||
256 | + } | ||
257 | + | ||
266 | if (StringUtils.isNotBlank(sizeSortReqBO.getAttribute_not())) { | 258 | if (StringUtils.isNotBlank(sizeSortReqBO.getAttribute_not())) { |
267 | boolFilter.mustNot(FilterBuilders.termFilter("attribute", sizeSortReqBO.getAttribute_not())); | 259 | boolFilter.mustNot(FilterBuilders.termFilter("attribute", sizeSortReqBO.getAttribute_not())); |
268 | } | 260 | } |
@@ -298,7 +290,9 @@ public class SearchSortSizeService { | @@ -298,7 +290,9 @@ public class SearchSortSizeService { | ||
298 | boolFilter.must(FilterBuilders.termsFilter("gender", genderIds)); | 290 | boolFilter.must(FilterBuilders.termsFilter("gender", genderIds)); |
299 | } | 291 | } |
300 | } | 292 | } |
301 | - | 293 | + |
294 | + logger.debug("boolFilter:" + boolFilter.toString()); | ||
295 | + | ||
302 | return boolFilter; | 296 | return boolFilter; |
303 | } | 297 | } |
304 | 298 | ||
@@ -339,5 +333,4 @@ public class SearchSortSizeService { | @@ -339,5 +333,4 @@ public class SearchSortSizeService { | ||
339 | } | 333 | } |
340 | return sizeResult; | 334 | return sizeResult; |
341 | } | 335 | } |
342 | - | ||
343 | } | 336 | } |
-
Please register or login to post a comment