...
|
...
|
@@ -166,21 +166,28 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
searchParam.setPage(0);
|
|
|
searchParam.setSize(0);
|
|
|
searchParam.setOffset(0);
|
|
|
// 4、执行搜索
|
|
|
|
|
|
// 4、先从缓存中获取,如果能取到,则直接返回
|
|
|
JSONArray sknSmallSortIdJSONArray = searchCacheService.getJSONArrayFromCache(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
if (sknSmallSortIdJSONArray != null) {
|
|
|
return this.jsonArrayToList(sknSmallSortIdJSONArray,Integer.class);
|
|
|
}
|
|
|
// 5、执行搜索
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
if (searchResult == null || searchResult.getAggMaps() == null || searchResult.getAggMaps().get("smallSortAgg") == null) {
|
|
|
return new ArrayList<Integer>();
|
|
|
}
|
|
|
List<Integer> results = new ArrayList<Integer>();
|
|
|
sknSmallSortIdJSONArray = new JSONArray();
|
|
|
MultiBucketsAggregation aggregation = (MultiBucketsAggregation) searchResult.getAggMaps().get(aggName);
|
|
|
Iterator<? extends Bucket> smallSortIdIterator = aggregation.getBuckets().iterator();
|
|
|
while (smallSortIdIterator.hasNext()) {
|
|
|
Bucket smallSortIdBucket = smallSortIdIterator.next();
|
|
|
if (StringUtils.isNumeric(smallSortIdBucket.getKeyAsString())) {
|
|
|
results.add(Integer.valueOf(smallSortIdBucket.getKeyAsString()));
|
|
|
sknSmallSortIdJSONArray.add(Integer.valueOf(smallSortIdBucket.getKeyAsString()));
|
|
|
}
|
|
|
}
|
|
|
return results;
|
|
|
searchCacheService.addJSONArrayToCache(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam, sknSmallSortIdJSONArray);
|
|
|
return this.jsonArrayToList(sknSmallSortIdJSONArray,Integer.class);
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -213,6 +220,7 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
// 2、构造filter
|
|
|
BoolQueryBuilder boolFilter = this.getDefaultBoolQueryBuilder();
|
|
|
boolFilter.must(QueryBuilders.termsQuery("smallSortId", smallSortIds));
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
|
|
|
// 3、构造query[针对用户做个性化打分]
|
|
|
searchParam.setQuery(searchServiceHelper.constructQueryBuilderForProductList(paramMap));
|
...
|
...
|
@@ -240,7 +248,7 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
// 6、先从缓存中获取,如果能取到,则直接返回
|
|
|
JSONArray recommendedSknJSONArray = searchCacheService.getJSONArrayFromCache(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
if (recommendedSknJSONArray != null) {
|
|
|
return this.jsonArrayToList(recommendedSknJSONArray);
|
|
|
return this.jsonArrayToList(recommendedSknJSONArray,String.class);
|
|
|
}
|
|
|
// 7、执行搜索,并构造返回结果
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
|
...
|
...
|
@@ -258,15 +266,11 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
recommendedSknJSONArray.add(recommendedSkn);
|
|
|
}
|
|
|
searchCacheService.addJSONArrayToCache(indexName, searchParam, recommendedSknJSONArray);
|
|
|
return this.jsonArrayToList(recommendedSknJSONArray);
|
|
|
return this.jsonArrayToList(recommendedSknJSONArray,String.class);
|
|
|
}
|
|
|
|
|
|
private List<String> jsonArrayToList(JSONArray jsonArray) {
|
|
|
List<String> results = new ArrayList<String>();
|
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
results.add(jsonArray.getString(i));
|
|
|
}
|
|
|
return results;
|
|
|
private <T> List<T> jsonArrayToList(JSONArray jsonArray,Class<T> clazz){
|
|
|
return JSONObject.parseArray(jsonArray.toJSONString(), clazz);
|
|
|
}
|
|
|
|
|
|
private List<String> getRecommendedSknList(MultiBucketsAggregation aggregation) {
|
...
|
...
|
|