|
|
package com.yoho.search.service.scene.general;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.error.event.SearchEvent;
|
|
|
import com.yoho.search.aop.cache.SearchCacheAble;
|
|
|
import com.yoho.search.base.utils.EventReportEnum;
|
|
|
import com.yoho.search.base.utils.ISearchConstants;
|
|
|
import com.yoho.search.cache.beans.AbstractCacheAbleService;
|
|
|
import com.yoho.search.cache.log.SearchCacheMatchLogger;
|
|
|
import com.yoho.search.cache.model.SearchCache;
|
|
|
import com.yoho.search.common.SearchCommonService;
|
|
|
import com.yoho.search.common.utils.SearchApiResultUtils;
|
|
|
import com.yoho.search.core.es.agg.IAggregation;
|
|
|
import com.yoho.search.core.es.model.SearchParam;
|
...
|
...
|
@@ -17,8 +13,6 @@ import com.yoho.search.core.es.model.SearchResult; |
|
|
import com.yoho.search.core.es.utils.IgnoreSomeException;
|
|
|
import com.yoho.search.models.SearchApiResult;
|
|
|
import com.yoho.search.service.aggregations.impls.AggregationFactory;
|
|
|
import com.yoho.search.common.SearchCommonService;
|
|
|
import com.yoho.search.service.helper.SearchAfterCacheHelper;
|
|
|
import com.yoho.search.service.helper.SearchParamHelper;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
...
|
...
|
@@ -27,8 +21,11 @@ import org.springframework.context.ApplicationEventPublisher; |
|
|
import org.springframework.context.ApplicationEventPublisherAware;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
public class RecentService extends AbstractCacheAbleService implements ApplicationEventPublisherAware {
|
|
|
public class RecentService implements ApplicationEventPublisherAware {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(RecentService.class);
|
|
|
|
...
|
...
|
@@ -37,15 +34,8 @@ public class RecentService extends AbstractCacheAbleService implements Applicati |
|
|
@Autowired
|
|
|
private SearchCommonService searchCommonService;
|
|
|
@Autowired
|
|
|
private SearchAfterCacheHelper searchAfterCacheService;
|
|
|
@Autowired
|
|
|
private SearchParamHelper searchParamHelper;
|
|
|
|
|
|
@Override
|
|
|
public SearchCache getSearchCache() {
|
|
|
return searchCacheFactory.getAggregationSearchCache();
|
|
|
}
|
|
|
|
|
|
private ApplicationEventPublisher publisher;
|
|
|
|
|
|
@Override
|
...
|
...
|
@@ -53,10 +43,9 @@ public class RecentService extends AbstractCacheAbleService implements Applicati |
|
|
this.publisher = applicationEventPublisher;
|
|
|
}
|
|
|
|
|
|
@SearchCacheAble(cacheInMinute = 30, cacheName = "RECENT", excludeParams = {"client_type", "yh_channel", "order", "uid", "udid"})
|
|
|
public SearchApiResult recent(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
logger.info("[func=recent][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis());
|
|
|
|
|
|
// 构造查询参数
|
|
|
SearchParam searchParam = searchParamHelper.buildDefault(paramMap);
|
|
|
|
...
|
...
|
@@ -68,15 +57,6 @@ public class RecentService extends AbstractCacheAbleService implements Applicati |
|
|
// 构造返回结果
|
|
|
SearchApiResult searchApiResult = new SearchApiResult().setMessage("recentShelveDay List.");
|
|
|
|
|
|
// 先从缓存中获取,如果能取到,则直接返回
|
|
|
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(this.searchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
if (cacheObject != null) {
|
|
|
Object result = searchAfterCacheService.dealRecentCacheObject(cacheObject);
|
|
|
searchApiResult.setData(result);
|
|
|
SearchCacheMatchLogger.doSearchCacheMatchLog("/recent.json", paramMap);
|
|
|
return searchApiResult;
|
|
|
}
|
|
|
|
|
|
// 进行检索
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
|
|
|
SearchResult searchResult = searchCommonService.doSearch(indexName, searchParam);
|
...
|
...
|
@@ -90,14 +70,13 @@ public class RecentService extends AbstractCacheAbleService implements Applicati |
|
|
}
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("recent", recentShelveDayResponse);
|
|
|
searchCacheService.addJSONObjectToCache(this.searchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam, jsonObject);
|
|
|
return searchApiResult.setData(jsonObject);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(),e);
|
|
|
publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_RECENT.getEventName(), EventReportEnum.SEARCHCONTROLLER_RECENT.getFunctionName(),
|
|
|
EventReportEnum.SEARCHCONTROLLER_RECENT.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null));
|
|
|
return SearchApiResultUtils.errorSearchApiResult("recent", paramMap, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|