Showing
4 changed files
with
24 additions
and
19 deletions
@@ -59,8 +59,8 @@ public class SceneRecallService { | @@ -59,8 +59,8 @@ public class SceneRecallService { | ||
59 | //3、执行召回 | 59 | //3、执行召回 |
60 | RecallSknResult recallSknResult = recallService.getRecallSknResult(recallSknParams); | 60 | RecallSknResult recallSknResult = recallService.getRecallSknResult(recallSknParams); |
61 | //4、根据召回结果查询商品信息 | 61 | //4、根据召回结果查询商品信息 |
62 | - List<Map<String, Object>> productList = this.queryProductList(recallSknParams, recallSknResult,page,pageSize); | ||
63 | - //6、构造返回结果 | 62 | + List<Map<String, Object>> productList = this.queryProductList(recallSknParams,recallSknResult,page,pageSize); |
63 | + //5、构造返回结果 | ||
64 | JSONObject dataMap = new JSONObject(); | 64 | JSONObject dataMap = new JSONObject(); |
65 | dataMap.put("total", recallSknResult.getTotal()); | 65 | dataMap.put("total", recallSknResult.getTotal()); |
66 | dataMap.put("page", page); | 66 | dataMap.put("page", page); |
@@ -74,7 +74,7 @@ public class SceneRecallService { | @@ -74,7 +74,7 @@ public class SceneRecallService { | ||
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | - private List<Map<String, Object>> queryProductList(RecallSknParams recallSknParams, RecallSknResult recallSknResult,int page,int pageSize) { | 77 | + private List<Map<String, Object>> queryProductList( RecallSknParams recallSknParams,RecallSknResult recallSknResult,int page,int pageSize) { |
78 | //1、判断当前页码是否在召回的页码里 | 78 | //1、判断当前页码是否在召回的页码里 |
79 | int recallTotalPage = recallSknResult.getRecallTotalPage(); | 79 | int recallTotalPage = recallSknResult.getRecallTotalPage(); |
80 | //2、在召回结果中则直接根据skn去查询 | 80 | //2、在召回结果中则直接根据skn去查询 |
@@ -84,7 +84,7 @@ public class SceneRecallService { | @@ -84,7 +84,7 @@ public class SceneRecallService { | ||
84 | } | 84 | } |
85 | //3、过滤召回的skn,修改真实页码,执行查询 | 85 | //3、过滤召回的skn,修改真实页码,执行查询 |
86 | int realPage = page - recallTotalPage; | 86 | int realPage = page - recallTotalPage; |
87 | - return this.queryProductByFilterSkn(recallSknResult.getSknList(), realPage, pageSize); | 87 | + return this.queryProductByFilterSkn(recallSknParams, recallSknResult.getSknList(), realPage, pageSize); |
88 | } | 88 | } |
89 | 89 | ||
90 | /** | 90 | /** |
@@ -94,15 +94,20 @@ public class SceneRecallService { | @@ -94,15 +94,20 @@ public class SceneRecallService { | ||
94 | * @param pageSize | 94 | * @param pageSize |
95 | * @return | 95 | * @return |
96 | */ | 96 | */ |
97 | - private List<Map<String, Object>> queryProductByFilterSkn(List<Integer> notProductSkns,int realPage,int pageSize){ | 97 | + private List<Map<String, Object>> queryProductByFilterSkn(RecallSknParams recallSknParams,List<Integer> notProductSkns,int realPage,int pageSize){ |
98 | SearchParam searchParam = new SearchParam(); | 98 | SearchParam searchParam = new SearchParam(); |
99 | - //设置分页参数 | ||
100 | - searchParam.setOffset((realPage-1)*pageSize); | ||
101 | - searchParam.setSize(pageSize); | 99 | + |
100 | + //设置query | ||
101 | + searchParam.setQuery(recallSknParams.getParamQueryFilter().getParamQuery()); | ||
102 | 102 | ||
103 | //设置filter | 103 | //设置filter |
104 | - BoolQueryBuilder filter = QueryBuilders.boolQuery(); | 104 | + BoolQueryBuilder filter = recallSknParams.getParamQueryFilter().getParamFilter(); |
105 | filter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.productSkn,notProductSkns)); | 105 | filter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.productSkn,notProductSkns)); |
106 | + searchParam.setFiter(filter); | ||
107 | + | ||
108 | + //设置分页参数 | ||
109 | + searchParam.setOffset((realPage-1)*pageSize); | ||
110 | + searchParam.setSize(pageSize); | ||
106 | 111 | ||
107 | //设置IncludeFields | 112 | //设置IncludeFields |
108 | searchParam.setIncludeFields(productIndexBaseService.getProductIndexIncludeFields()); | 113 | searchParam.setIncludeFields(productIndexBaseService.getProductIndexIncludeFields()); |
@@ -79,13 +79,13 @@ public class CacheRequestResponseComponent { | @@ -79,13 +79,13 @@ public class CacheRequestResponseComponent { | ||
79 | * @param <V> | 79 | * @param <V> |
80 | * @param <T> | 80 | * @param <T> |
81 | */ | 81 | */ |
82 | - public <K extends ICacheRequest, V, T extends CacheRequestResponse<K, V>> void batchFillResponseWithQueryResults(List<T> cacheRequestResponses,Map<RedisKeyBuilder,V> queryResults){ | 82 | + public <K extends ICacheRequest, V, T extends CacheRequestResponse<K, V>> void batchFillResponseWithQueryResults(List<T> cacheRequestResponses,Map<String,V> queryResults){ |
83 | for (T sknInfoRequestResponse : cacheRequestResponses) { | 83 | for (T sknInfoRequestResponse : cacheRequestResponses) { |
84 | if(sknInfoRequestResponse.getResponse()!=null){ | 84 | if(sknInfoRequestResponse.getResponse()!=null){ |
85 | continue; | 85 | continue; |
86 | } | 86 | } |
87 | RedisKeyBuilder redisKeyBuilder = sknInfoRequestResponse.getRequest().redisKeyBuilder(); | 87 | RedisKeyBuilder redisKeyBuilder = sknInfoRequestResponse.getRequest().redisKeyBuilder(); |
88 | - V response = queryResults.get(redisKeyBuilder); | 88 | + V response = queryResults.get(redisKeyBuilder.getKey()); |
89 | if(response!=null){ | 89 | if(response!=null){ |
90 | sknInfoRequestResponse.setResponse(response,true); | 90 | sknInfoRequestResponse.setResponse(response,true); |
91 | } | 91 | } |
@@ -69,7 +69,7 @@ public class BacthSknInfoComponent { | @@ -69,7 +69,7 @@ public class BacthSknInfoComponent { | ||
69 | //3、获取未命中缓存的请求 | 69 | //3、获取未命中缓存的请求 |
70 | List<CacheSknInfoRequestResponse> missCacheRequests = cacheRequestResponseComponent.filterMissCacheRequests(sknInfoCacheRequestRespons); | 70 | List<CacheSknInfoRequestResponse> missCacheRequests = cacheRequestResponseComponent.filterMissCacheRequests(sknInfoCacheRequestRespons); |
71 | //4、执行批量查询 | 71 | //4、执行批量查询 |
72 | - Map<RedisKeyBuilder,Map<String, Object>> queryResults = this.batchQueryMissCacheRequests(missCacheRequests); | 72 | + Map<String,Map<String, Object>> queryResults = this.batchQueryMissCacheRequests(missCacheRequests); |
73 | //5、填充查询结果 | 73 | //5、填充查询结果 |
74 | cacheRequestResponseComponent.batchFillResponseWithQueryResults(sknInfoCacheRequestRespons,queryResults); | 74 | cacheRequestResponseComponent.batchFillResponseWithQueryResults(sknInfoCacheRequestRespons,queryResults); |
75 | //6、将CacheRequestResponse中需要缓存的key加入缓存 | 75 | //6、将CacheRequestResponse中需要缓存的key加入缓存 |
@@ -77,9 +77,9 @@ public class BacthSknInfoComponent { | @@ -77,9 +77,9 @@ public class BacthSknInfoComponent { | ||
77 | return sknInfoCacheRequestRespons; | 77 | return sknInfoCacheRequestRespons; |
78 | } | 78 | } |
79 | 79 | ||
80 | - private Map<RedisKeyBuilder,Map<String, Object>> batchQueryMissCacheRequests(List<CacheSknInfoRequestResponse> notCachedRequestResponse) { | 80 | + private Map<String,Map<String, Object>> batchQueryMissCacheRequests(List<CacheSknInfoRequestResponse> notCachedRequestResponse) { |
81 | //1、合法性判断 | 81 | //1、合法性判断 |
82 | - Map<RedisKeyBuilder,Map<String, Object>> results = new HashMap<>(); | 82 | + Map<String,Map<String, Object>> results = new HashMap<>(); |
83 | if(notCachedRequestResponse==null||notCachedRequestResponse.isEmpty()){ | 83 | if(notCachedRequestResponse==null||notCachedRequestResponse.isEmpty()){ |
84 | return results; | 84 | return results; |
85 | } | 85 | } |
@@ -103,7 +103,7 @@ public class BacthSknInfoComponent { | @@ -103,7 +103,7 @@ public class BacthSknInfoComponent { | ||
103 | } | 103 | } |
104 | //5、构造最终结果 | 104 | //5、构造最终结果 |
105 | for (CacheSknInfoRequestResponse requestResponse :notCachedRequestResponse ) { | 105 | for (CacheSknInfoRequestResponse requestResponse :notCachedRequestResponse ) { |
106 | - results.put(requestResponse.getRequest().redisKeyBuilder(),productTempMap.get(requestResponse.getRequest().getProductSkn())); | 106 | + results.put(requestResponse.getRequest().redisKeyBuilder().getKey(),productTempMap.get(requestResponse.getRequest().getProductSkn())); |
107 | } | 107 | } |
108 | return results; | 108 | return results; |
109 | } | 109 | } |
@@ -57,7 +57,7 @@ public class BatchRecallComponent { | @@ -57,7 +57,7 @@ public class BatchRecallComponent { | ||
57 | } | 57 | } |
58 | 58 | ||
59 | //5、处理剩余请求 | 59 | //5、处理剩余请求 |
60 | - Map<RedisKeyBuilder,RecallResponse> notCacheResults = this.queryNotCachedResult(missCacheRequests); | 60 | + Map<String,RecallResponse> notCacheResults = this.queryNotCachedResult(missCacheRequests); |
61 | 61 | ||
62 | //6、填充recallRequestResponses | 62 | //6、填充recallRequestResponses |
63 | cacheRequestResponseHelper.batchFillResponseWithQueryResults(recallRequestResponses,notCacheResults); | 63 | cacheRequestResponseHelper.batchFillResponseWithQueryResults(recallRequestResponses,notCacheResults); |
@@ -74,7 +74,7 @@ public class BatchRecallComponent { | @@ -74,7 +74,7 @@ public class BatchRecallComponent { | ||
74 | * @param notCachedRequests | 74 | * @param notCachedRequests |
75 | * @return | 75 | * @return |
76 | */ | 76 | */ |
77 | - private Map<RedisKeyBuilder,RecallResponse> queryNotCachedResult(List<CacheRecallRequestResponse> notCachedRequests) { | 77 | + private Map<String,RecallResponse> queryNotCachedResult(List<CacheRecallRequestResponse> notCachedRequests) { |
78 | //1、构造请求参数 | 78 | //1、构造请求参数 |
79 | List<SearchParam> searchParams = new ArrayList<>(); | 79 | List<SearchParam> searchParams = new ArrayList<>(); |
80 | for (CacheRecallRequestResponse requestResponse : notCachedRequests) { | 80 | for (CacheRecallRequestResponse requestResponse : notCachedRequests) { |
@@ -83,12 +83,12 @@ public class BatchRecallComponent { | @@ -83,12 +83,12 @@ public class BatchRecallComponent { | ||
83 | //2、执行搜索 | 83 | //2、执行搜索 |
84 | List<SearchResult> searchResults = searchCommonService.doMutiSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParams); | 84 | List<SearchResult> searchResults = searchCommonService.doMutiSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParams); |
85 | //3、构造返回结果 | 85 | //3、构造返回结果 |
86 | - Map<RedisKeyBuilder,RecallResponse> notCachedResults = new HashMap<>(); | 86 | + Map<String,RecallResponse> notCachedResults = new HashMap<>(); |
87 | for (int i = 0; i < notCachedRequests.size(); i++) { | 87 | for (int i = 0; i < notCachedRequests.size(); i++) { |
88 | RecallRequest request = notCachedRequests.get(i).getRequest(); | 88 | RecallRequest request = notCachedRequests.get(i).getRequest(); |
89 | SearchResult searchResult = searchResults.get(i); | 89 | SearchResult searchResult = searchResults.get(i); |
90 | RecallResponse response = this.buildResonse(searchResult); | 90 | RecallResponse response = this.buildResonse(searchResult); |
91 | - notCachedResults.put(request.redisKeyBuilder(),response); | 91 | + notCachedResults.put(request.redisKeyBuilder().getKey(),response); |
92 | } | 92 | } |
93 | return notCachedResults; | 93 | return notCachedResults; |
94 | } | 94 | } |
-
Please register or login to post a comment