...
|
...
|
@@ -66,7 +66,6 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
@Autowired
|
|
|
private SearchCacheFactory searchCacheFactory;
|
|
|
|
|
|
|
|
|
private SearchCache productListSearchCache;
|
|
|
|
|
|
@PostConstruct
|
...
|
...
|
@@ -74,7 +73,7 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
productListSearchCache = searchCacheFactory.getProductListSearchCache();
|
|
|
}
|
|
|
|
|
|
private static final String product_skn = "product_skn";
|
|
|
private static final String view_product_skn = "view_product_skn";
|
|
|
private static final String cart_product_skn = "cart_product_skn";
|
|
|
private static final String collect_product_skn = "collect_product_skn";
|
|
|
|
...
|
...
|
@@ -102,7 +101,7 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
}
|
|
|
|
|
|
// 1.1 SKN参数获取
|
|
|
List<String> product_skns = stringToList(paramMap.getOrDefault(product_skn, ""), ",");
|
|
|
List<String> product_skns = stringToList(paramMap.getOrDefault(view_product_skn, ""), ",");
|
|
|
List<String> cart_productskns = stringToList(paramMap.getOrDefault(cart_product_skn, ""), ",");
|
|
|
List<String> collect_product_skns = stringToList(paramMap.getOrDefault(collect_product_skn, ""), ",");
|
|
|
|
...
|
...
|
@@ -122,9 +121,9 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
|
|
|
// 4、构造搜索参数
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
BoolQueryBuilder boolFilter = searchServiceHelper.constructFilterBuilder(paramMap, null);
|
|
|
boolFilter = this.getDefaultBoolQueryBuilder(boolFilter);
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
BoolQueryBuilder boolFilter = searchServiceHelper.constructFilterBuilder(paramMap, null);
|
|
|
boolFilter = this.getDefaultBoolQueryBuilder(boolFilter);
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
searchParam.setQuery(this.builderGoodProductQueryBuilder(paramMap, recommondSkns));
|
|
|
searchParam.setAggregationBuilders(null);
|
|
|
searchParam.setPage(page);
|
...
|
...
|
@@ -139,7 +138,7 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
|
|
|
// 5)从缓存中获取数据
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
|
|
|
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(productListSearchCache,indexName, searchParam);
|
|
|
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(productListSearchCache, indexName, searchParam);
|
|
|
if (cacheObject != null) {
|
|
|
JSONArray product_list = cacheObject.getJSONArray("product_list");
|
|
|
if (product_list != null) {
|
...
|
...
|
@@ -162,7 +161,7 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
dataMap.put("product_list", productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList(), Arrays.asList("phrase")));
|
|
|
|
|
|
// 8)将结果存进缓存
|
|
|
searchCacheService.addJSONObjectToCache(productListSearchCache,indexName, searchParam, dataMap);
|
|
|
searchCacheService.addJSONObjectToCache(productListSearchCache, indexName, searchParam, dataMap);
|
|
|
return new SearchApiResult().setData(dataMap);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -191,7 +190,7 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
searchParam.setOffset(0);
|
|
|
|
|
|
// 4、先从缓存中获取,如果能取到,则直接返回
|
|
|
JSONObject sortAndBrandJSONObject = searchCacheService.getJSONObjectFromCache(productListSearchCache,ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
JSONObject sortAndBrandJSONObject = searchCacheService.getJSONObjectFromCache(productListSearchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
if (sortAndBrandJSONObject != null) {
|
|
|
return sortAndBrandJSONObject;
|
|
|
}
|
...
|
...
|
@@ -210,7 +209,7 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
sortAndBrandJSONObject = new JSONObject();
|
|
|
sortAndBrandJSONObject.put("brandIds", brandIds);
|
|
|
sortAndBrandJSONObject.put("smallSortIds", smallSortIds);
|
|
|
searchCacheService.addJSONObjectToCache(productListSearchCache,ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam, sortAndBrandJSONObject);
|
|
|
searchCacheService.addJSONObjectToCache(productListSearchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam, sortAndBrandJSONObject);
|
|
|
return sortAndBrandJSONObject;
|
|
|
|
|
|
}
|
...
|
...
|
@@ -251,8 +250,8 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
}
|
|
|
// 2、构造filter
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
BoolQueryBuilder boolFilter = searchServiceHelper.constructFilterBuilder(paramMap, null);
|
|
|
boolFilter = this.getDefaultBoolQueryBuilder(boolFilter);
|
|
|
BoolQueryBuilder boolFilter = searchServiceHelper.constructFilterBuilder(paramMap, null);
|
|
|
boolFilter = this.getDefaultBoolQueryBuilder(boolFilter);
|
|
|
BoolQueryBuilder brandAndSortFilter = new BoolQueryBuilder();
|
|
|
if (!brandIds.isEmpty()) {
|
|
|
brandAndSortFilter.should(QueryBuilders.termsQuery("brandId", brandIds));
|
...
|
...
|
@@ -290,7 +289,7 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
searchParam.setOffset(0);
|
|
|
|
|
|
// 6、先从缓存中获取,如果能取到,则直接返回
|
|
|
JSONArray recommendedSknJSONArray = searchCacheService.getJSONArrayFromCache(productListSearchCache,ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
JSONArray recommendedSknJSONArray = searchCacheService.getJSONArrayFromCache(productListSearchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
if (recommendedSknJSONArray != null) {
|
|
|
return this.jsonArrayToList(recommendedSknJSONArray, String.class);
|
|
|
}
|
...
|
...
|
@@ -343,7 +342,7 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
if (cart_productskns.isEmpty() && collect_product_skns.isEmpty()) {
|
|
|
this.addListToJsonArray(recommendedSknJSONArray, product_skns);
|
|
|
}
|
|
|
searchCacheService.addJSONArrayToCache(productListSearchCache,indexName, searchParam, recommendedSknJSONArray);
|
|
|
searchCacheService.addJSONArrayToCache(productListSearchCache, indexName, searchParam, recommendedSknJSONArray);
|
|
|
return this.jsonArrayToList(recommendedSknJSONArray, String.class);
|
|
|
}
|
|
|
|
...
|
...
|
|