|
|
package com.yoho.search.recall.scene.beans.persional;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.yoho.search.base.utils.CollectionUtils;
|
|
|
import com.yoho.search.core.personalized.models.SortBrand;
|
|
|
import com.yoho.search.core.personalized.models.SortPriceAreas;
|
|
|
import com.yoho.search.core.personalized.models.UserPersonalFactorRspNew;
|
|
|
import com.yoho.search.recall.scene.models.personal.PageBrandSorts;
|
|
|
import com.yoho.search.recall.scene.models.personal.PagePersonalFactor;
|
|
|
import com.yoho.search.recall.scene.models.personal.SortBrandVectorScore;
|
|
|
import com.yoho.search.recall.scene.models.personal.UserPersonalFactor;
|
|
|
import com.yoho.search.recall.scene.models.req.UserRecallRequest;
|
|
|
import com.yoho.search.service.base.SearchDynamicConfigService;
|
...
|
...
|
@@ -30,6 +29,8 @@ public class QueryUserPersionalFactorBean { |
|
|
private UserPersionalFactorComponent userComponent;
|
|
|
@Autowired
|
|
|
private SearchDynamicConfigService searchDynamicConfigService;
|
|
|
@Autowired
|
|
|
private SortBrandVectorComponent sortBrandVectorComponent;
|
|
|
|
|
|
/**
|
|
|
* 获取个性化因子
|
...
|
...
|
@@ -51,7 +52,7 @@ public class QueryUserPersionalFactorBean { |
|
|
long begin = System.currentTimeMillis();
|
|
|
PagePersonalFactor pageFactor = pageComponent.queryPagePersionalFactor(userRecallRequest.getParamQueryFilter());
|
|
|
long cost = System.currentTimeMillis() - begin;
|
|
|
RECALL_NEW_LOGGER.info("QueryUserPersionalFactorBean[1]:queryPageFactor. uid is[{}],udid is[{}], cost is[{}],size is[{}] ", uid, udid, cost, pageFactor == null ? "null" : pageFactor.pageBrandSortsSize());
|
|
|
RECALL_NEW_LOGGER.info("QueryUserPersionalFactorBean[1]:queryPageFactor. uid is[{}],udid is[{}], cost is[{}],size is[{}] ", uid, udid, cost, pageFactor == null ? "null" : pageFactor.sortBrandListSize());
|
|
|
|
|
|
//2、获取用户的个性化因子
|
|
|
begin = System.currentTimeMillis();
|
...
|
...
|
@@ -63,14 +64,16 @@ public class QueryUserPersionalFactorBean { |
|
|
if (!openDetailLog) {
|
|
|
RECALL_NEW_LOGGER.info("QueryUserPersionalFactorBean[2]:queryUserFactor. uid is[{}],udid is[{}], cost is[{}], forecastSortBrandSize is[{}],realTimeSortBrandSize is[{}], recommendSknSize is[{}] ", uid, udid, cost, forecastSortBrandSize, realTimeSortBrandSize, recommendSknSize);
|
|
|
} else {
|
|
|
RECALL_NEW_LOGGER.info("QueryUserPersionalFactorBean[2]:queryUserFactor. uid is[{}],udid is[{}], cost is[{}], forecastSortBrandSize is[{}],realTimeSortBrandSize is[{}], recommendSknSize is[{}],misortIds is[{}],userFactor is[{}] ", uid, udid, cost, forecastSortBrandSize, realTimeSortBrandSize, recommendSknSize, pageFactor.getMisortIds(),JSON.toJSONString(userFactor));
|
|
|
RECALL_NEW_LOGGER.info("QueryUserPersionalFactorBean[2]:queryUserFactor. uid is[{}],udid is[{}], cost is[{}], forecastSortBrandSize is[{}],realTimeSortBrandSize is[{}], recommendSknSize is[{}],misortIds is[{}],userFactor is[{}] ", uid, udid, cost, forecastSortBrandSize, realTimeSortBrandSize, recommendSknSize, pageFactor.getMisortIds(), JSON.toJSONString(userFactor));
|
|
|
}
|
|
|
//3、构造结果
|
|
|
begin = System.currentTimeMillis();
|
|
|
UserPersonalFactor userPersonalFactor = this.buildUserPersonalFactor(pageFactor, userFactor);
|
|
|
cost = System.currentTimeMillis() - begin;
|
|
|
if (!openDetailLog) {
|
|
|
RECALL_NEW_LOGGER.info("QueryUserPersionalFactorBean[3]:after join. uid is[{}],udid is[{}], forecastSortBrand size is[{}], realTimeSortBrand size is[{}], sortPriceAreas size is [{}] ", uid, udid, userPersonalFactor.getForecastSortBrandListSize(), userPersonalFactor.getRealTimeSortBrandListSize(), userPersonalFactor.getSortPriceAreasListSize());
|
|
|
RECALL_NEW_LOGGER.info("QueryUserPersionalFactorBean[3]:buildUserPersonalFactor.cost is[{}ms], uid is[{}],udid is[{}], forecastSortBrand size is[{}], realTimeSortBrand size is[{}], vectorSortBrand size is[{}], sortPriceAreas size is [{}] ",cost, uid, udid, userPersonalFactor.getForecastSortBrandListSize(), userPersonalFactor.getRealTimeSortBrandListSize(),userPersonalFactor.getVectorSortBrandListSize(), userPersonalFactor.getSortPriceAreasListSize());
|
|
|
} else {
|
|
|
RECALL_NEW_LOGGER.info("QueryUserPersionalFactorBean[3]:after join. uid is[{}],udid is[{}], forecastSortBrand size is[{}], realTimeSortBrand size is[{}], sortPriceAreas size is [{}], results is [{}] ", uid, udid, userPersonalFactor.getForecastSortBrandListSize(), userPersonalFactor.getRealTimeSortBrandListSize(), userPersonalFactor.getSortPriceAreasListSize(), JSON.toJSONString(userPersonalFactor));
|
|
|
RECALL_NEW_LOGGER.info("QueryUserPersionalFactorBean[3]:buildUserPersonalFactor.cost is[{}ms], uid is[{}],udid is[{}], forecastSortBrand size is[{}], realTimeSortBrand size is[{}], vectorSortBrand size is[{}], sortPriceAreas size is [{}], results is [{}] ",cost, uid, udid, userPersonalFactor.getForecastSortBrandListSize(), userPersonalFactor.getRealTimeSortBrandListSize(),userPersonalFactor.getVectorSortBrandListSize(), userPersonalFactor.getSortPriceAreasListSize(), JSON.toJSONString(userPersonalFactor));
|
|
|
}
|
|
|
return userPersonalFactor;
|
|
|
} catch (Exception e) {
|
...
|
...
|
@@ -80,27 +83,40 @@ public class QueryUserPersionalFactorBean { |
|
|
}
|
|
|
|
|
|
private UserPersonalFactor buildUserPersonalFactor(PagePersonalFactor pageFactor, UserPersonalFactorRspNew userFactor) {
|
|
|
//1、构造页面中的品牌品类map
|
|
|
Map<Integer, List<Integer>> pageBrand2MiSortIdsMap = this.getPageBrand2MiSortIdsMap(pageFactor);
|
|
|
//1、获取页面中存在的所有的key
|
|
|
Set<String> pageSortBrandKeys = new HashSet<>();
|
|
|
Set<String> filterSortBrandKeys = new HashSet<>();
|
|
|
for (SortBrand pageSortBrand : pageFactor.getSortBrandList()) {
|
|
|
pageSortBrandKeys.add(pageSortBrand.key());
|
|
|
}
|
|
|
//2、构造实时【品类+品牌】
|
|
|
int maxRealTimeSortBrandCount = searchDynamicConfigService.maxRealTimeSortBrandCount();
|
|
|
List<SortBrand> realTimeSortBrandList = this.getSortBrandListWithSort(null, pageBrand2MiSortIdsMap, userFactor.getRealTimeSortBrandList(), maxRealTimeSortBrandCount);
|
|
|
Set<String> realTimeSortBrandKeys = new HashSet<>();
|
|
|
for (SortBrand realTimeSortBrand : realTimeSortBrandList) {
|
|
|
realTimeSortBrandKeys.add(realTimeSortBrand.key());
|
|
|
List<SortBrand> realTimeSortBrandList = this.getSortBrandListWithSort(pageSortBrandKeys,filterSortBrandKeys,userFactor.getRealTimeSortBrandList(), maxRealTimeSortBrandCount);
|
|
|
for (SortBrand existSortBrand : realTimeSortBrandList) {
|
|
|
filterSortBrandKeys.add(existSortBrand.key());
|
|
|
}
|
|
|
//3、构造预测的【品牌+品牌】,去除实时的品类和品牌
|
|
|
//3、构造基于向量的【品牌+品牌】,去除实时的品类和品牌
|
|
|
int maxVectorSortBrandCount = searchDynamicConfigService.maxVectorSortBrandCount();
|
|
|
List<SortBrand> vectorSortBrandList = sortBrandVectorComponent.queryVectorSortBrandList(pageFactor.getSortBrandList(),filterSortBrandKeys,userFactor.getSortBrandVector(), maxVectorSortBrandCount);
|
|
|
for (SortBrand existSortBrand : vectorSortBrandList) {
|
|
|
filterSortBrandKeys.add(existSortBrand.key());
|
|
|
}
|
|
|
//4、构造预测的【品牌+品牌】,去除实时的品类和品牌
|
|
|
int maxForecastSortBrandCount = searchDynamicConfigService.maxForecastSortBrandCount();
|
|
|
int maxJoinSortBrandCount = searchDynamicConfigService.maxJoinSortBrandCount();
|
|
|
int count = Math.max(maxForecastSortBrandCount, maxJoinSortBrandCount - realTimeSortBrandList.size());
|
|
|
List<SortBrand> forecastSortBrandList = this.getSortBrandListWithSort(realTimeSortBrandKeys, pageBrand2MiSortIdsMap, userFactor.getSortBrandList(), count);
|
|
|
//4、构造品类价格带
|
|
|
List<SortBrand> forecastSortBrandList = this.getSortBrandListWithSort(pageSortBrandKeys,filterSortBrandKeys,userFactor.getSortBrandList(), maxForecastSortBrandCount);
|
|
|
for (SortBrand existSortBrand : forecastSortBrandList) {
|
|
|
filterSortBrandKeys.add(existSortBrand.key());
|
|
|
}
|
|
|
|
|
|
//5、构造品类价格带
|
|
|
List<SortPriceAreas> sortPriceAreasList = this.getSortPriceAreasListWithSort(userFactor, pageFactor);
|
|
|
//5、构造推荐的skn列表
|
|
|
|
|
|
//6、构造推荐的skn列表
|
|
|
List<Integer> recommendSknList = userFactor.getRecommendSknList();
|
|
|
List<Integer> realTimeSimilarSknList = this.queryRealTimeSimilarSknList(userFactor);
|
|
|
//6、返回最终结果
|
|
|
return new UserPersonalFactor(realTimeSortBrandList, forecastSortBrandList, sortPriceAreasList, recommendSknList, realTimeSimilarSknList, userFactor.getVector());
|
|
|
|
|
|
//7、返回最终结果
|
|
|
return new UserPersonalFactor(realTimeSortBrandList, forecastSortBrandList, vectorSortBrandList, sortPriceAreasList, recommendSknList, realTimeSimilarSknList, userFactor.getVector());
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -127,30 +143,13 @@ public class QueryUserPersionalFactorBean { |
|
|
return results;
|
|
|
}
|
|
|
|
|
|
private Map<Integer, List<Integer>> getPageBrand2MiSortIdsMap(PagePersonalFactor pageFactor) {
|
|
|
if (pageFactor == null || pageFactor.getBrandSortsList() == null) {
|
|
|
return new HashMap<>();
|
|
|
}
|
|
|
//1、构造brand2MiSortIdsMap
|
|
|
List<PageBrandSorts> brandSortsList = pageFactor.getBrandSortsList();
|
|
|
Map<Integer, List<Integer>> brand2MiSortIdsMap = new HashMap<>();
|
|
|
for (PageBrandSorts pageBrandSorts : brandSortsList) {
|
|
|
brand2MiSortIdsMap.put(pageBrandSorts.getBrandId(), pageBrandSorts.getMisorts());
|
|
|
}
|
|
|
return brand2MiSortIdsMap;
|
|
|
}
|
|
|
|
|
|
private List<SortBrand> getSortBrandListWithSort(Set<String> filterSortBrandKeys, Map<Integer, List<Integer>> brand2MiSortIdsMap, List<SortBrand> userSortBrands, int maxCount) {
|
|
|
private List<SortBrand> getSortBrandListWithSort(Set<String> pageSortBrandKeys,Set<String> filterSortBrandKeys,List<SortBrand> userSortBrands, int maxCount) {
|
|
|
List<SortBrand> results = new ArrayList<>();
|
|
|
if (brand2MiSortIdsMap == null || brand2MiSortIdsMap.isEmpty() || userSortBrands == null || userSortBrands.isEmpty()) {
|
|
|
if (pageSortBrandKeys == null || pageSortBrandKeys.isEmpty() || userSortBrands == null || userSortBrands.isEmpty()) {
|
|
|
return results;
|
|
|
}
|
|
|
for (SortBrand sortBrand : userSortBrands) {
|
|
|
if (!brand2MiSortIdsMap.containsKey(sortBrand.getBrandId())) {
|
|
|
continue;
|
|
|
}
|
|
|
List<Integer> miSortIds = brand2MiSortIdsMap.get(sortBrand.getBrandId());
|
|
|
if (miSortIds == null || !miSortIds.contains(sortBrand.getMisort())) {
|
|
|
if (!pageSortBrandKeys.contains(sortBrand.key())) {
|
|
|
continue;
|
|
|
}
|
|
|
if (filterSortBrandKeys != null && filterSortBrandKeys.contains(sortBrand.key())) {
|
...
|
...
|
@@ -164,6 +163,7 @@ public class QueryUserPersionalFactorBean { |
|
|
return results;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 【品类+价格带】
|
|
|
*
|
...
|
...
|
|