Authored by 胡古飞

fix brand index

... ... @@ -162,9 +162,7 @@ public class SearchCommonService implements ApplicationEventPublisherAware {
return map;
}
// 构造返回结果
if (indexName.equals(ISearchConstants.INDEX_NAME_BRAND)) {
map = getBrandMap(response.getSource());
} else if (indexName.equals(ISearchConstants.INDEX_NAME_PRODUCT_COLOR)) {
if (indexName.equals(ISearchConstants.INDEX_NAME_PRODUCT_COLOR)) {
map = getColorMap(response.getSource());
} else if (indexName.equals(ISearchConstants.INDEX_NAME_SIZE)) {
map = getSizeMap(response.getSource());
... ... @@ -177,22 +175,6 @@ public class SearchCommonService implements ApplicationEventPublisherAware {
}
return map;
}
private Map<String, Object> getBrandMap(Map<String, Object> esMap) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", esMap.get("id"));
map.put("brand_alif", esMap.get("brandAlif"));
map.put("brand_name_en", esMap.get("brandNameEn"));
map.put("brand_domain", esMap.get("brandDomain"));
map.put("is_hot", esMap.get("isHot"));
map.put("hot_keyword", esMap.get("hotKeyword"));
map.put("brand_name_cn", esMap.get("brandNameCn"));
map.put("brand_ico", esMap.get("brandIco"));
map.put("brand_name", esMap.get("brandName"));
map.put("brand_keyword", esMap.get("brandKeyword"));
map.put("status", esMap.get("status"));
return map;
}
/**
* 通过id获取内容
... ...
... ... @@ -235,14 +235,14 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe
searchParam.setFiter(boolQueryBuilder);
// 2、brand数据量比较大,走本地缓存。guavacache缓存中获取result,没有到es中获取
final String indexName = ISearchConstants.INDEX_NAME_BRAND;
JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(brandCacheEnum, indexName, searchParam);
final String brandIndexName = ISearchConstants.INDEX_NAME_BRAND;
JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(brandCacheEnum, brandIndexName, searchParam);
if (cacheJSONArray != null) {
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);
SearchResult searchResult = searchCommonService.doSearch(brandIndexName, searchParam);
if (searchResult == null || searchResult.getResultList().isEmpty()) {
return new SearchApiResult().setData(400).setMessage("empty result");
}
... ... @@ -253,7 +253,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe
Map<String, Object> brandInfo= brandIndexBaseService.getBrandMap(map);
jsonArray.add(brandInfo);
}
searchCacheService.addJSONArrayToCache(brandCacheEnum, indexName, searchParam, jsonArray);
searchCacheService.addJSONArrayToCache(brandCacheEnum, brandIndexName, searchParam, jsonArray);
return new SearchApiResult().setMessage("brands info").setData(jsonArray);
} catch (Exception e) {
publisher.publishEvent(new SearchEvent(EventReportEnum.BRANDCONTROLLER_BRAND_LIST.getEventName(), EventReportEnum.BRANDCONTROLLER_BRAND_LIST.getFunctionName(),
... ... @@ -310,6 +310,7 @@ public class BrandServiceImpl implements IBrandService, ApplicationEventPublishe
JSONArray jsonArrayBrands = (JSONArray) searchApiResultBrands.getData();
Iterator<Object> it = jsonArrayBrands.iterator();
while (it.hasNext()) {
@SuppressWarnings("unchecked")
Map<String, Object> dataMap = (Map<String, Object>) it.next();
brandMap.put(dataMap.get("id").toString(), dataMap);
}
... ...
... ... @@ -29,6 +29,7 @@ import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
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.servicenew.IBreakSizeService;
import com.yoho.search.service.servicenew.ISelectionsWithAdvanceService;
... ... @@ -51,6 +52,8 @@ public class SelectionWithAdvanceImpl implements ISelectionsWithAdvanceService {
private SearchAfterCacheService searchAfterCacheService;
@Autowired
private IBreakSizeService breakSizeService;
@Autowired
private BrandIndexBaseService brandIndexBaseService;
private static Logger logger = LoggerFactory.getLogger(SelectionWithAdvanceImpl.class);
private static Logger CACHE_MATCH_REQUEST = LoggerFactory.getLogger("CACHE_MATCH_REQUEST");
... ... @@ -333,7 +336,7 @@ public class SelectionWithAdvanceImpl implements ISelectionsWithAdvanceService {
}
// 7) 如果参数里面有brand,则将此brand返回给PC
if (StringUtils.isNotBlank(paramMap.get("brand"))) {
JSONArray paramBrand = searchCommonService.doMultiGet(ISearchConstants.INDEX_NAME_BRAND, paramMap.get("brand").split(","), null);
List<Map<String, Object>> paramBrand =brandIndexBaseService.getBrandListByIds(Arrays.asList(paramMap.get("brand").split(",")));
filter.put("paramBrand", paramBrand);
} else {
filter.put("paramBrand", new JSONArray());
... ...
... ... @@ -8,6 +8,7 @@ import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
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.servicenew.ISelectionsWithOutAdvanceService;
import com.yoho.search.service.utils.HttpServletRequestUtils;
... ... @@ -42,6 +43,8 @@ public class SelectionWithOutAdvanceImpl implements ISelectionsWithOutAdvanceSer
private SearchCacheService searchCacheService;
@Autowired
private SearchAfterCacheService searchAfterCacheService;
@Autowired
private BrandIndexBaseService brandIndexBaseService;
@Override
public SearchApiResult getSelectionsForApp(Map<String, String> paramMap) {
... ... @@ -188,9 +191,9 @@ public class SelectionWithOutAdvanceImpl implements ISelectionsWithOutAdvanceSer
if (brandResponse != null) {
filter.put("brand", brandResponse);
} else {
filter.put("brand", searchCommonService.doMultiGet(ISearchConstants.INDEX_NAME_BRAND, paramMap.get("brand").split(","), null));
filter.put("brand", brandIndexBaseService.getBrandListByIds(Arrays.asList(paramMap.get("brand").split(","))));
}
// 7)获取尺码聚合结果[尺码不会提前聚合]
IAggregation sizeAggregation = aggregationFactoryService.getSizeAggregation();
Object sizeResponse = sizeAggregation.getAggregationResponseMap(aggMaps);
... ...