商品池模糊搜索需要返回product_pool_orderby
Showing
7 changed files
with
40 additions
and
15 deletions
@@ -3,7 +3,10 @@ package com.yoho.search.service.index.ufo; | @@ -3,7 +3,10 @@ package com.yoho.search.service.index.ufo; | ||
3 | import com.yoho.search.base.constants.ISearchConstants; | 3 | import com.yoho.search.base.constants.ISearchConstants; |
4 | import com.yoho.search.base.constants.UfoProductIndexEsField; | 4 | import com.yoho.search.base.constants.UfoProductIndexEsField; |
5 | import com.yoho.search.common.SearchCommonService; | 5 | import com.yoho.search.common.SearchCommonService; |
6 | +import com.yoho.search.common.UfoSearchRequestParams; | ||
7 | +import org.apache.commons.collections.CollectionUtils; | ||
6 | import org.apache.commons.collections.MapUtils; | 8 | import org.apache.commons.collections.MapUtils; |
9 | +import org.apache.commons.lang3.StringUtils; | ||
7 | import org.slf4j.Logger; | 10 | import org.slf4j.Logger; |
8 | import org.slf4j.LoggerFactory; | 11 | import org.slf4j.LoggerFactory; |
9 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -52,15 +55,15 @@ public class UfoProductIndexBaseService { | @@ -52,15 +55,15 @@ public class UfoProductIndexBaseService { | ||
52 | return results; | 55 | return results; |
53 | } | 56 | } |
54 | 57 | ||
55 | - public List<Map<String, Object>> buildProductReturnInfoList(List<Map<String, Object>> productEsSourceList) { | 58 | + public List<Map<String, Object>> buildProductReturnInfoList(List<Map<String, Object>> productEsSourceList, Map<String, String> paramMap) { |
56 | List<Map<String, Object>> results = new ArrayList<>(productEsSourceList.size()); | 59 | List<Map<String, Object>> results = new ArrayList<>(productEsSourceList.size()); |
57 | for (Map<String, Object> productEsSource : productEsSourceList) { | 60 | for (Map<String, Object> productEsSource : productEsSourceList) { |
58 | - results.add(this.getProductMapFromEsSource(productEsSource)); | 61 | + results.add(this.getProductMapFromEsSource(productEsSource, paramMap)); |
59 | } | 62 | } |
60 | return results; | 63 | return results; |
61 | } | 64 | } |
62 | 65 | ||
63 | - private Map<String, Object> getProductMapFromEsSource(Map<String, Object> map) { | 66 | + private Map<String, Object> getProductMapFromEsSource(Map<String, Object> map, Map<String, String> paramMap) { |
64 | Map<String, Object> productMap = new HashMap<>(); | 67 | Map<String, Object> productMap = new HashMap<>(); |
65 | productMap.put("id", MapUtils.getIntValue(map, UfoProductIndexEsField.id, 0)); | 68 | productMap.put("id", MapUtils.getIntValue(map, UfoProductIndexEsField.id, 0)); |
66 | productMap.put("product_name", MapUtils.getString(map, UfoProductIndexEsField.productName, "")); | 69 | productMap.put("product_name", MapUtils.getString(map, UfoProductIndexEsField.productName, "")); |
@@ -78,16 +81,17 @@ public class UfoProductIndexBaseService { | @@ -78,16 +81,17 @@ public class UfoProductIndexBaseService { | ||
78 | productMap.put("available_now_price", availableNowPrice == null || availableNowPrice == -1d ? null : availableNowPrice); | 81 | productMap.put("available_now_price", availableNowPrice == null || availableNowPrice == -1d ? null : availableNowPrice); |
79 | 82 | ||
80 | productMap.put("is_yoho", MapUtils.getString(map, UfoProductIndexEsField.isYoho, "N")); | 83 | productMap.put("is_yoho", MapUtils.getString(map, UfoProductIndexEsField.isYoho, "N")); |
84 | + productMap.put("pool_order_by", getPoolOrderBy(map, paramMap)); | ||
81 | productMap.put("pool_ids", MapUtils.getString(map, UfoProductIndexEsField.poolIds, "")); | 85 | productMap.put("pool_ids", MapUtils.getString(map, UfoProductIndexEsField.poolIds, "")); |
82 | return productMap; | 86 | return productMap; |
83 | } | 87 | } |
84 | 88 | ||
85 | - public Map<Integer,Map<String,Object>> queryUfoProductMapByProductIds(final Collection<?> ufoProductIds) { | ||
86 | - List<Map<String, Object>> resultList = this.queryListByProductIds(ufoProductIds); | 89 | + public Map<Integer,Map<String,Object>> queryUfoProductMapByProductIds(final Collection<?> ufoProductIds, Map<String, String> paramMap) { |
90 | + List<Map<String, Object>> resultList = this.queryListByProductIds(ufoProductIds, paramMap); | ||
87 | return resultList.stream().collect(Collectors.toMap(a->MapUtils.getIntValue(a,"id",0),p->p)); | 91 | return resultList.stream().collect(Collectors.toMap(a->MapUtils.getIntValue(a,"id",0),p->p)); |
88 | } | 92 | } |
89 | 93 | ||
90 | - public List<Map<String, Object>> queryListByProductIds(final Collection<?> ufoProductIds) { | 94 | + public List<Map<String, Object>> queryListByProductIds(final Collection<?> ufoProductIds, Map<String, String> paramMap) { |
91 | List<Map<String, Object>> resultList = new ArrayList<>(); | 95 | List<Map<String, Object>> resultList = new ArrayList<>(); |
92 | try { | 96 | try { |
93 | if (ufoProductIds == null || ufoProductIds.isEmpty()) { | 97 | if (ufoProductIds == null || ufoProductIds.isEmpty()) { |
@@ -95,7 +99,7 @@ public class UfoProductIndexBaseService { | @@ -95,7 +99,7 @@ public class UfoProductIndexBaseService { | ||
95 | } | 99 | } |
96 | List<Map<String, Object>> queryResults = searchCommonService.doMultiGetCommon(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, ufoProductIds); | 100 | List<Map<String, Object>> queryResults = searchCommonService.doMultiGetCommon(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, ufoProductIds); |
97 | for (Map<String, Object> results : queryResults) { | 101 | for (Map<String, Object> results : queryResults) { |
98 | - resultList.add(this.getProductMapFromEsSource(results)); | 102 | + resultList.add(this.getProductMapFromEsSource(results, paramMap)); |
99 | } | 103 | } |
100 | } catch (Exception e) { | 104 | } catch (Exception e) { |
101 | logger.error(e.getMessage(), e); | 105 | logger.error(e.getMessage(), e); |
@@ -103,5 +107,26 @@ public class UfoProductIndexBaseService { | @@ -103,5 +107,26 @@ public class UfoProductIndexBaseService { | ||
103 | return resultList; | 107 | return resultList; |
104 | } | 108 | } |
105 | 109 | ||
106 | - | 110 | + private int getPoolOrderBy(Map<String, Object> map, Map<String, String> paramMap) { |
111 | + try { | ||
112 | + String inputPoolId = MapUtils.getString(paramMap, UfoSearchRequestParams.UFO_PARAM_POOL, ""); | ||
113 | + if (StringUtils.isBlank(inputPoolId)) { | ||
114 | + return 0; | ||
115 | + } | ||
116 | + List<Map<String, Object>> poolList = (List<Map<String, Object>>) map.get(UfoProductIndexEsField.pools); | ||
117 | + if (CollectionUtils.isEmpty(poolList)) { | ||
118 | + return 0; | ||
119 | + } | ||
120 | + for (Map<String, Object> poolMap : poolList) { | ||
121 | + Integer poolId = MapUtils.getIntValue(poolMap, "poolId", 0); | ||
122 | + if (Integer.valueOf(inputPoolId).equals(poolId)) { | ||
123 | + return MapUtils.getIntValue(poolMap, "orderBy", 0); | ||
124 | + } | ||
125 | + } | ||
126 | + return 0; | ||
127 | + } catch (Exception e) { | ||
128 | + logger.error(e.getMessage(), e); | ||
129 | + return 0; | ||
130 | + } | ||
131 | + } | ||
107 | } | 132 | } |
@@ -71,7 +71,7 @@ public class UfoFavoriteService { | @@ -71,7 +71,7 @@ public class UfoFavoriteService { | ||
71 | // 5、执行搜索 | 71 | // 5、执行搜索 |
72 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam); | 72 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam); |
73 | // 6、构造返回结果 | 73 | // 6、构造返回结果 |
74 | - List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList()); | 74 | + List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList(), paramMap); |
75 | // 7、添加自定义标签 | 75 | // 7、添加自定义标签 |
76 | customizeTagBaseService.fillCustomizeTag(returnInfoList, false); | 76 | customizeTagBaseService.fillCustomizeTag(returnInfoList, false); |
77 | // 8、按id顺序排序 | 77 | // 8、按id顺序排序 |
@@ -77,7 +77,7 @@ public class UfoFuzzySceneService { | @@ -77,7 +77,7 @@ public class UfoFuzzySceneService { | ||
77 | // 执行搜索 | 77 | // 执行搜索 |
78 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam); | 78 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam); |
79 | // 构造返回结果 | 79 | // 构造返回结果 |
80 | - List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList()); | 80 | + List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList(), paramMap); |
81 | // 返回结果为空时,针对货号进行模糊纠错匹配 | 81 | // 返回结果为空时,针对货号进行模糊纠错匹配 |
82 | if (CollectionUtils.isEmpty(returnInfoList)) { | 82 | if (CollectionUtils.isEmpty(returnInfoList)) { |
83 | return fuzzySearchForProductCode(paramMap); | 83 | return fuzzySearchForProductCode(paramMap); |
@@ -111,7 +111,7 @@ public class UfoFuzzySceneService { | @@ -111,7 +111,7 @@ public class UfoFuzzySceneService { | ||
111 | // 执行搜索 | 111 | // 执行搜索 |
112 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam); | 112 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam); |
113 | // 构造返回结果 | 113 | // 构造返回结果 |
114 | - List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList()); | 114 | + List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList(), paramMap); |
115 | // 添加变价计划 | 115 | // 添加变价计划 |
116 | productPricePlanIndexBaseService.fillProductPricePlanForUfo(returnInfoList); | 116 | productPricePlanIndexBaseService.fillProductPricePlanForUfo(returnInfoList); |
117 | JSONObject dataMap = new JSONObject(); | 117 | JSONObject dataMap = new JSONObject(); |
@@ -69,7 +69,7 @@ public class UfoHotSaleListService { | @@ -69,7 +69,7 @@ public class UfoHotSaleListService { | ||
69 | // 3、执行搜索 | 69 | // 3、执行搜索 |
70 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam); | 70 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam); |
71 | // 4、处理返回结果 | 71 | // 4、处理返回结果 |
72 | - List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList()); | 72 | + List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList(), paramMap); |
73 | // 5、添加排行序列号 | 73 | // 5、添加排行序列号 |
74 | this.addNumberTag(returnInfoList, page, pageSize); | 74 | this.addNumberTag(returnInfoList, page, pageSize); |
75 | // 6、构造返回结果【限制返回总数100个】 | 75 | // 6、构造返回结果【限制返回总数100个】 |
@@ -67,7 +67,7 @@ public class UfoProductListService { | @@ -67,7 +67,7 @@ public class UfoProductListService { | ||
67 | // 执行搜索 | 67 | // 执行搜索 |
68 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam); | 68 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam); |
69 | // 构造返回结果 | 69 | // 构造返回结果 |
70 | - List<Map<String, Object>> productList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList()); | 70 | + List<Map<String, Object>> productList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList(), paramMap); |
71 | // 添加变价计划 | 71 | // 添加变价计划 |
72 | productPricePlanIndexBaseService.fillProductPricePlanForUfo(productList); | 72 | productPricePlanIndexBaseService.fillProductPricePlanForUfo(productList); |
73 | // 添加自定义标签 | 73 | // 添加自定义标签 |
@@ -159,7 +159,7 @@ public class UfoSecondhandSkupService { | @@ -159,7 +159,7 @@ public class UfoSecondhandSkupService { | ||
159 | Map<Integer, Double> storageAvailableNowPriceMap = this.queryAvailableNowPriceByStorageIds(ufoStorageIds); | 159 | Map<Integer, Double> storageAvailableNowPriceMap = this.queryAvailableNowPriceByStorageIds(ufoStorageIds); |
160 | 160 | ||
161 | // 6、根据productIds查询商品信息 | 161 | // 6、根据productIds查询商品信息 |
162 | - Map<Integer, Map<String, Object>> ufoProductMap = ufoProductIndexBaseService.queryUfoProductMapByProductIds(ufoProductIds); | 162 | + Map<Integer, Map<String, Object>> ufoProductMap = ufoProductIndexBaseService.queryUfoProductMapByProductIds(ufoProductIds, paramMap); |
163 | 163 | ||
164 | // 9、处理结果 | 164 | // 9、处理结果 |
165 | for (Map<String, Object> skupResult : skupResultList) { | 165 | for (Map<String, Object> skupResult : skupResultList) { |
@@ -66,7 +66,7 @@ public class UfoSoonSaleService { | @@ -66,7 +66,7 @@ public class UfoSoonSaleService { | ||
66 | // 执行搜索 | 66 | // 执行搜索 |
67 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam); | 67 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam); |
68 | // 处理返回结果 | 68 | // 处理返回结果 |
69 | - List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList()); | 69 | + List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList(), paramMap); |
70 | // 构造返回结果 | 70 | // 构造返回结果 |
71 | JSONObject result = new JSONObject(); | 71 | JSONObject result = new JSONObject(); |
72 | result.put("total", searchResult.getTotal()); | 72 | result.put("total", searchResult.getTotal()); |
-
Please register or login to post a comment