Authored by hugufei

移包

... ... @@ -7,8 +7,8 @@ import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.recall.scene.beans.QueryRecallResultCacheBean;
import com.yoho.search.recall.scene.beans.QueryProductInfoCacheBean;
import com.yoho.search.recall.scene.beans.cache.QueryRecallResultCacheBean;
import com.yoho.search.recall.scene.beans.cache.QueryProductInfoCacheBean;
import com.yoho.search.recall.scene.beans.helper.SortBuilderHelper;
import com.yoho.search.recall.scene.models.*;
import com.yoho.search.recall.scene.beans.builder.RecallParamsBuilder;
... ...
package com.yoho.search.recall.scene.beans;
package com.yoho.search.recall.scene.beans.cache;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.base.utils.CollectionUtils;
... ...
package com.yoho.search.recall.scene.beans;
package com.yoho.search.recall.scene.beans.cache;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
... ...
package com.yoho.search.recall.scene.beans;
package com.yoho.search.recall.scene.beans.cache;
import com.yoho.search.base.utils.ISearchConstants;
... ...
package com.yoho.search.recall.scene.beans;
import com.yoho.search.recall.scene.beans.builder.BrandRecallRequestBuilder;
import com.yoho.search.recall.scene.beans.builder.CommonRecallRequestBuilder;
import com.yoho.search.recall.scene.beans.builder.SortPriceRecallRequestBuilder;
import com.yoho.search.recall.scene.beans.builder.RecallMergerResultBuilder;
import com.yoho.search.recall.scene.beans.builder.RecallResultBuilder;
import com.yoho.search.recall.scene.models.*;
import com.yoho.search.recall.scene.beans.persional.QueryUserPersionalFactorBean;
import com.yoho.search.recall.scene.models.CacheRecallRequestRecallResponse;
import com.yoho.search.recall.scene.models.CacheRecallParamsRecallResult;
import com.yoho.search.recall.scene.models.RecallRequest;
import com.yoho.search.recall.scene.models.RecallParams;
import com.yoho.search.recall.scene.models.PersionalFactor;
import com.yoho.search.recall.scene.models.RecallMergerResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class QueryRecallResultCacheBean extends AbstractCacheBean<RecallParams,RecallResult,CacheRecallParamsRecallResult> {
@Autowired
private CommonRecallRequestBuilder commonRequestBuilder;
@Autowired
private BrandRecallRequestBuilder brandRequestBuilder;
@Autowired
private SortPriceRecallRequestBuilder sortPriceRequestBuilder;
@Autowired
private BatchRecallCacheBean batchRecallCacheBean;
@Autowired
private QueryUserPersionalFactorBean queryUserPersionalFactorBean;
@Autowired
private RecallMergerResultBuilder recallMergerResultBuilder;
@Autowired
private RecallResultBuilder recallResultBuilder;
/**
* 召回入口
* @param recallParams
* @return
*/
public RecallResult queryRecallResult(RecallParams recallParams){
//1、构建请求
List<CacheRecallParamsRecallResult> requests = new ArrayList<>();
requests.add(new CacheRecallParamsRecallResult(recallParams));
//2、执行父类方法
this.bacthFillResponseWithCache(requests,false,1);
//3、判断
if(requests.size()==1 && requests.get(0).getResponse()!=null){
return requests.get(0).getResponse();
}
return null;
}
@Override
public Map<RecallParams, RecallResult> queryMissCacheRequestResults(List<CacheRecallParamsRecallResult> missCachseRequests) {
Map<RecallParams, RecallResult> results = new HashMap<>();
for (CacheRecallParamsRecallResult request: missCachseRequests) {
RecallResult response = this.doRealRecall(request.getRequest());
results.put(request.getRequest(),response);
}
return results;
}
/**
* 真正的召回入口
* @param param
* @return
*/
private RecallResult doRealRecall(RecallParams param) {
//1、获取个性化因子
PersionalFactor persionalFactor = queryUserPersionalFactorBean.queryPersionalFactor(param);
//2、构造请求
List<RecallRequest> batchRequests = this.buildBatchRequests(param, persionalFactor);
//3、批量召回
List<CacheRecallRequestRecallResponse> requestResponses = batchRecallCacheBean.batchRecallAndCache(batchRequests);
//4、获取skn列表[去重]
RecallMergerResult recallMergerResult = recallMergerResultBuilder.buildRecallResponseBatch(requestResponses);
//5、构造真实结果[排序,截取skn]
RecallResult recallResult = recallResultBuilder.builderRecallResult(recallMergerResult, param, persionalFactor);
return recallResult;
}
/**
* 批量构造请求
* @param param
* @param persionalFactor
* @return
*/
private List<RecallRequest> buildBatchRequests(RecallParams param, PersionalFactor persionalFactor) {
//1、构造召回请求
List<RecallRequest> allRequests = new ArrayList<>();
//2、构造非个性化的请求
List<RecallRequest> commonRequests = commonRequestBuilder.buildCommonRecallRequests(param.getParamQueryFilter(), param.getFirstProductSkns());
allRequests.addAll(commonRequests);
//4、构建个性化品牌的召回请求
List<RecallRequest> brandRequests = brandRequestBuilder.buildBrandRecallRequests(param.getParamQueryFilter(), persionalFactor.getBrandIds());
allRequests.addAll(brandRequests);
//5、构建个性化品牌的召回请求
List<RecallRequest> sortPriceRequests = sortPriceRequestBuilder.buildSortPriceRecallRequests(param.getParamQueryFilter(), persionalFactor.getSortPriceAreas());
allRequests.addAll(sortPriceRequests);
return allRequests;
}
}
package com.yoho.search.recall.scene.beans.cache;
import com.yoho.search.recall.scene.beans.builder.BrandRecallRequestBuilder;
import com.yoho.search.recall.scene.beans.builder.CommonRecallRequestBuilder;
import com.yoho.search.recall.scene.beans.builder.SortPriceRecallRequestBuilder;
import com.yoho.search.recall.scene.beans.builder.RecallMergerResultBuilder;
import com.yoho.search.recall.scene.beans.builder.RecallResultBuilder;
import com.yoho.search.recall.scene.models.*;
import com.yoho.search.recall.scene.beans.persional.QueryUserPersionalFactorBean;
import com.yoho.search.recall.scene.models.CacheRecallRequestRecallResponse;
import com.yoho.search.recall.scene.models.CacheRecallParamsRecallResult;
import com.yoho.search.recall.scene.models.RecallRequest;
import com.yoho.search.recall.scene.models.RecallParams;
import com.yoho.search.recall.scene.models.PersionalFactor;
import com.yoho.search.recall.scene.models.RecallMergerResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class QueryRecallResultCacheBean extends AbstractCacheBean<RecallParams,RecallResult,CacheRecallParamsRecallResult> {
@Autowired
private CommonRecallRequestBuilder commonRequestBuilder;
@Autowired
private BrandRecallRequestBuilder brandRequestBuilder;
@Autowired
private SortPriceRecallRequestBuilder sortPriceRequestBuilder;
@Autowired
private BatchRecallCacheBean batchRecallCacheBean;
@Autowired
private QueryUserPersionalFactorBean queryUserPersionalFactorBean;
@Autowired
private RecallMergerResultBuilder recallMergerResultBuilder;
@Autowired
private RecallResultBuilder recallResultBuilder;
/**
* 召回入口
* @param recallParams
* @return
*/
public RecallResult queryRecallResult(RecallParams recallParams){
//1、构建请求
List<CacheRecallParamsRecallResult> requests = new ArrayList<>();
requests.add(new CacheRecallParamsRecallResult(recallParams));
//2、执行父类方法
this.bacthFillResponseWithCache(requests,false,1);
//3、判断
if(requests.size()==1 && requests.get(0).getResponse()!=null){
return requests.get(0).getResponse();
}
return null;
}
@Override
public Map<RecallParams, RecallResult> queryMissCacheRequestResults(List<CacheRecallParamsRecallResult> missCachseRequests) {
Map<RecallParams, RecallResult> results = new HashMap<>();
for (CacheRecallParamsRecallResult request: missCachseRequests) {
RecallResult response = this.doRealRecall(request.getRequest());
results.put(request.getRequest(),response);
}
return results;
}
/**
* 真正的召回入口
* @param param
* @return
*/
private RecallResult doRealRecall(RecallParams param) {
//1、获取个性化因子
PersionalFactor persionalFactor = queryUserPersionalFactorBean.queryPersionalFactor(param);
//2、构造请求
List<RecallRequest> batchRequests = this.buildBatchRequests(param, persionalFactor);
//3、批量召回
List<CacheRecallRequestRecallResponse> requestResponses = batchRecallCacheBean.batchRecallAndCache(batchRequests);
//4、获取skn列表[去重]
RecallMergerResult recallMergerResult = recallMergerResultBuilder.buildRecallResponseBatch(requestResponses);
//5、构造真实结果[排序,截取skn]
RecallResult recallResult = recallResultBuilder.builderRecallResult(recallMergerResult, param, persionalFactor);
return recallResult;
}
/**
* 批量构造请求
* @param param
* @param persionalFactor
* @return
*/
private List<RecallRequest> buildBatchRequests(RecallParams param, PersionalFactor persionalFactor) {
//1、构造召回请求
List<RecallRequest> allRequests = new ArrayList<>();
//2、构造非个性化的请求
List<RecallRequest> commonRequests = commonRequestBuilder.buildCommonRecallRequests(param.getParamQueryFilter(), param.getFirstProductSkns());
allRequests.addAll(commonRequests);
//4、构建个性化品牌的召回请求
List<RecallRequest> brandRequests = brandRequestBuilder.buildBrandRecallRequests(param.getParamQueryFilter(), persionalFactor.getBrandIds());
allRequests.addAll(brandRequests);
//5、构建个性化品牌的召回请求
List<RecallRequest> sortPriceRequests = sortPriceRequestBuilder.buildSortPriceRecallRequests(param.getParamQueryFilter(), persionalFactor.getSortPriceAreas());
allRequests.addAll(sortPriceRequests);
return allRequests;
}
}
... ...