...
|
...
|
@@ -3,6 +3,7 @@ package com.yoho.search.service.scene.activity; |
|
|
import com.yoho.search.base.helper.RnnVectorCalculator;
|
|
|
import com.yoho.search.base.helper.Word2VectorCalculator;
|
|
|
import com.yoho.search.base.utils.CollectionUtils;
|
|
|
import com.yoho.search.core.personalized.models.SortBrand;
|
|
|
import com.yoho.search.core.personalized.models.UserPersonalFactorRspNew;
|
|
|
import com.yoho.search.models.SearchApiResult;
|
|
|
import com.yoho.search.recall.beans.persional.UserPersionalFactorComponent;
|
...
|
...
|
@@ -10,13 +11,17 @@ import com.yoho.search.recall.beans.vector.BrandVectorCacheBean; |
|
|
import com.yoho.search.service.base.SearchRequestParams;
|
|
|
import com.yoho.search.service.base.index.ShopsIndexBaseService;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class ActivityService{
|
|
|
public class ActivityService {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ActivityService.class);
|
|
|
|
|
|
@Autowired
|
|
|
private ActivityShopBrandListService activityShopBrandListService;
|
...
|
...
|
@@ -38,32 +43,38 @@ public class ActivityService{ |
|
|
String udid = MapUtils.getString(paramMap, "udid", "");
|
|
|
UserPersonalFactorRspNew userPersonalFactorRspNew = userComponent.queryUserPersionalFactor(uid, udid, null);
|
|
|
//3、按相关性聚合品牌
|
|
|
List<Integer> shopIds = this.buildShopIds(shopBrandList,userPersonalFactorRspNew);
|
|
|
List<Integer> shopIds = this.buildShopIds(shopBrandList, userPersonalFactorRspNew);
|
|
|
//4、查询店铺
|
|
|
List<Map<String, Object>> shopsList = shopsIndexBaseService.getShopListByIdsWithSortAndStatus(shopIds);
|
|
|
//5、数量截取
|
|
|
int viewNum = MapUtils.getIntValue(paramMap, SearchRequestParams.PARAM_SEARCH_VIEWNUM, 10);
|
|
|
shopsList = CollectionUtils.safeSubList(shopsList,0,viewNum);
|
|
|
shopsList = CollectionUtils.safeSubList(shopsList, 0, viewNum);
|
|
|
//6、构造返回结果
|
|
|
return this.buildShopList(200, "success",shopsList);
|
|
|
return this.buildShopList(200, "success", shopsList);
|
|
|
}
|
|
|
|
|
|
private List<Integer> buildShopIds(List<ActivityShopBrandList.ShopBrand> shopBrandList, UserPersonalFactorRspNew userPersonalFactorRspNew){
|
|
|
private List<Integer> buildShopIds(List<ActivityShopBrandList.ShopBrand> shopBrandList, UserPersonalFactorRspNew userPersonalFactorRspNew) {
|
|
|
//1、计算店铺得分
|
|
|
List<Double> brandVector = userPersonalFactorRspNew.getBrandVector();
|
|
|
List<Double> brandVectorW2v = userPersonalFactorRspNew.getBrandVectorW2v();
|
|
|
if(brandVectorW2v!=null && !brandVectorW2v.isEmpty()){
|
|
|
this.calScore(shopBrandList,brandVector,false);
|
|
|
}else{
|
|
|
this.calScore(shopBrandList,brandVectorW2v,true);
|
|
|
if (brandVectorW2v != null && !brandVectorW2v.isEmpty()) {
|
|
|
this.calScore(shopBrandList, brandVector, false);
|
|
|
} else {
|
|
|
this.calScore(shopBrandList, brandVectorW2v, true);
|
|
|
}
|
|
|
//2、实时推荐店铺加分
|
|
|
List<Integer> recBrandIds = this.getRecBrandIds(userPersonalFactorRspNew);
|
|
|
for (ActivityShopBrandList.ShopBrand shopBrand : shopBrandList) {
|
|
|
if(recBrandIds.contains(shopBrand.getBrandId())){
|
|
|
shopBrand.score = shopBrand.score+1000;
|
|
|
}
|
|
|
}
|
|
|
//2、按得分排序
|
|
|
//3、按得分排序
|
|
|
Collections.sort(shopBrandList, (o1, o2) -> (o2.score).compareTo(o1.score));
|
|
|
|
|
|
//3、截取shopId
|
|
|
//4、截取shopId
|
|
|
List<Integer> shopIds = new ArrayList<>();
|
|
|
for (ActivityShopBrandList.ShopBrand shopBrand: shopBrandList) {
|
|
|
if(shopIds.size()>=50){
|
|
|
for (ActivityShopBrandList.ShopBrand shopBrand : shopBrandList) {
|
|
|
if (shopIds.size() >= 50) {
|
|
|
break;
|
|
|
}
|
|
|
shopIds.add(shopBrand.getShopId());
|
...
|
...
|
@@ -71,12 +82,27 @@ public class ActivityService{ |
|
|
return shopIds;
|
|
|
}
|
|
|
|
|
|
private List<Integer> getRecBrandIds(UserPersonalFactorRspNew userPersonalFactorRspNew) {
|
|
|
List<Integer> realBrandId = new ArrayList<>();
|
|
|
try {
|
|
|
List<SortBrand> realTimeSortBrand = userPersonalFactorRspNew.getRealTimeSortBrandList();
|
|
|
for (SortBrand sortBrand : realTimeSortBrand) {
|
|
|
if (!realBrandId.contains(sortBrand.getBrandId())) {
|
|
|
realBrandId.add(sortBrand.getBrandId());
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
}
|
|
|
return realBrandId;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 按向量计算品牌得分
|
|
|
*/
|
|
|
private void calScore(List<ActivityShopBrandList.ShopBrand> shopBrandList , List<Double> userBrandVector, boolean isRnn) {
|
|
|
private void calScore(List<ActivityShopBrandList.ShopBrand> shopBrandList, List<Double> userBrandVector, boolean isRnn) {
|
|
|
double userBrandVectorNorm = Word2VectorCalculator.getVectorListNorm(userBrandVector);
|
|
|
for (ActivityShopBrandList.ShopBrand shopBrand: shopBrandList) {
|
|
|
for (ActivityShopBrandList.ShopBrand shopBrand : shopBrandList) {
|
|
|
Integer brandId = shopBrand.getBrandId();
|
|
|
List<Double> brandVector = brandVectorCacheBean.queryBrandVector(brandId, isRnn);
|
|
|
if (brandVector == null || brandVector.isEmpty()) {
|
...
|
...
|
|