|
|
package com.yoho.search.recall.scene.beans.cache;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.yoho.search.base.utils.CollectionUtils;
|
|
|
import com.yoho.search.core.personalized.models.SortBrand;
|
|
|
import com.yoho.search.models.SearchApiResult;
|
|
|
import com.yoho.search.recall.scene.beans.builder.*;
|
|
|
import com.yoho.search.recall.scene.beans.persional.QueryUserPersionalFactorBean;
|
|
|
import com.yoho.search.recall.scene.beans.strategy.SortBrandType;
|
|
|
import com.yoho.search.recall.scene.beans.strategy.impls.RecommendSknStrategy;
|
|
|
import com.yoho.search.recall.scene.constants.SknCountConstants;
|
|
|
import com.yoho.search.recall.scene.models.common.RecallMergerResult;
|
|
|
import com.yoho.search.recall.scene.models.personal.UserPersonalFactor;
|
|
|
import com.yoho.search.recall.scene.models.req.*;
|
|
|
import com.yoho.search.service.base.SearchDynamicConfigService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
...
|
...
|
@@ -43,7 +38,7 @@ public class UserRecallCacheBean extends AbstractCacheBean<UserRecallRequest, Us |
|
|
@Autowired
|
|
|
private UserRecallResponseBuilder userRecallResponseBuilder;
|
|
|
|
|
|
private ExecutorService recallExecutorService = Executors.newFixedThreadPool(30);
|
|
|
private ExecutorService recallExecutorService = Executors.newFixedThreadPool(50);
|
|
|
|
|
|
/**
|
|
|
* 召回入口
|
...
|
...
|
@@ -105,7 +100,7 @@ public class UserRecallCacheBean extends AbstractCacheBean<UserRecallRequest, Us |
|
|
private List<RecallRequestResponse> batchRecall(UserRecallRequest userRecallRequest, UserPersonalFactor userPersonalFactor) {
|
|
|
|
|
|
//1、处理实时推荐SKN的召回
|
|
|
CompletableFuture<List<RecallRequestResponse>> recallBySknListCompletableFuture = this.doRecallBySknList(userRecallRequest, userPersonalFactor);
|
|
|
CompletableFuture<List<RecallRequestResponse>> sknListCompletableFuture = this.doRecallSknList(userRecallRequest, userPersonalFactor);
|
|
|
|
|
|
//2、处理通用召回
|
|
|
CompletableFuture<List<RecallRequestResponse>> commonCompletableFuture = this.doRecallCommon(userRecallRequest, userPersonalFactor);
|
...
|
...
|
@@ -113,22 +108,26 @@ public class UserRecallCacheBean extends AbstractCacheBean<UserRecallRequest, Us |
|
|
//3、处理实时推荐的品类品牌的召回
|
|
|
CompletableFuture<List<RecallRequestResponse>> realTimeSortBrandCompletableFuture = this.doRecallRealTimeSortBrand(userRecallRequest, userPersonalFactor);
|
|
|
|
|
|
//4、处理基于向量生成的品类品牌的召回
|
|
|
CompletableFuture<List<RecallRequestResponse>> vectorSortBrandCompletableFuture = this.doRecallVectorSortBrand(userRecallRequest, userPersonalFactor);
|
|
|
|
|
|
//5、处理RNN预测的品类品牌的召回
|
|
|
//4、处理预测的品类品牌的召回
|
|
|
CompletableFuture<List<RecallRequestResponse>> forecastSortBrandCompletableFuture = this.doRecallPredictSortBrand(userRecallRequest, userPersonalFactor);
|
|
|
|
|
|
//6、构造最终返回结果投入额
|
|
|
//5、处理基于RNN向量生成的品类品牌的召回
|
|
|
CompletableFuture<List<RecallRequestResponse>> vectorRnnSortBrandCompletableFuture = this.doRecallVectorRnnSortBrand(userRecallRequest, userPersonalFactor);
|
|
|
|
|
|
//7、处理基于W2V向量生成的品类品牌的召回
|
|
|
CompletableFuture<List<RecallRequestResponse>> vectorW2vSortBrandCompletableFuture = this.doRecallVectorW2vSortBrand(userRecallRequest, userPersonalFactor);
|
|
|
|
|
|
//8、构造最终返回结果投入额
|
|
|
List<RecallRequestResponse> batchRequestResults = new ArrayList<>();
|
|
|
|
|
|
batchRequestResults.addAll(this.getResultFromCompletableFuture(recallBySknListCompletableFuture));//按skn召回放在第一个,不然merger的时候可能会无序
|
|
|
batchRequestResults.addAll(this.getResultFromCompletableFuture(sknListCompletableFuture));//按skn召回放在第一个,不然merger的时候可能会无序
|
|
|
batchRequestResults.addAll(this.getResultFromCompletableFuture(commonCompletableFuture));
|
|
|
batchRequestResults.addAll(this.getResultFromCompletableFuture(realTimeSortBrandCompletableFuture));
|
|
|
batchRequestResults.addAll(this.getResultFromCompletableFuture(vectorSortBrandCompletableFuture));
|
|
|
batchRequestResults.addAll(this.getResultFromCompletableFuture(forecastSortBrandCompletableFuture));
|
|
|
batchRequestResults.addAll(this.getResultFromCompletableFuture(vectorRnnSortBrandCompletableFuture));
|
|
|
batchRequestResults.addAll(this.getResultFromCompletableFuture(vectorW2vSortBrandCompletableFuture));
|
|
|
|
|
|
//6、日志打印
|
|
|
//9、日志打印
|
|
|
if (userRecallRequest.openDetailLog()) {
|
|
|
for (RecallRequestResponse recallRequestResponse : batchRequestResults) {
|
|
|
RecallRequest recallRequest = recallRequestResponse.getRequest();
|
...
|
...
|
@@ -174,12 +173,11 @@ public class UserRecallCacheBean extends AbstractCacheBean<UserRecallRequest, Us |
|
|
* @param userPersonalFactor
|
|
|
* @return
|
|
|
*/
|
|
|
private CompletableFuture<List<RecallRequestResponse>> doRecallBySknList(UserRecallRequest userRecallRequest, UserPersonalFactor userPersonalFactor) {
|
|
|
private CompletableFuture<List<RecallRequestResponse>> doRecallSknList(UserRecallRequest userRecallRequest, UserPersonalFactor userPersonalFactor) {
|
|
|
return CompletableFuture.supplyAsync(() -> {
|
|
|
long begin = System.currentTimeMillis();
|
|
|
int recommendSknCount = userPersonalFactor.getRecommendSknList() == null ? 0 : userPersonalFactor.getRecommendSknList().size();
|
|
|
List<RecallRequestResponse> recommendSknRequestResponses = sknRecallCacheBean.batchRecallBySknList(userRecallRequest, userPersonalFactor, SknCountConstants.REC_SKN_COUNT);
|
|
|
RECALL_NEW_LOGGER.info("UserRecallCacheBean[2.2]-doRecallRecommendSkn,recommendSknCount is [{}],cost is [{}]", recommendSknCount, System.currentTimeMillis() - begin);
|
|
|
RECALL_NEW_LOGGER.info("UserRecallCacheBean[2.2]-doRecallRecommendSkn,recommendSknCount is [{}],cost is [{}]", recommendSknRequestResponses.size(), System.currentTimeMillis() - begin);
|
|
|
return recommendSknRequestResponses;
|
|
|
}, recallExecutorService);
|
|
|
}
|
...
|
...
|
@@ -202,36 +200,54 @@ public class UserRecallCacheBean extends AbstractCacheBean<UserRecallRequest, Us |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 执行向量【品牌+品类】的召回
|
|
|
* 执行预测【品牌+品类】的召回
|
|
|
*
|
|
|
* @param userRecallRequest
|
|
|
* @param userPersonalFactor
|
|
|
* @return
|
|
|
*/
|
|
|
private CompletableFuture<List<RecallRequestResponse>> doRecallPredictSortBrand(UserRecallRequest userRecallRequest, UserPersonalFactor userPersonalFactor) {
|
|
|
return CompletableFuture.supplyAsync(() -> {
|
|
|
long begin = System.currentTimeMillis();
|
|
|
List<RecallRequest> forecastSortBrandRequests = sortBrandRecallRequestBuilder.buildSortBrandRecallRequests(userRecallRequest.getUid(), userRecallRequest.getParamQueryFilter(), userPersonalFactor.getPredictSortBrandList(), SortBrandType.PRED_SORT_BRAND, SknCountConstants.PRED_SORT_BRAND_SKN_COUNT);
|
|
|
List<RecallRequestResponse> forecastSortBrandRequestsResponses = batchRecallCacheBean.batchRecallAndCache(forecastSortBrandRequests);
|
|
|
RECALL_NEW_LOGGER.info("UserRecallCacheBean[2.4]-doRecallPredictSortBrand,requestCount is [{}], cost is [{}]", forecastSortBrandRequests.size(), System.currentTimeMillis() - begin);
|
|
|
return forecastSortBrandRequestsResponses;
|
|
|
}, recallExecutorService);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 执行RNN向量【品牌+品类】的召回
|
|
|
*
|
|
|
* @param userRecallRequest
|
|
|
* @param userPersonalFactor
|
|
|
* @return
|
|
|
*/
|
|
|
private CompletableFuture<List<RecallRequestResponse>> doRecallVectorSortBrand(UserRecallRequest userRecallRequest, UserPersonalFactor userPersonalFactor) {
|
|
|
private CompletableFuture<List<RecallRequestResponse>> doRecallVectorRnnSortBrand(UserRecallRequest userRecallRequest, UserPersonalFactor userPersonalFactor) {
|
|
|
return CompletableFuture.supplyAsync(() -> {
|
|
|
long begin = System.currentTimeMillis();
|
|
|
List<RecallRequest> vecortSortBrandRequests = sortBrandRecallRequestBuilder.buildSortBrandRecallRequests(userRecallRequest.getUid(), userRecallRequest.getParamQueryFilter(), userPersonalFactor.getVectorSortBrandList(), SortBrandType.VEC_SORT_BRAND, SknCountConstants.VEC_SORT_BRAND_SKN_COUNT);
|
|
|
List<RecallRequestResponse> vecSortBrandRequestsResponses = batchRecallCacheBean.batchRecallAndCache(vecortSortBrandRequests);
|
|
|
RECALL_NEW_LOGGER.info("UserRecallCacheBean[2.4]-doRecallVectorSortBrand,requestCount is [{}], cost is [{}]", vecortSortBrandRequests.size(), System.currentTimeMillis() - begin);
|
|
|
List<RecallRequest> vectorRnnSortBrandRequests = sortBrandRecallRequestBuilder.buildSortBrandRecallRequests(userRecallRequest.getUid(), userRecallRequest.getParamQueryFilter(), userPersonalFactor.getVectorRnnSortBrandList(), SortBrandType.VEC_RNN_SORT_BRAND, SknCountConstants.VEC_SORT_BRAND_SKN_COUNT);
|
|
|
List<RecallRequestResponse> vecSortBrandRequestsResponses = batchRecallCacheBean.batchRecallAndCache(vectorRnnSortBrandRequests);
|
|
|
RECALL_NEW_LOGGER.info("UserRecallCacheBean[2.5]-doRecallVectorRnnSortBrand,requestCount is [{}], cost is [{}]", vectorRnnSortBrandRequests.size(), System.currentTimeMillis() - begin);
|
|
|
return vecSortBrandRequestsResponses;
|
|
|
}, recallExecutorService);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 执行预测【品牌+品类】的召回
|
|
|
* 执行w2v向量【品牌+品类】的召回
|
|
|
*
|
|
|
* @param userRecallRequest
|
|
|
* @param userPersonalFactor
|
|
|
* @return
|
|
|
*/
|
|
|
private CompletableFuture<List<RecallRequestResponse>> doRecallPredictSortBrand(UserRecallRequest userRecallRequest, UserPersonalFactor userPersonalFactor) {
|
|
|
private CompletableFuture<List<RecallRequestResponse>> doRecallVectorW2vSortBrand(UserRecallRequest userRecallRequest, UserPersonalFactor userPersonalFactor) {
|
|
|
return CompletableFuture.supplyAsync(() -> {
|
|
|
long begin = System.currentTimeMillis();
|
|
|
List<RecallRequest> forecastSortBrandRequests = sortBrandRecallRequestBuilder.buildSortBrandRecallRequests(userRecallRequest.getUid(), userRecallRequest.getParamQueryFilter(), userPersonalFactor.getPredictSortBrandList(), SortBrandType.PRED_SORT_BRAND, SknCountConstants.PRED_SORT_BRAND_SKN_COUNT);
|
|
|
List<RecallRequestResponse> forecastSortBrandRequestsResponses = batchRecallCacheBean.batchRecallAndCache(forecastSortBrandRequests);
|
|
|
RECALL_NEW_LOGGER.info("UserRecallCacheBean[2.5]-doRecallPredictSortBrand,requestCount is [{}], cost is [{}]", forecastSortBrandRequests.size(), System.currentTimeMillis() - begin);
|
|
|
return forecastSortBrandRequestsResponses;
|
|
|
List<RecallRequest> vectorW2vSortBrandRequests = sortBrandRecallRequestBuilder.buildSortBrandRecallRequests(userRecallRequest.getUid(), userRecallRequest.getParamQueryFilter(), userPersonalFactor.getVectorW2vSortBrandList(), SortBrandType.VEC_W2V_SORT_BRAND, SknCountConstants.VEC_SORT_BRAND_SKN_COUNT);
|
|
|
List<RecallRequestResponse> vecSortBrandRequestsResponses = batchRecallCacheBean.batchRecallAndCache(vectorW2vSortBrandRequests);
|
|
|
RECALL_NEW_LOGGER.info("UserRecallCacheBean[2.6]-doRecallVectorW2vSortBrand,requestCount is [{}], cost is [{}]", vectorW2vSortBrandRequests.size(), System.currentTimeMillis() - begin);
|
|
|
return vecSortBrandRequestsResponses;
|
|
|
}, recallExecutorService);
|
|
|
}
|
|
|
|
...
|
...
|
|