Authored by unknown

代码优化

Showing 18 changed files with 9 additions and 42 deletions
... ... @@ -61,9 +61,6 @@ public class AggregationService implements ApplicationEventPublisherAware {
private SearchResult doSearchForAggregation(IAggregation aggregation, SearchParam searchParam) {
SearchParam searchParamClone = searchParam.clone();
searchParamClone.setPage(1);
searchParamClone.setOffset(1);
searchParamClone.setSize(0);
return searchCommonService.doSearch(AggregationServiceIndex, searchParamClone);
}
... ... @@ -106,9 +103,7 @@ public class AggregationService implements ApplicationEventPublisherAware {
private SearchParam genSearchParamForAgg(IAggregation aggregation, Map<String, String> paramMap, String filterParamName, int cacheSize) throws Exception {
SearchParam searchParam = searchParamHelper.buildWithFilterParam(paramMap,filterParamName);
searchParam.setAggregationBuilders(Arrays.asList(aggregation.getBuilder()));
searchParam.setPage(0);
searchParam.setOffset(cacheSize);// 只是用来做缓存的
searchParam.setSize(0);
return searchParam;
}
... ...
... ... @@ -100,8 +100,6 @@ public class SearchLikeHelper {
boolFilter.must(QueryBuilders.termsQuery("productSkn", productSkn));
searchParam.setFiter(boolFilter);
searchParam.setAggregationBuilders(null);
searchParam.setPage(0);
searchParam.setOffset(0);
searchParam.setSize(1);
String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
... ...
... ... @@ -88,7 +88,6 @@ public class HelperServiceImpl extends BaseService implements IHelperService, Ap
if (pageSize > 500) {
pageSize = 500;
}
searchParam.setPage(page);
searchParam.setOffset((page - 1) * pageSize);
searchParam.setSize(pageSize);
... ...
... ... @@ -56,9 +56,6 @@ public class ProductCountServiceImpl implements IProductCountService {
private long queryProductCount(SearchParam searchParam) {
// 1)为searchParam设置默认值
searchParam.setAggregationBuilders(null);
searchParam.setPage(0);
searchParam.setOffset(0);
searchParam.setSize(0);
searchParam.setSearchType(SearchType.QUERY_THEN_FETCH);
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
... ...
... ... @@ -268,7 +268,6 @@ public class ProductListServiceImpl implements IProductListService {
SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, true);
setHighlight(paramMap, searchParam);
searchParam.setAggregationBuilders(null);
searchParam.setPage(page);
searchParam.setSize(pageSize);
searchParam.setOffset((page - 1) * pageSize);
// 3)设置排序字段
... ...
... ... @@ -231,7 +231,6 @@ public class ProductListWithSupplyServiceImpl implements IProductListWithSupplyS
SearchParam searchParam = searchParamHelper.buildDefault(paramMap);
setHighlight(paramMap, searchParam);
searchParam.setAggregationBuilders(null);
searchParam.setPage(page);
searchParam.setOffset((page - 1) * pageSize);
searchParam.setSize(pageSize);
// 3)设置排序字段
... ...
... ... @@ -103,7 +103,6 @@ public class RobotQuestionServiceImpl extends BaseService implements IRobotQuest
if (pageSize > 500) {
pageSize = 500;
}
searchParam.setPage(page);
searchParam.setOffset((page - 1) * pageSize);
searchParam.setSize(pageSize);
... ...
... ... @@ -257,7 +257,7 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService {
QueryBuilder queryBuilder = isLimitKeywords ? buildQueryBuilderByLimit(terms) : buildQueryBuilder(keywordsToSearch, termSet);
searchParam.setQuery(queryBuilder);
searchParam.setPage(1);
searchParam.setOffset(0);
searchParam.setSize(SMART_SUGGESTION_TERM_COUNT);
// 3.5) 设置过滤条件
... ... @@ -461,7 +461,7 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService {
// 2) 根据terms搜索构造搜索请求 要求完全匹配source
SearchParam searchParam = new SearchParam();
searchParam.setQuery(QueryBuilders.termQuery("source.source_keyword", queryWord.trim().toLowerCase()));
searchParam.setPage(1);
searchParam.setOffset(0);
searchParam.setSize(1);
searchParam.setFiter(QueryBuilders.termQuery("status", 1));
... ... @@ -519,7 +519,6 @@ public class SearchRecommendServiceImpl implements ISearchRecommendService {
SearchParam searchParam = new SearchParam();
QueryBuilder queryBuilder = StringUtils.isNotEmpty(queryWord) ? QueryBuilders.matchQuery("source", queryWord) : QueryBuilders.matchAllQuery();
searchParam.setQuery(queryBuilder);
searchParam.setPage(page);
searchParam.setOffset((page - 1) * 10);
searchParam.setSize(10);
if (updateTime > 0) {
... ...
... ... @@ -116,8 +116,7 @@ public class SearchSortGroupService implements ISearchSortGroupService, Applicat
searchParam.setAggregationBuilders(sortGroupBuilders);
// 设置查询结果
searchParam.setPage(1);
searchParam.setOffset(1);
searchParam.setOffset(1);//just for cache
searchParam.setSize(0);
// 构造返回结果
... ...
... ... @@ -75,8 +75,7 @@ public class SelectionForAppImpl implements ISelectionsForApp {
searchParam.setAggregationBuilders(this.getAllAggregationBuilders(paramMap));
// 构造其他参数
final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
searchParam.setPage(1);
searchParam.setOffset(1);
searchParam.setOffset(2);//just for cache
searchParam.setSize(0);
// 先从缓存里取,取到则处理下缓存结果并直接返回
... ...
... ... @@ -92,8 +92,7 @@ public class SelectionsForPcImpl implements ISelectionsForPc {
public SearchApiResult getSelectionsForPc(Map<String, String> paramMap, BoolQueryBuilder mustFilter) throws Exception {
// 1)构造SearchParam
SearchParam searchParam = searchParamHelper.buildWithMustFilter(paramMap, mustFilter);
searchParam.setPage(1);
searchParam.setOffset(1);
searchParam.setOffset(3);// just for cache
searchParam.setSize(0);
SearchParam searchParamClone = searchParam.clone();// 用来缓存
... ...
... ... @@ -126,9 +126,8 @@ public class SimilarProductServiceImpl extends BaseService implements ISimilarPr
aggregationBuilders.add(brandIdAgg);
searchParam.setAggregationBuilders(aggregationBuilders);
// 3、设置分页
searchParam.setPage(0);
searchParam.setSize(0);
searchParam.setOffset(0);
searchParam.setSize(0);
// 4、先从缓存中获取,如果能取到,则直接返回
JSONObject sortAndBrandJSONObject = searchCacheService.getJSONObjectFromCache(searchLikeSearchCache,ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
if (sortAndBrandJSONObject != null) {
... ... @@ -190,9 +189,8 @@ public class SimilarProductServiceImpl extends BaseService implements ISimilarPr
searchParam.setAggregationBuilders(Arrays.asList(smallSortAndBrandAgg));
// 5、设置分页
searchParam.setPage(0);
searchParam.setSize(0);
searchParam.setOffset(0);
searchParam.setSize(0);
// 6、先从缓存中获取,如果能取到,则直接返回
JSONArray recommendedSknJSONArray = searchCacheService.getJSONArrayFromCache(searchLikeSearchCache,ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
... ... @@ -228,7 +226,6 @@ public class SimilarProductServiceImpl extends BaseService implements ISimilarPr
searchParam.setFiter(this.getDefaultBoolQueryBuilder());
searchParam.setQuery(this.builderProductQueryBuilder(paramMap, recommendSknList));
searchParam.setAggregationBuilders(null);
searchParam.setPage(page);
searchParam.setOffset((page - 1) * pageSize);
searchParam.setSize(pageSize);
List<SortBuilder> sortBuilders = new ArrayList<>();
... ...
... ... @@ -148,8 +148,8 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl
QueryBuilder query = QueryBuilders.boolQuery().should(QueryBuilders.prefixQuery("keyword", keyword)).should(QueryBuilders.prefixQuery("keyword.keyword_pinyin", keyword))
.should(QueryBuilders.prefixQuery("keyword.keyword_jianpin", keyword));
searchParam.setQuery(query);
searchParam.setPage(1);
searchParam.setSize(size);
searchParam.setOffset(0);
// count数量要>=2
final String countEsField = getCountField(paramMap);
... ... @@ -285,7 +285,6 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl
}
searchParam.setQuery(queryBuilder);
searchParam.setPage(page);
searchParam.setOffset((page - 1) * 10);
searchParam.setSize(10);
... ... @@ -332,7 +331,6 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl
List<SortBuilder> sortBuilders = new ArrayList<SortBuilder>();
sortBuilders.add(SortBuilders.fieldSort(countEsField).order(SortOrder.DESC));
searchParam.setSortBuilders(sortBuilders);
searchParam.setPage(page);
searchParam.setOffset((page - 1) * pageSize);
searchParam.setSize(pageSize);
// 2) 调用ES查询
... ...
... ... @@ -125,7 +125,6 @@ public class GoodProductSceneService {
searchParam.setFiter(boolFilter);
searchParam.setQuery(this.builderGoodProductQueryBuilder(paramMap, boolFilter, recommondSkns));
searchParam.setAggregationBuilders(null);
searchParam.setPage(page);
searchParam.setOffset((page - 1) * pageSize);
searchParam.setSize(pageSize);
//设置不返回字段
... ... @@ -184,7 +183,6 @@ public class GoodProductSceneService {
aggregationBuilders.add(brandIdAgg);
searchParam.setAggregationBuilders(aggregationBuilders);
// 3、设置分页
searchParam.setPage(0);
searchParam.setSize(0);
searchParam.setOffset(0);
... ... @@ -283,7 +281,6 @@ public class GoodProductSceneService {
searchParam.setAggregationBuilders(list);
// 5、设置分页
searchParam.setPage(0);
searchParam.setSize(0);
searchParam.setOffset(0);
... ...
... ... @@ -227,7 +227,6 @@ public class PromotionSceneService {
if (pageSize > 500) {
pageSize = 500;
}
searchParam.setPage(page);
searchParam.setOffset((page - 1) * pageSize);
searchParam.setSize(pageSize);
// 5)设置排序字段
... ... @@ -277,9 +276,8 @@ public class PromotionSceneService {
aggregationBuilders.add(sortGroupAggregation.getBuilder());
// 4、设置分页参数
searchParam.setPage(1);
searchParam.setOffset(0);
searchParam.setSize(1);
searchParam.setSize(0);
final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
... ...
... ... @@ -143,7 +143,6 @@ public class SearchLikeSceneService {
sortBuilders.add(SortBuilders.fieldSort("_score").order(SortOrder.DESC));
searchParam.setSortBuilders(sortBuilders);
// 4、设置分页参数
searchParam.setPage(1);
searchParam.setOffset(0);
searchParam.setSize(limit);
... ... @@ -196,7 +195,6 @@ public class SearchLikeSceneService {
searchParam.setAggregationBuilders(list);
// 4、设置分页参数
searchParam.setPage(0);
searchParam.setOffset(0);
searchParam.setSize(0);
... ... @@ -370,7 +368,6 @@ public class SearchLikeSceneService {
sortBuilders.add(SortBuilders.fieldSort("_score").order(SortOrder.DESC));
searchParam.setSortBuilders(sortBuilders);
// 4、设置分页参数
searchParam.setPage(1);
searchParam.setOffset(0);
searchParam.setSize(pageSize);
return searchParam;
... ...
... ... @@ -108,7 +108,6 @@ public class SceneProductListService extends BaseService {
SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, true);
setHighlight(paramMap, searchParam);
searchParam.setAggregationBuilders(null);
searchParam.setPage(page);
searchParam.setOffset((page - 1) * pageSize);
searchParam.setSize(pageSize);
// 3)设置排序字段
... ...
... ... @@ -197,7 +197,6 @@ public class SceneSelectionsService extends BaseService {
searchParam.setAggregationBuilders(this.getAggregationBuilders(aggregations));
// 2)构造其他参数
final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
searchParam.setPage(0);
searchParam.setOffset(100);// just for cache
searchParam.setSize(0);
... ...