...
|
...
|
@@ -54,8 +54,6 @@ public class SknRecallCacheBean { |
|
|
try {
|
|
|
if (recommedSknList == null || recommedSknList.isEmpty()) {
|
|
|
return new ArrayList<>();
|
|
|
//localhost:8080/yohosearch/productindex/productList.json?uid=11145&status=1&gender=1,2,3,4,5
|
|
|
//recommedSknList = Arrays.asList(50020667,50026235,50026280,50024584,50026611,50028826,50031356,50031387,50029959,51001108);
|
|
|
}
|
|
|
List<Integer> filterSknList;
|
|
|
if (recallWithCache) {
|
...
|
...
|
@@ -63,15 +61,17 @@ public class SknRecallCacheBean { |
|
|
} else {
|
|
|
filterSknList = this.filterRecommedSknListByEs(userRecallRequest, recommedSknList);
|
|
|
}
|
|
|
RECALL_NEW_LOGGER.info("recommedSknList size is [{}], filterSknListSize is[{}]", recommedSknList.size(), filterSknList.size());
|
|
|
return this.buildResults(userRecallRequest, filterSknList, maxReturnCount);
|
|
|
}catch (Exception e){
|
|
|
RECALL_NEW_LOGGER.error(e.getMessage(),e);
|
|
|
} catch (Exception e) {
|
|
|
RECALL_NEW_LOGGER.error(e.getMessage(), e);
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 从ehcahc或者redis中构造返回结果
|
|
|
*
|
|
|
* @param userRecallRequest
|
|
|
* @param recommedSknList
|
|
|
* @return
|
...
|
...
|
@@ -79,7 +79,7 @@ public class SknRecallCacheBean { |
|
|
private List<Integer> filterRecommendWithCache(UserRecallRequest userRecallRequest, List<Integer> recommedSknList) {
|
|
|
//1、skn转成productId
|
|
|
Map<Integer, Integer> productSknToIdMap = sknBaseInfoCacheBean.queryProductSknToProductIdMap(recommedSknList);
|
|
|
if(productSknToIdMap==null || productSknToIdMap.isEmpty()){
|
|
|
if (productSknToIdMap == null || productSknToIdMap.isEmpty()) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
List<Integer> recommedProductIds = new ArrayList<>();
|
...
|
...
|
@@ -88,29 +88,26 @@ public class SknRecallCacheBean { |
|
|
//2、先从本地缓存获取
|
|
|
ParamQueryFilter paramQueryFilter = userRecallRequest.getParamQueryFilter();
|
|
|
RedisKeyBuilder redisKeyBuilder = pageProductIdBitSetComponent.genRedisKeyBuilder(paramQueryFilter);
|
|
|
Map<Integer, Boolean> ehcacheQueryResult = ehCache.getFromBitSet(redisKeyBuilder,recommedProductIds);
|
|
|
Map<Integer, Boolean> ehcacheQueryResult = ehCache.getFromBitSet(redisKeyBuilder, recommedProductIds);
|
|
|
if (ehcacheQueryResult != null) {
|
|
|
return this.filterSknByCacheQueryResult(recommedSknList,productSknToIdMap, ehcacheQueryResult);
|
|
|
RECALL_NEW_LOGGER.info("filterSknBy EhCache success");
|
|
|
return this.filterSknByCacheQueryResult(recommedSknList, productSknToIdMap, ehcacheQueryResult);
|
|
|
}
|
|
|
|
|
|
//3、再从redis的bitset缓存结构中过滤
|
|
|
Map<Integer, Boolean> redisQueryResult = searchRedis.getFromBitSet(redisKeyBuilder, recommedProductIds);
|
|
|
if (redisQueryResult != null) {
|
|
|
//TODO 回写本地缓存
|
|
|
return this.filterSknByCacheQueryResult(recommedSknList, productSknToIdMap,redisQueryResult);
|
|
|
RECALL_NEW_LOGGER.info("filterSknBy Redis success");
|
|
|
return this.filterSknByCacheQueryResult(recommedSknList, productSknToIdMap, redisQueryResult);
|
|
|
}
|
|
|
|
|
|
//4、执行查询,添加到缓存
|
|
|
PageProductIdBitSet pageProductIdBitSet = pageProductIdBitSetComponent.queryPageProductIdBitSet(userRecallRequest.getParamQueryFilter());
|
|
|
//3.1)添加到本地缓存
|
|
|
this.ehCache.setBitSet(redisKeyBuilder,pageProductIdBitSet.getProductIdBitSet(),pageProductIdBitSetComponent.cacheTimeInMinute());
|
|
|
//3.2)添加到redis缓存
|
|
|
//TODO 异步加入redis缓存
|
|
|
this.searchRedis.setBitSet(redisKeyBuilder,pageProductIdBitSet.getProductIdBitSet(),pageProductIdBitSetComponent.cacheTimeInMinute());
|
|
|
return this.filterSknByPageProductIdBitSet(recommedSknList,productSknToIdMap, pageProductIdBitSet.getProductIdBitSet());
|
|
|
//4.1)添加到本地缓存
|
|
|
this.ehCache.setBitSet(redisKeyBuilder, pageProductIdBitSet.getProductIdBitSet(), pageProductIdBitSetComponent.cacheTimeInMinute());
|
|
|
//4.2)异步添加到redis缓存
|
|
|
this.searchRedis.setBitSet(redisKeyBuilder, pageProductIdBitSet.getProductIdBitSet(), pageProductIdBitSetComponent.cacheTimeInMinute());
|
|
|
return this.filterSknByPageProductIdBitSet(recommedSknList, productSknToIdMap, pageProductIdBitSet.getProductIdBitSet());
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 从bitset对象中构造返回对象
|
|
|
*
|
...
|
...
|
@@ -118,11 +115,11 @@ public class SknRecallCacheBean { |
|
|
* @param bitSet
|
|
|
* @return
|
|
|
*/
|
|
|
private List<Integer> filterSknByPageProductIdBitSet(List<Integer> recommedSknList,Map<Integer, Integer> productSknToIdMap, BitSet bitSet) {
|
|
|
private List<Integer> filterSknByPageProductIdBitSet(List<Integer> recommedSknList, Map<Integer, Integer> productSknToIdMap, BitSet bitSet) {
|
|
|
List<Integer> existProductSkns = new ArrayList<>();
|
|
|
for (Integer recommedSkn : recommedSknList) {
|
|
|
Integer productId = productSknToIdMap.get(recommedSkn);
|
|
|
if(productId==null){
|
|
|
if (productId == null) {
|
|
|
continue;
|
|
|
}
|
|
|
if (!bitSet.get(productId)) {
|
...
|
...
|
@@ -140,11 +137,11 @@ public class SknRecallCacheBean { |
|
|
* @param cacheQueryResult
|
|
|
* @return
|
|
|
*/
|
|
|
private List<Integer> filterSknByCacheQueryResult(List<Integer> recommedSknList,Map<Integer, Integer> productSknToIdMap, Map<Integer, Boolean> cacheQueryResult) {
|
|
|
private List<Integer> filterSknByCacheQueryResult(List<Integer> recommedSknList, Map<Integer, Integer> productSknToIdMap, Map<Integer, Boolean> cacheQueryResult) {
|
|
|
List<Integer> existProductSkns = new ArrayList<>();
|
|
|
for (Integer recommedSkn : recommedSknList) {
|
|
|
Integer productId = productSknToIdMap.get(recommedSkn);
|
|
|
if(productId==null){
|
|
|
if (productId == null) {
|
|
|
continue;
|
|
|
}
|
|
|
if (!cacheQueryResult.getOrDefault(productId, false)) {
|
...
|
...
|
|