Authored by unknown

场景化的列表和筛选项缓存优化

... ... @@ -4,54 +4,40 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.common.cache.SearchCacheFactory;
import com.yoho.search.common.cache.SearchCacheMatchLogger;
import com.yoho.search.common.cache.model.SearchCache;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.base.ProductListSortService;
import com.yoho.search.service.base.SearchCacheService;
import com.yoho.search.service.base.SearchCommonService;
import com.yoho.search.service.base.index.ProductIndexBaseService;
import com.yoho.search.service.helper.SearchCommonHelper;
import com.yoho.search.service.helper.SearchParamHelper;
import com.yoho.search.service.helper.SearchSortHelper;
import com.yoho.search.service.service.impl.BaseService;
@Service
public class SceneProductListService extends BaseService {
public class SceneProductListService extends AbstractCacheAbleService {
@Autowired
private SearchCommonHelper searchCommonHelper;
@Autowired
private SearchCommonService searchCommonService;
@Autowired
private ProductIndexBaseService productIndexBaseService;
@Autowired
private SearchCacheService searchCacheService;
@Autowired
private SearchCacheFactory searchCacheFactory;
@Autowired
private SearchParamHelper searchParamHelper;
@Autowired
private SearchSortHelper searchSortHelper;
@Autowired
private ProductListSortService productListSortService;
private SearchCache searchCache;
@PostConstruct
void init() {
searchCache = searchCacheFactory.getProductListSearchCache();
@Override
public SearchCache getSearchCache() {
return searchCacheFactory.getProductListSearchCache();
}
/**
... ... @@ -67,7 +53,7 @@ public class SceneProductListService extends BaseService {
// 2)从缓存中获取数据
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(searchCache, indexName, searchParam);
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(this.searchCache, indexName, searchParam);
if (cacheObject != null) {
SearchCacheMatchLogger.doSearchCacheMatchLog("/scene/productList.json", paramMap);
return new SearchApiResult().setData(cacheObject);
... ... @@ -87,9 +73,9 @@ public class SceneProductListService extends BaseService {
dataMap.put("page_total", searchResult.getTotalPage());
List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
dataMap.put("product_list", productListSortService.sortProductList(product_list, paramMap));// 处理一下商品的顺序;
// 5)将结果存进缓存
searchCacheService.addJSONObjectToCache(searchCache, indexName, searchParam, dataMap);
searchCacheService.addJSONObjectToCache(this.searchCache, indexName, searchParam, dataMap);
return new SearchApiResult().setData(dataMap);
}
... ... @@ -114,8 +100,8 @@ public class SceneProductListService extends BaseService {
searchParam.setSortBuilders(searchSortHelper.buildSortList(paramMap));
// 4)设置不返回的参数【节省带宽】
List<String> excludeFields = productIndexBaseService.getProductIndexExcludeFields();
searchParam.setExcludeFields(excludeFields);
searchParam.setExcludeFields(excludeFields);
return searchParam;
}
... ...
... ... @@ -8,8 +8,6 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.annotation.PostConstruct;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
... ... @@ -21,7 +19,6 @@ import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.common.cache.SearchCacheFactory;
import com.yoho.search.common.cache.SearchCacheMatchLogger;
import com.yoho.search.common.cache.model.SearchCache;
import com.yoho.search.core.es.agg.IAggregation;
... ... @@ -29,54 +26,32 @@ import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
import com.yoho.search.service.base.SearchCacheService;
import com.yoho.search.service.base.SearchCommonService;
import com.yoho.search.service.base.SearchDynamicConfigService;
import com.yoho.search.service.base.index.ProductIndexBaseService;
import com.yoho.search.service.helper.SearchCommonHelper;
import com.yoho.search.service.helper.SearchKeyWordHelper;
import com.yoho.search.service.helper.SearchParamHelper;
import com.yoho.search.service.service.IAggRecommendService;
import com.yoho.search.service.service.ISearchRecommendService;
import com.yoho.search.service.service.impl.BaseService;
@Service
public class SceneSelectionsService extends BaseService {
public class SceneSelectionsService extends AbstractCacheAbleService {
private static final Logger logger = LoggerFactory.getLogger(SceneSelectionsService.class);
@Autowired
private SearchCommonHelper searchCommonHelper;
@Autowired
private SearchParamHelper searchParamHelper;
@Autowired
private SearchCommonService searchCommonService;
@Autowired
private SearchKeyWordHelper searchKeyWordService;
@Autowired
private ISearchRecommendService searchRecommendService;
@Autowired
private SearchDynamicConfigService searchDynamicConfigService;
@Autowired
private ProductIndexBaseService productIndexBaseService;
@Autowired
private SearchCacheService searchCacheService;
@Autowired
private SearchCacheFactory searchCacheFactory;
@Autowired
private AggregationFactoryService aggregationFactoryService;
@Autowired
private IAggRecommendService aggRecommendService;
private SearchCache aggregationSearchCache;
@Override
public SearchCache getSearchCache() {
return searchCacheFactory.getSelectionsForAppCache();
}
private ExecutorService executorService = Executors.newFixedThreadPool(100);
@PostConstruct
void init() {
aggregationSearchCache = searchCacheFactory.getSelectionsForAppCache();
}
/**
* @新版筛选器的聚合选项:
* @1、全球购
... ... @@ -202,7 +177,7 @@ public class SceneSelectionsService extends BaseService {
searchParam.setSize(0);
// 先从缓存里取,取到则处理下缓存结果并直接返回
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(aggregationSearchCache, productIndexName, searchParam);
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(this.searchCache, productIndexName, searchParam);
if (cacheObject != null) {
SearchCacheMatchLogger.doSearchCacheMatchLog("/scene/aggregations.json", paramMap);
return cacheObject;
... ... @@ -216,7 +191,7 @@ public class SceneSelectionsService extends BaseService {
}
// 构造返回结果
JSONObject dataMap = this.genFilterResult(aggregations, aggMaps);
searchCacheService.addJSONObjectToCache(aggregationSearchCache, productIndexName, searchParam, dataMap);
searchCacheService.addJSONObjectToCache(this.searchCache, productIndexName, searchParam, dataMap);
return dataMap;
} catch (Exception e) {
logger.error("[func=getFiltersResults][params=" + paramMap + "]", e);
... ...