Showing
6 changed files
with
84 additions
and
73 deletions
1 | package com.yoho.search.service.aggregations.impls; | 1 | package com.yoho.search.service.aggregations.impls; |
2 | 2 | ||
3 | -import com.yoho.search.base.utils.ISearchConstants; | ||
4 | -import com.yoho.search.core.es.agg.AbstractAggregation; | ||
5 | -import com.yoho.search.service.service.SearchCommonService; | 3 | +import java.util.ArrayList; |
4 | +import java.util.Iterator; | ||
5 | +import java.util.List; | ||
6 | +import java.util.Map; | ||
7 | + | ||
6 | import org.apache.commons.lang.StringUtils; | 8 | import org.apache.commons.lang.StringUtils; |
7 | import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; | 9 | import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; |
8 | import org.elasticsearch.search.aggregations.Aggregation; | 10 | import org.elasticsearch.search.aggregations.Aggregation; |
9 | import org.elasticsearch.search.aggregations.AggregationBuilders; | 11 | import org.elasticsearch.search.aggregations.AggregationBuilders; |
10 | import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; | 12 | import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; |
11 | import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket; | 13 | import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket; |
14 | +import org.slf4j.Logger; | ||
15 | +import org.slf4j.LoggerFactory; | ||
12 | 16 | ||
13 | -import java.util.Iterator; | ||
14 | -import java.util.LinkedHashSet; | ||
15 | -import java.util.Map; | ||
16 | -import java.util.Set; | 17 | +import com.yoho.search.core.es.agg.AbstractAggregation; |
18 | +import com.yoho.search.service.service.base.BrandIndexBaseService; | ||
17 | 19 | ||
18 | public class BrandAggregation extends AbstractAggregation { | 20 | public class BrandAggregation extends AbstractAggregation { |
19 | 21 | ||
20 | - private SearchCommonService searchCommonService; | 22 | + private static final Logger logger = LoggerFactory.getLogger(BrandAggregation.class); |
23 | + | ||
24 | + private BrandIndexBaseService brandIndexBaseService; | ||
21 | private Map<String, String> paramMap; | 25 | private Map<String, String> paramMap; |
22 | private int brandCount; | 26 | private int brandCount; |
23 | 27 | ||
24 | - BrandAggregation(SearchCommonService searchCommonService, Map<String, String> paramMap) { | ||
25 | - this.searchCommonService = searchCommonService; | 28 | + BrandAggregation(BrandIndexBaseService brandIndexBaseService, Map<String, String> paramMap) { |
29 | + this.brandIndexBaseService = brandIndexBaseService; | ||
26 | this.paramMap = paramMap; | 30 | this.paramMap = paramMap; |
27 | this.brandCount=500; | 31 | this.brandCount=500; |
28 | } | 32 | } |
29 | 33 | ||
30 | - BrandAggregation(SearchCommonService searchCommonService, Map<String, String> paramMap,int brandCount){ | ||
31 | - this.searchCommonService = searchCommonService; | 34 | + BrandAggregation(BrandIndexBaseService brandIndexBaseService, Map<String, String> paramMap,int brandCount){ |
35 | + this.brandIndexBaseService = brandIndexBaseService; | ||
32 | this.paramMap = paramMap; | 36 | this.paramMap = paramMap; |
33 | this.brandCount = brandCount; | 37 | this.brandCount = brandCount; |
34 | } | 38 | } |
@@ -49,24 +53,24 @@ public class BrandAggregation extends AbstractAggregation { | @@ -49,24 +53,24 @@ public class BrandAggregation extends AbstractAggregation { | ||
49 | if (aggregation == null) { | 53 | if (aggregation == null) { |
50 | return null; | 54 | return null; |
51 | } | 55 | } |
52 | - Set<String> brandIdSet = new LinkedHashSet<String>(); | 56 | + List<String> brandIds = new ArrayList<String>(); |
53 | Iterator<? extends Bucket> itSizeAgg = aggregation.getBuckets().iterator(); | 57 | Iterator<? extends Bucket> itSizeAgg = aggregation.getBuckets().iterator(); |
54 | while (itSizeAgg.hasNext()) { | 58 | while (itSizeAgg.hasNext()) { |
55 | Bucket ltSize = itSizeAgg.next(); | 59 | Bucket ltSize = itSizeAgg.next(); |
56 | for (String brandId : ltSize.getKeyAsString().split(",")) { | 60 | for (String brandId : ltSize.getKeyAsString().split(",")) { |
57 | - brandIdSet.add(brandId); | 61 | + brandIds.add(brandId); |
58 | } | 62 | } |
59 | } | 63 | } |
60 | if (paramMap.containsKey("brand") && StringUtils.isNotBlank(paramMap.get("brand"))) { | 64 | if (paramMap.containsKey("brand") && StringUtils.isNotBlank(paramMap.get("brand"))) { |
61 | String[] ids = paramMap.get("brand").split(","); | 65 | String[] ids = paramMap.get("brand").split(","); |
62 | for (String id : ids) { | 66 | for (String id : ids) { |
63 | - brandIdSet.add(id); | 67 | + brandIds.add(id); |
64 | } | 68 | } |
65 | } | 69 | } |
66 | try { | 70 | try { |
67 | - return searchCommonService.doMultiGet(ISearchConstants.INDEX_NAME_BRAND, brandIdSet, null); | 71 | + return brandIndexBaseService.getBrandListByIds(brandIds); |
68 | } catch (Exception e) { | 72 | } catch (Exception e) { |
69 | - e.printStackTrace(); | 73 | + logger.error(e.getMessage(),e); |
70 | return null; | 74 | return null; |
71 | } | 75 | } |
72 | } | 76 | } |
@@ -177,6 +177,22 @@ public class SearchCommonService implements ApplicationEventPublisherAware { | @@ -177,6 +177,22 @@ public class SearchCommonService implements ApplicationEventPublisherAware { | ||
177 | } | 177 | } |
178 | return map; | 178 | return map; |
179 | } | 179 | } |
180 | + | ||
181 | + private Map<String, Object> getBrandMap(Map<String, Object> esMap) { | ||
182 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
183 | + map.put("id", esMap.get("id")); | ||
184 | + map.put("brand_alif", esMap.get("brandAlif")); | ||
185 | + map.put("brand_name_en", esMap.get("brandNameEn")); | ||
186 | + map.put("brand_domain", esMap.get("brandDomain")); | ||
187 | + map.put("is_hot", esMap.get("isHot")); | ||
188 | + map.put("hot_keyword", esMap.get("hotKeyword")); | ||
189 | + map.put("brand_name_cn", esMap.get("brandNameCn")); | ||
190 | + map.put("brand_ico", esMap.get("brandIco")); | ||
191 | + map.put("brand_name", esMap.get("brandName")); | ||
192 | + map.put("brand_keyword", esMap.get("brandKeyword")); | ||
193 | + map.put("status", esMap.get("status")); | ||
194 | + return map; | ||
195 | + } | ||
180 | 196 | ||
181 | /** | 197 | /** |
182 | * 通过id获取内容 | 198 | * 通过id获取内容 |
@@ -227,14 +243,6 @@ public class SearchCommonService implements ApplicationEventPublisherAware { | @@ -227,14 +243,6 @@ public class SearchCommonService implements ApplicationEventPublisherAware { | ||
227 | // 构造返回结果 | 243 | // 构造返回结果 |
228 | JSONArray list = new JSONArray(); | 244 | JSONArray list = new JSONArray(); |
229 | Map<String, Object> tmpMap; | 245 | Map<String, Object> tmpMap; |
230 | - if (indexName.equals(ISearchConstants.INDEX_NAME_BRAND)) { | ||
231 | - for (MultiGetItemResponse item : response.getResponses()) { | ||
232 | - if (item.getResponse().isExists()) { | ||
233 | - tmpMap = item.getResponse().getSource(); | ||
234 | - list.add(getBrandMap(tmpMap)); | ||
235 | - } | ||
236 | - } | ||
237 | - } | ||
238 | if (indexName.equals(ISearchConstants.INDEX_NAME_SHOPS)) { | 246 | if (indexName.equals(ISearchConstants.INDEX_NAME_SHOPS)) { |
239 | for (MultiGetItemResponse item : response.getResponses()) { | 247 | for (MultiGetItemResponse item : response.getResponses()) { |
240 | if (item.getResponse().isExists()) { | 248 | if (item.getResponse().isExists()) { |
@@ -330,22 +338,6 @@ public class SearchCommonService implements ApplicationEventPublisherAware { | @@ -330,22 +338,6 @@ public class SearchCommonService implements ApplicationEventPublisherAware { | ||
330 | return map; | 338 | return map; |
331 | } | 339 | } |
332 | 340 | ||
333 | - private Map<String, Object> getBrandMap(Map<String, Object> esMap) { | ||
334 | - Map<String, Object> map = new HashMap<String, Object>(); | ||
335 | - map.put("id", esMap.get("id")); | ||
336 | - map.put("brand_alif", esMap.get("brandAlif")); | ||
337 | - map.put("brand_name_en", esMap.get("brandNameEn")); | ||
338 | - map.put("brand_domain", esMap.get("brandDomain")); | ||
339 | - map.put("is_hot", esMap.get("isHot")); | ||
340 | - map.put("hot_keyword", esMap.get("hotKeyword")); | ||
341 | - map.put("brand_name_cn", esMap.get("brandNameCn")); | ||
342 | - map.put("brand_ico", esMap.get("brandIco")); | ||
343 | - map.put("brand_name", esMap.get("brandName")); | ||
344 | - map.put("brand_keyword", esMap.get("brandKeyword")); | ||
345 | - map.put("status", esMap.get("status")); | ||
346 | - return map; | ||
347 | - } | ||
348 | - | ||
349 | private Map<String, Object> getShopMap(Map<String, Object> esMap) { | 341 | private Map<String, Object> getShopMap(Map<String, Object> esMap) { |
350 | Map<String, Object> map = new HashMap<String, Object>(); | 342 | Map<String, Object> map = new HashMap<String, Object>(); |
351 | map.put("shop_id", esMap.get("shopsId")); | 343 | map.put("shop_id", esMap.get("shopsId")); |
@@ -20,6 +20,7 @@ import com.alibaba.fastjson.JSONObject; | @@ -20,6 +20,7 @@ import com.alibaba.fastjson.JSONObject; | ||
20 | import com.yoho.search.base.utils.ISearchConstants; | 20 | import com.yoho.search.base.utils.ISearchConstants; |
21 | import com.yoho.search.core.es.model.SearchParam; | 21 | import com.yoho.search.core.es.model.SearchParam; |
22 | import com.yoho.search.core.es.model.SearchResult; | 22 | import com.yoho.search.core.es.model.SearchResult; |
23 | +import com.yoho.search.service.service.base.BrandIndexBaseService; | ||
23 | import com.yoho.search.service.service.helper.SearchCommonHelper; | 24 | import com.yoho.search.service.service.helper.SearchCommonHelper; |
24 | import com.yoho.search.service.service.helper.SearchServiceHelper; | 25 | import com.yoho.search.service.service.helper.SearchServiceHelper; |
25 | import com.yoho.search.service.service.helper.SearchSortHelper; | 26 | import com.yoho.search.service.service.helper.SearchSortHelper; |
@@ -43,6 +44,8 @@ public class SearchProductsServiceNew { | @@ -43,6 +44,8 @@ public class SearchProductsServiceNew { | ||
43 | private AggregationService aggregationService; | 44 | private AggregationService aggregationService; |
44 | @Autowired | 45 | @Autowired |
45 | private SearchKeyWordService searchKeyWordService; | 46 | private SearchKeyWordService searchKeyWordService; |
47 | + @Autowired | ||
48 | + private BrandIndexBaseService brandIndexBaseService; | ||
46 | 49 | ||
47 | private void setHighlight(final Map<String, String> paramMap, SearchParam searchParam) { | 50 | private void setHighlight(final Map<String, String> paramMap, SearchParam searchParam) { |
48 | if (StringUtils.isNotBlank(paramMap.get("highlight")) && "1".equals(paramMap.get("highlight")) && StringUtils.isNotBlank(paramMap.get("query"))) { | 51 | if (StringUtils.isNotBlank(paramMap.get("highlight")) && "1".equals(paramMap.get("highlight")) && StringUtils.isNotBlank(paramMap.get("query"))) { |
@@ -274,7 +277,7 @@ public class SearchProductsServiceNew { | @@ -274,7 +277,7 @@ public class SearchProductsServiceNew { | ||
274 | if (brandResponse != null) { | 277 | if (brandResponse != null) { |
275 | filter.put("brand", brandResponse); | 278 | filter.put("brand", brandResponse); |
276 | } else { | 279 | } else { |
277 | - filter.put("brand", searchCommonService.doMultiGet(ISearchConstants.INDEX_NAME_BRAND, paramMap.get("brand").split(","), null)); | 280 | + filter.put("brand", brandIndexBaseService.getBrandListByIds(Arrays.asList(paramMap.get("brand").split(",")))); |
278 | } | 281 | } |
279 | 282 | ||
280 | // 7)获取规则的聚合结果[规格不会提前聚合] | 283 | // 7)获取规则的聚合结果[规格不会提前聚合] |
@@ -29,8 +29,8 @@ public class BrandIndexBaseService { | @@ -29,8 +29,8 @@ public class BrandIndexBaseService { | ||
29 | private SearchServiceHelper searchServiceHelper; | 29 | private SearchServiceHelper searchServiceHelper; |
30 | 30 | ||
31 | private static final String BRAND_INDEX_NAME = ISearchConstants.INDEX_NAME_BRAND; | 31 | private static final String BRAND_INDEX_NAME = ISearchConstants.INDEX_NAME_BRAND; |
32 | - | ||
33 | - public Map<String, Object> getBrandMap(Map<String, Object> esMap) { | 32 | + |
33 | + private Map<String, Object> getBrandMapOld(Map<String, Object> esMap) { | ||
34 | Map<String, Object> map = new HashMap<String, Object>(); | 34 | Map<String, Object> map = new HashMap<String, Object>(); |
35 | map.put("id", esMap.get("id")); | 35 | map.put("id", esMap.get("id")); |
36 | map.put("brand_alif", esMap.get("brandAlif")); | 36 | map.put("brand_alif", esMap.get("brandAlif")); |
@@ -43,11 +43,28 @@ public class BrandIndexBaseService { | @@ -43,11 +43,28 @@ public class BrandIndexBaseService { | ||
43 | map.put("brand_name", esMap.get("brandName")); | 43 | map.put("brand_name", esMap.get("brandName")); |
44 | map.put("brand_keyword", esMap.get("brandKeyword")); | 44 | map.put("brand_keyword", esMap.get("brandKeyword")); |
45 | map.put("status", esMap.get("status")); | 45 | map.put("status", esMap.get("status")); |
46 | - map.put("yoho_brand_id", esMap.get("yohoBrandId")); | ||
47 | - map.put("is_global", esMap.get("isGlobal")); | ||
48 | return map; | 46 | return map; |
49 | } | 47 | } |
50 | 48 | ||
49 | + public Map<String, Object> getBrandMap(Map<String, Object> esMap) { | ||
50 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
51 | + map.put("id", esMap.get("id")); | ||
52 | + map.put("brand_name", esMap.getOrDefault("brandName","")); | ||
53 | + map.put("brand_name_en", esMap.getOrDefault("brandNameEn","")); | ||
54 | + map.put("brand_name_cn", esMap.getOrDefault("brandNameCn","")); | ||
55 | + map.put("brand_ico", esMap.getOrDefault("brandIco","")); | ||
56 | + map.put("shelves_brand_time", esMap.getOrDefault("shelvesBrandTime",0)); | ||
57 | + map.put("is_hot", esMap.getOrDefault("isHot","N")); | ||
58 | + map.put("status", esMap.getOrDefault("status",0)); | ||
59 | + map.put("brand_alif", esMap.getOrDefault("brandAlif","")); | ||
60 | + map.put("brand_domain", esMap.getOrDefault("brandDomain","")); | ||
61 | + map.put("hot_keyword", esMap.getOrDefault("hotKeyword","")); | ||
62 | + map.put("brand_keyword", esMap.getOrDefault("brandKeyword","")); | ||
63 | + map.put("yoho_brand_id", esMap.getOrDefault("yohoBrandId",0)); | ||
64 | + map.put("is_global", esMap.getOrDefault("isGlobal","N")); | ||
65 | + return map; | ||
66 | + } | ||
67 | + | ||
51 | public List<Map<String, Object>> getBrandListByIds(List<?> brandIds) { | 68 | public List<Map<String, Object>> getBrandListByIds(List<?> brandIds) { |
52 | List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>(); | 69 | List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>(); |
53 | try { | 70 | try { |
@@ -9,7 +9,7 @@ import com.yoho.search.service.vo.SearchApiResult; | @@ -9,7 +9,7 @@ import com.yoho.search.service.vo.SearchApiResult; | ||
9 | public interface IBrandService { | 9 | public interface IBrandService { |
10 | 10 | ||
11 | /** | 11 | /** |
12 | - * 获取品牌的聚合结果[使用本地缓存] | 12 | + * 获取品牌的聚合结果[使用本地缓存][按参数决定是否返回全球购品牌] |
13 | * | 13 | * |
14 | * @param paramMap | 14 | * @param paramMap |
15 | * @return | 15 | * @return |
@@ -17,7 +17,7 @@ public interface IBrandService { | @@ -17,7 +17,7 @@ public interface IBrandService { | ||
17 | public SearchApiResult aggBrand(Map<String, String> paramMap); | 17 | public SearchApiResult aggBrand(Map<String, String> paramMap); |
18 | 18 | ||
19 | /** | 19 | /** |
20 | - * 获取品牌的聚合结果[使用本地缓存] | 20 | + * 获取品牌的聚合结果[使用本地缓存][按参数决定是否返回全球购品牌] |
21 | * | 21 | * |
22 | * @param paramMap | 22 | * @param paramMap |
23 | * @return | 23 | * @return |
@@ -25,7 +25,7 @@ public interface IBrandService { | @@ -25,7 +25,7 @@ public interface IBrandService { | ||
25 | public SearchApiResult aggBrand(Map<String, String> paramMap,BoolQueryBuilder mustFilter); | 25 | public SearchApiResult aggBrand(Map<String, String> paramMap,BoolQueryBuilder mustFilter); |
26 | 26 | ||
27 | /** | 27 | /** |
28 | - * 按品牌前缀名获取品牌列表[使用本地缓存] | 28 | + * 按品牌前缀名获取品牌列表[按参数决定是否返回全球购品牌] |
29 | * | 29 | * |
30 | * @param paramMap | 30 | * @param paramMap |
31 | * @return | 31 | * @return |
@@ -33,7 +33,7 @@ public interface IBrandService { | @@ -33,7 +33,7 @@ public interface IBrandService { | ||
33 | public SearchApiResult brands(Map<String, String> paramMap); | 33 | public SearchApiResult brands(Map<String, String> paramMap); |
34 | 34 | ||
35 | /** | 35 | /** |
36 | - * 获取商品列表[直接从brand索引里取全部] | 36 | + * 获取商品列表[直接从brand索引里取全部][不返回全球购品牌] |
37 | * | 37 | * |
38 | * @param paramMap | 38 | * @param paramMap |
39 | * @return | 39 | * @return |
@@ -41,7 +41,7 @@ public interface IBrandService { | @@ -41,7 +41,7 @@ public interface IBrandService { | ||
41 | public SearchApiResult brandList(Map<String, String> paramMap); | 41 | public SearchApiResult brandList(Map<String, String> paramMap); |
42 | 42 | ||
43 | /** | 43 | /** |
44 | - * 按品牌聚合商品 | 44 | + * 按品牌聚合商品[按参数决定是否返回全球购品牌] |
45 | * @param paramMap | 45 | * @param paramMap |
46 | * @return | 46 | * @return |
47 | */ | 47 | */ |
@@ -5,13 +5,11 @@ import java.util.Arrays; | @@ -5,13 +5,11 @@ import java.util.Arrays; | ||
5 | import java.util.Collections; | 5 | import java.util.Collections; |
6 | import java.util.Comparator; | 6 | import java.util.Comparator; |
7 | import java.util.HashMap; | 7 | import java.util.HashMap; |
8 | -import java.util.HashSet; | ||
9 | import java.util.Iterator; | 8 | import java.util.Iterator; |
10 | import java.util.LinkedHashMap; | 9 | import java.util.LinkedHashMap; |
11 | import java.util.List; | 10 | import java.util.List; |
12 | import java.util.Map; | 11 | import java.util.Map; |
13 | import java.util.Map.Entry; | 12 | import java.util.Map.Entry; |
14 | -import java.util.Set; | ||
15 | 13 | ||
16 | import org.apache.commons.lang.StringUtils; | 14 | import org.apache.commons.lang.StringUtils; |
17 | import org.elasticsearch.index.query.BoolQueryBuilder; | 15 | import org.elasticsearch.index.query.BoolQueryBuilder; |
@@ -49,6 +47,7 @@ import com.yoho.search.service.cache.CacheEnum; | @@ -49,6 +47,7 @@ import com.yoho.search.service.cache.CacheEnum; | ||
49 | import com.yoho.search.service.service.AggregationService; | 47 | import com.yoho.search.service.service.AggregationService; |
50 | import com.yoho.search.service.service.SearchCacheService; | 48 | import com.yoho.search.service.service.SearchCacheService; |
51 | import com.yoho.search.service.service.SearchCommonService; | 49 | import com.yoho.search.service.service.SearchCommonService; |
50 | +import com.yoho.search.service.service.base.BrandIndexBaseService; | ||
52 | import com.yoho.search.service.service.helper.SearchServiceHelper; | 51 | import com.yoho.search.service.service.helper.SearchServiceHelper; |
53 | import com.yoho.search.service.service.helper.SearchSortHelper; | 52 | import com.yoho.search.service.service.helper.SearchSortHelper; |
54 | import com.yoho.search.service.servicenew.IBrandService; | 53 | import com.yoho.search.service.servicenew.IBrandService; |
@@ -71,6 +70,8 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe | @@ -71,6 +70,8 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe | ||
71 | private SearchCommonService searchCommonService; | 70 | private SearchCommonService searchCommonService; |
72 | @Autowired | 71 | @Autowired |
73 | private SearchCacheService searchCacheService; | 72 | private SearchCacheService searchCacheService; |
73 | + @Autowired | ||
74 | + private BrandIndexBaseService brandIndexBaseService; | ||
74 | 75 | ||
75 | private static final CacheEnum brandCacheEnum = CacheEnum.EHCACHE; | 76 | private static final CacheEnum brandCacheEnum = CacheEnum.EHCACHE; |
76 | 77 | ||
@@ -194,16 +195,15 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe | @@ -194,16 +195,15 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe | ||
194 | brandAlif2BrandIds.put(brandAlif, brandIds); | 195 | brandAlif2BrandIds.put(brandAlif, brandIds); |
195 | } | 196 | } |
196 | // 2)获取所有的品牌id | 197 | // 2)获取所有的品牌id |
197 | - Set<String> brandIdSet = new HashSet<String>(); | 198 | + List<String> brandIds = new ArrayList<String>(); |
198 | for (Map.Entry<String, List<String>> entry : brandAlif2BrandIds.entrySet()) { | 199 | for (Map.Entry<String, List<String>> entry : brandAlif2BrandIds.entrySet()) { |
199 | - brandIdSet.addAll(entry.getValue()); | 200 | + brandIds.addAll(entry.getValue()); |
200 | } | 201 | } |
201 | // 3)获取所有的品牌数据 | 202 | // 3)获取所有的品牌数据 |
202 | - JSONArray jsonArray = searchCommonService.doMultiGet(ISearchConstants.INDEX_NAME_BRAND, brandIdSet, null); | ||
203 | - Map<String, JSONObject> brandIdMap = new HashMap<String, JSONObject>(); | ||
204 | - for (int index = 0; index < jsonArray.size(); index++) { | ||
205 | - JSONObject brandJSONObject = jsonArray.getJSONObject(index); | ||
206 | - brandIdMap.put(brandJSONObject.getString("id"), brandJSONObject); | 203 | + List<Map<String, Object>> brandList = brandIndexBaseService.getBrandListByIds(brandIds); |
204 | + Map<String, Map<String, Object>> brandIdMap = new HashMap<String, Map<String, Object>>(); | ||
205 | + for (Map<String, Object> brand:brandList) { | ||
206 | + brandIdMap.put(brand.getOrDefault("id", 0).toString(), brand); | ||
207 | } | 207 | } |
208 | // 4)构造真正的数据 | 208 | // 4)构造真正的数据 |
209 | Map<String, JSONArray> result = new LinkedHashMap<String, JSONArray>(); | 209 | Map<String, JSONArray> result = new LinkedHashMap<String, JSONArray>(); |
@@ -211,7 +211,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe | @@ -211,7 +211,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe | ||
211 | String brandAlif = entry.getKey(); | 211 | String brandAlif = entry.getKey(); |
212 | JSONArray brands = new JSONArray(); | 212 | JSONArray brands = new JSONArray(); |
213 | for (String brandId : entry.getValue()) { | 213 | for (String brandId : entry.getValue()) { |
214 | - JSONObject brand = brandIdMap.get(brandId); | 214 | + Map<String, Object> brand = brandIdMap.get(brandId); |
215 | if (brand != null) { | 215 | if (brand != null) { |
216 | brands.add(brand); | 216 | brands.add(brand); |
217 | } | 217 | } |
@@ -230,6 +230,9 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe | @@ -230,6 +230,9 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe | ||
230 | SearchParam searchParam = new SearchParam(); | 230 | SearchParam searchParam = new SearchParam(); |
231 | searchParam.setSize(10000); | 231 | searchParam.setSize(10000); |
232 | searchParam.setQuery(QueryBuilders.matchAllQuery()); | 232 | searchParam.setQuery(QueryBuilders.matchAllQuery()); |
233 | + BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); | ||
234 | + boolQueryBuilder.mustNot(QueryBuilders.termQuery("isGlobal", "Y")); | ||
235 | + searchParam.setFiter(boolQueryBuilder); | ||
233 | 236 | ||
234 | // 2、brand数据量比较大,走本地缓存。guavacache缓存中获取result,没有到es中获取 | 237 | // 2、brand数据量比较大,走本地缓存。guavacache缓存中获取result,没有到es中获取 |
235 | final String indexName = ISearchConstants.INDEX_NAME_BRAND; | 238 | final String indexName = ISearchConstants.INDEX_NAME_BRAND; |
@@ -238,25 +241,17 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe | @@ -238,25 +241,17 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe | ||
238 | CACHE_MATCH_REQUEST.info("match cache , url is :/brand/list.json?" + HttpServletRequestUtils.genParamString(paramMap)); | 241 | CACHE_MATCH_REQUEST.info("match cache , url is :/brand/list.json?" + HttpServletRequestUtils.genParamString(paramMap)); |
239 | return new SearchApiResult().setData(cacheJSONArray); | 242 | return new SearchApiResult().setData(cacheJSONArray); |
240 | } | 243 | } |
244 | + // 3、执行搜索 | ||
241 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_BRAND, searchParam); | 245 | SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_BRAND, searchParam); |
242 | if (searchResult == null || searchResult.getResultList().isEmpty()) { | 246 | if (searchResult == null || searchResult.getResultList().isEmpty()) { |
243 | return new SearchApiResult().setData(400).setMessage("empty result"); | 247 | return new SearchApiResult().setData(400).setMessage("empty result"); |
244 | } | 248 | } |
249 | + //4、构建返回结果并加入缓存 | ||
245 | List<Map<String, Object>> result = searchResult.getResultList(); | 250 | List<Map<String, Object>> result = searchResult.getResultList(); |
246 | JSONArray jsonArray = new JSONArray(); | 251 | JSONArray jsonArray = new JSONArray(); |
247 | for (Map<String, Object> map : result) { | 252 | for (Map<String, Object> map : result) { |
248 | - Map<String, Object> dataMap = new HashMap<>(); | ||
249 | - dataMap.put("id", map.get("id")); | ||
250 | - dataMap.put("brand_alif", map.get("brandAlif")); | ||
251 | - dataMap.put("brand_name_en", map.get("brandNameEn")); | ||
252 | - dataMap.put("brand_domain", map.get("brandDomain")); | ||
253 | - dataMap.put("is_hot", map.get("isHot")); | ||
254 | - dataMap.put("hot_keyword", map.get("hotKeyword")); | ||
255 | - dataMap.put("brand_name_cn", map.get("brandNameCn")); | ||
256 | - dataMap.put("brand_ico", map.get("brandIco")); | ||
257 | - dataMap.put("brand_name", map.get("brandName")); | ||
258 | - dataMap.put("brand_keyword", map.get("brandKeyword")); | ||
259 | - jsonArray.add(dataMap); | 253 | + Map<String, Object> brandInfo= brandIndexBaseService.getBrandMap(map); |
254 | + jsonArray.add(brandInfo); | ||
260 | } | 255 | } |
261 | searchCacheService.addJSONArrayToCache(brandCacheEnum, indexName, searchParam, jsonArray); | 256 | searchCacheService.addJSONArrayToCache(brandCacheEnum, indexName, searchParam, jsonArray); |
262 | return new SearchApiResult().setMessage("brands info").setData(jsonArray); | 257 | return new SearchApiResult().setMessage("brands info").setData(jsonArray); |
-
Please register or login to post a comment