|
|
package com.yoho.search.recall.scene.beans.cache;
|
|
|
|
|
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
|
|
import com.yoho.search.base.utils.CollectionUtils;
|
|
|
import com.yoho.search.base.utils.ISearchConstants;
|
|
|
import com.yoho.search.base.utils.ProductIndexEsField;
|
|
|
import com.yoho.search.common.cache.impls.EhCache;
|
...
|
...
|
@@ -9,9 +10,13 @@ import com.yoho.search.common.cache.model.CacheObject; |
|
|
import com.yoho.search.core.es.model.SearchParam;
|
|
|
import com.yoho.search.core.es.model.SearchResult;
|
|
|
import com.yoho.search.recall.scene.beans.persional.PageProductIdBitSetComponent;
|
|
|
import com.yoho.search.recall.scene.beans.strategy.IStrategy;
|
|
|
import com.yoho.search.recall.scene.beans.strategy.impls.IRecallSknStrategy;
|
|
|
import com.yoho.search.recall.scene.beans.strategy.impls.RealTimeSimilarSknStrategy;
|
|
|
import com.yoho.search.recall.scene.beans.strategy.impls.RecommendSknStrategy;
|
|
|
import com.yoho.search.recall.scene.models.common.ParamQueryFilter;
|
|
|
import com.yoho.search.recall.scene.models.personal.PageProductIdBitSet;
|
|
|
import com.yoho.search.recall.scene.models.personal.UserPersonalFactor;
|
|
|
import com.yoho.search.recall.scene.models.req.RecallRequest;
|
|
|
import com.yoho.search.recall.scene.models.req.RecallRequestResponse;
|
|
|
import com.yoho.search.recall.scene.models.req.RecallResponse;
|
...
|
...
|
@@ -50,25 +55,63 @@ public class SknRecallCacheBean { |
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public List<RecallRequestResponse> batchRecallRecommedSknList(UserRecallRequest userRecallRequest, List<Integer> recommedSknList, int maxReturnCount) {
|
|
|
public List<RecallRequestResponse> batchRecallBySknList(UserRecallRequest userRecallRequest, UserPersonalFactor userPersonalFactor, int maxReturnCount) {
|
|
|
try {
|
|
|
if (recommedSknList == null || recommedSknList.isEmpty()) {
|
|
|
return new ArrayList<>();
|
|
|
//1、获取SKN,以及每个skn对应的找回类型
|
|
|
List<Integer> filterSknList = new ArrayList<>();
|
|
|
if (userPersonalFactor.getRecommendSknList() != null) {
|
|
|
filterSknList.addAll(userPersonalFactor.getRecommendSknList());
|
|
|
}
|
|
|
List<Integer> filterSknList;
|
|
|
if (userPersonalFactor.getRealTimeSimilarSknList() != null) {
|
|
|
filterSknList.addAll(userPersonalFactor.getRealTimeSimilarSknList());
|
|
|
}
|
|
|
//2、执行查询
|
|
|
List<Integer> filterSknResults;
|
|
|
if (recallWithCache) {
|
|
|
filterSknList = this.filterRecommendWithCache(userRecallRequest, recommedSknList);
|
|
|
filterSknResults = this.filterRecommendWithCache(userRecallRequest, filterSknList);
|
|
|
} else {
|
|
|
filterSknList = this.filterRecommedSknListByEs(userRecallRequest, recommedSknList);
|
|
|
filterSknResults = this.filterRecommedSknListByEs(userRecallRequest, filterSknList);
|
|
|
}
|
|
|
RECALL_NEW_LOGGER.info("recommedSknList size is [{}], filterSknListSize is[{}]", recommedSknList.size(), filterSknList.size());
|
|
|
return this.buildResults(userRecallRequest, filterSknList, maxReturnCount);
|
|
|
//3、构造结果
|
|
|
List<RecallRequestResponse> results = new ArrayList<>();
|
|
|
ParamQueryFilter paramQueryFilter = userRecallRequest.getParamQueryFilter();
|
|
|
results.addAll(this.buildResults(paramQueryFilter, userPersonalFactor.getRecommendSknList(), RecommendSknStrategy.class, filterSknResults, maxReturnCount));
|
|
|
results.addAll(this.buildResults(paramQueryFilter, userPersonalFactor.getRealTimeSimilarSknList(), RealTimeSimilarSknStrategy.class, filterSknResults, maxReturnCount));
|
|
|
return results;
|
|
|
} catch (Exception e) {
|
|
|
RECALL_NEW_LOGGER.error(e.getMessage(), e);
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<RecallRequestResponse> buildResults(ParamQueryFilter paramQueryFilter, List<Integer> filterSkns, Class<? extends IRecallSknStrategy> clazz, List<Integer> sknResults, int maxReturnCount) {
|
|
|
if (filterSkns == null || filterSkns.isEmpty() || sknResults == null || sknResults.isEmpty()) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
List<RecallRequestResponse> results = new ArrayList<>();
|
|
|
for (Integer skn : filterSkns) {
|
|
|
if (results.size() >= maxReturnCount) {
|
|
|
break;
|
|
|
}
|
|
|
if(!sknResults.contains(skn)){
|
|
|
continue;
|
|
|
}
|
|
|
RecallRequest recallRequest = new RecallRequest(paramQueryFilter, this.getRecallSknStrategy(clazz, skn));
|
|
|
RecallRequestResponse recallRequestResponse = new RecallRequestResponse(recallRequest);
|
|
|
recallRequestResponse.setResponse(new RecallResponse(1L, Arrays.asList(skn)), false);
|
|
|
results.add(recallRequestResponse);
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
private IRecallSknStrategy getRecallSknStrategy(Class<? extends IRecallSknStrategy> clazz, Integer skn) {
|
|
|
if (clazz.isAssignableFrom(RecommendSknStrategy.class)) {
|
|
|
return new RecommendSknStrategy(skn);
|
|
|
} else {
|
|
|
return new RealTimeSimilarSknStrategy(skn);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 从ehcahc或者redis中构造返回结果
|
|
|
*
|
...
|
...
|
@@ -198,27 +241,4 @@ public class SknRecallCacheBean { |
|
|
return results;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 将推荐的skn构造成召回对象
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
private List<RecallRequestResponse> buildResults(UserRecallRequest userRecallRequest, final List<Integer> recommedSknList, int maxReturnCount) {
|
|
|
List<RecallRequestResponse> results = new ArrayList<>();
|
|
|
if (recommedSknList == null || recommedSknList.isEmpty()) {
|
|
|
return results;
|
|
|
}
|
|
|
ParamQueryFilter paramQueryFilter = userRecallRequest.getParamQueryFilter();
|
|
|
for (Integer recommendSkn : recommedSknList) {
|
|
|
if (results.size() >= maxReturnCount) {
|
|
|
break;
|
|
|
}
|
|
|
RecallRequest recallRequest = new RecallRequest(paramQueryFilter, new RecommendSknStrategy(recommendSkn));
|
|
|
RecallRequestResponse recallRequestResponse = new RecallRequestResponse(recallRequest);
|
|
|
recallRequestResponse.setResponse(new RecallResponse(1L, Arrays.asList(recommendSkn)), false);
|
|
|
results.add(recallRequestResponse);
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|