Authored by hugufei

品牌品类召回时,实时的和预测的需要去重

... ... @@ -14,10 +14,7 @@ import org.slf4j.LoggerFactory;
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;
import java.util.*;
@Component
public class UserRecallRequestResponseCacheBean extends AbstractCacheBean<UserRecallRequest,UserRecallResponse,UserRecallRequestResponse> {
... ... @@ -121,18 +118,31 @@ public class UserRecallRequestResponseCacheBean extends AbstractCacheBean<UserRe
private List<RecallRequest> buildBatchRequests(UserRecallRequest param,UserPersonalFactor userPersonalFactor) {
//1、构造召回请求
List<RecallRequest> recallRequests = new ArrayList<>();
//2、构造非个性化的请求
List<RecallRequest> commonRequests = commonRequestBuilder.buildCommonRecallRequests(param.getParamQueryFilter(), param.getFirstProductSkns());
recallRequests.addAll(commonRequests);
//3、构【品类+品牌】的实时点击的召回请求
List<SortBrand> sortBrands = new ArrayList<>();
sortBrands.addAll(userPersonalFactor.getRealTimeSortBrandList());
sortBrands.addAll(userPersonalFactor.getForecastSortBrandList());
//TODO 去重
//3、构【品类+品牌】的实时点击的召回请求-去重
List<SortBrand> tempSortBrands = new ArrayList<>();
tempSortBrands.addAll(userPersonalFactor.getRealTimeSortBrandList());
tempSortBrands.addAll(userPersonalFactor.getForecastSortBrandList());
//4、去重
Set<String> existKeys = new HashSet<>();
List<SortBrand> results = new ArrayList<>();
for (SortBrand sortBrand : tempSortBrands){
String key = sortBrand.getMisort() + "_" + sortBrand.getBrandId();
if(existKeys.contains(key)){
continue;
}
results.add(sortBrand);
existKeys.add(key);
}
//5、数量控制
int maxCount = searchDynamicConfigService.maxJoinSortBrandCount();
sortBrands = CollectionUtils.safeSubList(sortBrands,0,maxCount);
List<RecallRequest> sortBrandRequests = sortBrandRecallRequestBuilder.buildSortBrandRecallRequests(param.getParamQueryFilter(), sortBrands);
results = CollectionUtils.safeSubList(results,0,maxCount);
List<RecallRequest> sortBrandRequests = sortBrandRecallRequestBuilder.buildSortBrandRecallRequests(param.getParamQueryFilter(), results);
recallRequests.addAll(sortBrandRequests);
return recallRequests;
}
... ...