...
|
...
|
@@ -5,13 +5,11 @@ import java.util.Arrays; |
|
|
import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Map.Entry;
|
|
|
import java.util.Set;
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
...
|
...
|
@@ -49,6 +47,7 @@ import com.yoho.search.service.cache.CacheEnum; |
|
|
import com.yoho.search.service.service.AggregationService;
|
|
|
import com.yoho.search.service.service.SearchCacheService;
|
|
|
import com.yoho.search.service.service.SearchCommonService;
|
|
|
import com.yoho.search.service.service.base.BrandIndexBaseService;
|
|
|
import com.yoho.search.service.service.helper.SearchServiceHelper;
|
|
|
import com.yoho.search.service.service.helper.SearchSortHelper;
|
|
|
import com.yoho.search.service.servicenew.IBrandService;
|
...
|
...
|
@@ -71,6 +70,8 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe |
|
|
private SearchCommonService searchCommonService;
|
|
|
@Autowired
|
|
|
private SearchCacheService searchCacheService;
|
|
|
@Autowired
|
|
|
private BrandIndexBaseService brandIndexBaseService;
|
|
|
|
|
|
private static final CacheEnum brandCacheEnum = CacheEnum.EHCACHE;
|
|
|
|
...
|
...
|
@@ -194,16 +195,15 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe |
|
|
brandAlif2BrandIds.put(brandAlif, brandIds);
|
|
|
}
|
|
|
// 2)获取所有的品牌id
|
|
|
Set<String> brandIdSet = new HashSet<String>();
|
|
|
List<String> brandIds = new ArrayList<String>();
|
|
|
for (Map.Entry<String, List<String>> entry : brandAlif2BrandIds.entrySet()) {
|
|
|
brandIdSet.addAll(entry.getValue());
|
|
|
brandIds.addAll(entry.getValue());
|
|
|
}
|
|
|
// 3)获取所有的品牌数据
|
|
|
JSONArray jsonArray = searchCommonService.doMultiGet(ISearchConstants.INDEX_NAME_BRAND, brandIdSet, null);
|
|
|
Map<String, JSONObject> brandIdMap = new HashMap<String, JSONObject>();
|
|
|
for (int index = 0; index < jsonArray.size(); index++) {
|
|
|
JSONObject brandJSONObject = jsonArray.getJSONObject(index);
|
|
|
brandIdMap.put(brandJSONObject.getString("id"), brandJSONObject);
|
|
|
List<Map<String, Object>> brandList = brandIndexBaseService.getBrandListByIds(brandIds);
|
|
|
Map<String, Map<String, Object>> brandIdMap = new HashMap<String, Map<String, Object>>();
|
|
|
for (Map<String, Object> brand:brandList) {
|
|
|
brandIdMap.put(brand.getOrDefault("id", 0).toString(), brand);
|
|
|
}
|
|
|
// 4)构造真正的数据
|
|
|
Map<String, JSONArray> result = new LinkedHashMap<String, JSONArray>();
|
...
|
...
|
@@ -211,7 +211,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe |
|
|
String brandAlif = entry.getKey();
|
|
|
JSONArray brands = new JSONArray();
|
|
|
for (String brandId : entry.getValue()) {
|
|
|
JSONObject brand = brandIdMap.get(brandId);
|
|
|
Map<String, Object> brand = brandIdMap.get(brandId);
|
|
|
if (brand != null) {
|
|
|
brands.add(brand);
|
|
|
}
|
...
|
...
|
@@ -230,6 +230,9 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe |
|
|
SearchParam searchParam = new SearchParam();
|
|
|
searchParam.setSize(10000);
|
|
|
searchParam.setQuery(QueryBuilders.matchAllQuery());
|
|
|
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
|
|
boolQueryBuilder.mustNot(QueryBuilders.termQuery("isGlobal", "Y"));
|
|
|
searchParam.setFiter(boolQueryBuilder);
|
|
|
|
|
|
// 2、brand数据量比较大,走本地缓存。guavacache缓存中获取result,没有到es中获取
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_BRAND;
|
...
|
...
|
@@ -238,25 +241,17 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe |
|
|
CACHE_MATCH_REQUEST.info("match cache , url is :/brand/list.json?" + HttpServletRequestUtils.genParamString(paramMap));
|
|
|
return new SearchApiResult().setData(cacheJSONArray);
|
|
|
}
|
|
|
// 3、执行搜索
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_BRAND, searchParam);
|
|
|
if (searchResult == null || searchResult.getResultList().isEmpty()) {
|
|
|
return new SearchApiResult().setData(400).setMessage("empty result");
|
|
|
}
|
|
|
//4、构建返回结果并加入缓存
|
|
|
List<Map<String, Object>> result = searchResult.getResultList();
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
for (Map<String, Object> map : result) {
|
|
|
Map<String, Object> dataMap = new HashMap<>();
|
|
|
dataMap.put("id", map.get("id"));
|
|
|
dataMap.put("brand_alif", map.get("brandAlif"));
|
|
|
dataMap.put("brand_name_en", map.get("brandNameEn"));
|
|
|
dataMap.put("brand_domain", map.get("brandDomain"));
|
|
|
dataMap.put("is_hot", map.get("isHot"));
|
|
|
dataMap.put("hot_keyword", map.get("hotKeyword"));
|
|
|
dataMap.put("brand_name_cn", map.get("brandNameCn"));
|
|
|
dataMap.put("brand_ico", map.get("brandIco"));
|
|
|
dataMap.put("brand_name", map.get("brandName"));
|
|
|
dataMap.put("brand_keyword", map.get("brandKeyword"));
|
|
|
jsonArray.add(dataMap);
|
|
|
Map<String, Object> brandInfo= brandIndexBaseService.getBrandMap(map);
|
|
|
jsonArray.add(brandInfo);
|
|
|
}
|
|
|
searchCacheService.addJSONArrayToCache(brandCacheEnum, indexName, searchParam, jsonArray);
|
|
|
return new SearchApiResult().setMessage("brands info").setData(jsonArray);
|
...
|
...
|
|