Authored by wangnan

Merge branch '0110' of http://git.yoho.cn/yoho-search/yoho-search-service into 0110

... ... @@ -29,6 +29,7 @@ import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.error.event.SearchEvent;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ISearchConstants;
... ... @@ -120,11 +121,10 @@ public class AggProductListServiceImpl implements IAggProductListService,Applica
SearchApiResult searchApiResult = new SearchApiResult().setMessage("agg productList list");
// 6、先从缓存中获取,如果能取到,则直接返回
JSONArray jsonArray = searchCacheService.getJSONArrayFromCache(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
if (jsonArray != null) {
return searchApiResult.setData(jsonArray);
JSONObject jsonObject = searchCacheService.getJSONObjectFromCache(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
if (jsonObject != null) {
return searchApiResult.setData(jsonObject);
}
// 7、执行搜索,并构造返回结果
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
SearchResult searchResult = searchCommonService.doSearch(indexName, searchParam);
... ... @@ -136,12 +136,18 @@ public class AggProductListServiceImpl implements IAggProductListService,Applica
return searchApiResult.setData("");
}
JSONArray productList = this.getProductList(((MultiBucketsAggregation) aggMaps.get(firstAggName)));
searchCacheService.addJSONArrayToCache(indexName, searchParam, productList);
return searchApiResult.setData(productList);
jsonObject = new JSONObject();
jsonObject.put("total", productList==null ?0:productList.size());
jsonObject.put("page", 1);
jsonObject.put("page_size", viewNum);
jsonObject.put("page_total", 1);
jsonObject.put("product_list", productList);
searchCacheService.addJSONObjectToCache(indexName, searchParam, jsonObject);
return searchApiResult.setData(jsonObject);
} catch (Exception e) {
publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_NEW_SHELVE.getEventName(), EventReportEnum.SEARCHCONTROLLER_NEW_SHELVE.getFunctionName(),
EventReportEnum.SEARCHCONTROLLER_NEW_SHELVE.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null));
return SearchApiResultUtils.errorSearchApiResult("searchNewestProductWithDiffBrand", paramMap, e);
publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_AGG_PRODUCTLIST.getEventName(), EventReportEnum.SEARCHCONTROLLER_AGG_PRODUCTLIST.getFunctionName(),
EventReportEnum.SEARCHCONTROLLER_AGG_PRODUCTLIST.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null));
return SearchApiResultUtils.errorSearchApiResult("aggProductList", paramMap, e);
}
}
... ...