Authored by hugufei

添加品类页的动态参数

... ... @@ -166,4 +166,18 @@ public class SearchDynamicConfigService {
public int getSearchLikeNotInShopSameSortPercent() {
return configReader.getInt("search.searchlike.not_in_shop.same_sort_percent", 60);
}
/**
* 品类页使用新的召回机制
*/
public boolean isSortPageRecallOpen() {
return configReader.getBoolean("search.sortpage.recall.open", true);
}
/**
* 召回时是否使用全局品牌id
*/
public boolean isSortPageRecallUseGlobalBrand() {
return configReader.getBoolean("search.sortpage.recall.use_global_brand", false);
}
}
... ...
... ... @@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.base.SearchDynamicConfigService;
import com.yoho.search.service.base.SearchRequestParams;
import com.yoho.search.service.helper.SearchCommonHelper;
import com.yoho.search.service.scene.common.AbstractSceneService;
... ... @@ -41,6 +42,8 @@ public class SortSceneService extends AbstractSceneService {
private IAggRecommendService aggRecommendService;
@Autowired
private SortRecallSceneService sortRecallSceneService;
@Autowired
private SearchDynamicConfigService searchDynamicConfigService;
@Override
public String pageId() {
... ... @@ -86,16 +89,18 @@ public class SortSceneService extends AbstractSceneService {
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
CompletableFuture<SearchApiResult> productListFuture = null;
// 2、获取商品列表
//if(!"13420925".equals(this.getuid(paramMap))){
productListFuture = CompletableFuture.supplyAsync(() -> sceneProductListService.productList(this.newParamMap(paramMap)),executorService);
//}else{
// productListFuture = CompletableFuture.supplyAsync(() -> sortRecallSceneService.productList(this.newParamMap(paramMap)),executorService);
//}
// 2、获取商品列表-是否使用召回策略
if (searchDynamicConfigService.isSortPageRecallOpen()) {
productListFuture = CompletableFuture.supplyAsync(() -> sortRecallSceneService.productList(this.newParamMap(paramMap)), executorService);
} else {
productListFuture = CompletableFuture.supplyAsync(() -> sceneProductListService.productList(this.newParamMap(paramMap)), executorService);
}
// 3、获取聚合结果
CompletableFuture<SearchApiResult> standardsFuture = CompletableFuture.supplyAsync(() -> productIndexService.aggStandard(this.newParamMap(paramMap)),executorService);
CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> productIndexService.aggCustomizeTag(this.newParamMap(paramMap)),executorService);
CompletableFuture<List<Object>> recommendProductFuture = CompletableFuture.supplyAsync(() -> aggRecommendService.recommendPromotion(this.newParamMap(paramMap)), executorService);
CompletableFuture<SearchApiResult> standardsFuture = CompletableFuture.supplyAsync(() -> productIndexService.aggStandard(this.newParamMap(paramMap)), executorService);
CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> productIndexService.aggCustomizeTag(this.newParamMap(paramMap)),
executorService);
CompletableFuture<List<Object>> recommendProductFuture = CompletableFuture.supplyAsync(() -> aggRecommendService.recommendPromotion(this.newParamMap(paramMap)),
executorService);
// 4、组合结果
SearchApiResult productList = productListFuture.get();
SearchApiResult standards = standardsFuture.get();
... ...
... ... @@ -52,17 +52,17 @@ public abstract class AbstractRecallService {
long begin = System.currentTimeMillis();
// 1、获取召回策略
List<IRecallStrategy> recallStrategys = this.getRecallStrategys(paramMap);
logger.warn("[func=getRecallStrategys][cost={}ms]", System.currentTimeMillis() - begin);
logger.info("[func=getRecallStrategys][cost={}ms]", System.currentTimeMillis() - begin);
// 2、获取召回参数
begin = System.currentTimeMillis();
List<RecallSearchParam> recallSearchParams = this.getRecallSearchParams(paramMap, recallStrategys);
logger.warn("[func=getRecallSearchParams][cost={}ms]", System.currentTimeMillis() - begin);
logger.info("[func=getRecallSearchParams][cost={}ms]", System.currentTimeMillis() - begin);
// 3、执行查询
begin = System.currentTimeMillis();
RecallResult recallResult = this.queryRecallResult(recallSearchParams);
logger.warn("[func=queryRecallResult][cost={}ms]", System.currentTimeMillis() - begin);
logger.info("[func=queryRecallResult][cost={}ms]", System.currentTimeMillis() - begin);
// 4、从兜底策略中获取总数
long total = this.getTotalFromRecallResult(recallResult);
... ... @@ -70,17 +70,17 @@ public abstract class AbstractRecallService {
// 5、粗排
begin = System.currentTimeMillis();
recallResult = this.doSketchyRank(paramMap, recallResult);
logger.warn("[func=doSketchyRank][cost={}ms]", System.currentTimeMillis() - begin);
logger.info("[func=doSketchyRank][cost={}ms]", System.currentTimeMillis() - begin);
// 6、精排
begin = System.currentTimeMillis();
recallResult = this.doCarefulRank(paramMap, recallResult);
logger.warn("[func=doCarefulRank][cost={}ms]", System.currentTimeMillis() - begin);
logger.info("[func=doCarefulRank][cost={}ms]", System.currentTimeMillis() - begin);
// 7、重排
begin = System.currentTimeMillis();
recallResult = this.doReRank(paramMap, recallResult);
logger.warn("[func=doReRank][cost={}ms]", System.currentTimeMillis() - begin);
logger.info("[func=doReRank][cost={}ms]", System.currentTimeMillis() - begin);
// 8、构造返回结果
begin = System.currentTimeMillis();
... ... @@ -137,7 +137,7 @@ public abstract class AbstractRecallService {
searchParams.add(recallSearchParam.getSearchParam());
}
List<SearchResult> searchResults = searchCommonService.doMutiSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParams);
logger.warn("doMutiSearch cost is:[{}]", System.currentTimeMillis() - begin);
logger.info("doMutiSearch cost is:[{}]", System.currentTimeMillis() - begin);
List<RecallSearchResult> recallSearchResults = new ArrayList<RecallSearchResult>();
for (int i = 0; i < recallSearchParams.size(); i++) {
recallSearchResults.add(new RecallSearchResult(recallSearchParams.get(i).getRecallType(), searchResults.get(i)));
... ...
... ... @@ -126,14 +126,12 @@ public class SortRecallSceneService extends AbstractRecallService {
// 2)获取商品列表
long begin = System.currentTimeMillis();
RecallProductInfoList recallProductInfoList = this.queryRecallProductInfoList(paramMap, page, pageSize);
logger.warn("[func1=queryRealProductList][cost={}]", System.currentTimeMillis() - begin);
logger.info("[func1=queryRealProductList][cost={}]", System.currentTimeMillis() - begin);
// 3)填充变价计划,并做品牌打散
begin = System.currentTimeMillis();
List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(recallProductInfoList.getProductInfoList());
// product_list =
// productListSortService.sortProductList(product_list, paramMap);
logger.warn("[func2=getProductListWithPricePlan][cost={}]", System.currentTimeMillis() - begin);
logger.info("[func2=getProductListWithPricePlan][cost={}]", System.currentTimeMillis() - begin);
// 4)构造返回结果
JSONObject dataMap = new JSONObject();
... ... @@ -201,7 +199,7 @@ public class SortRecallSceneService extends AbstractRecallService {
}
realResults.add(productMap.get(produtSkn));
}
logger.warn("[func=queryProductListWithSort][query by sknList][resultsize is {}][cost={}]", productList.size(), System.currentTimeMillis() - begin);
logger.info("[func=queryProductListWithSort][query by sknList][resultsize is {}][cost={}]", productList.size(), System.currentTimeMillis() - begin);
return realResults;
}
... ... @@ -236,7 +234,7 @@ public class SortRecallSceneService extends AbstractRecallService {
// 4、查询es
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
logger.warn("[func=queryProductListWithDefault][resultsize is {}][cost={}]", searchResult.getTotal(), System.currentTimeMillis() - begin);
logger.info("[func=queryProductListWithDefault][resultsize is {}][cost={}]", searchResult.getTotal(), System.currentTimeMillis() - begin);
return searchResult.getResultList();
}
... ... @@ -258,13 +256,13 @@ public class SortRecallSceneService extends AbstractRecallService {
String uid = MapUtils.getString(paramMap, "uid", "0");
String vectorFeatureVersion = searchDynamicConfigService.personalizedSearchVersion();
String userGlobalBrandIds = bigDataRedisService.getUserGlobalFaveriteBrand(uid, vectorFeatureVersion);
logger.warn("uid is [{}],vectorFeatureVersion is [{}], userGlobalBrandIds is [{}]", uid, vectorFeatureVersion, userGlobalBrandIds);
logger.info("uid is [{}],vectorFeatureVersion is [{}], userGlobalBrandIds is [{}]", uid, vectorFeatureVersion, userGlobalBrandIds);
JSONArray brandJsonArray = JSON.parseArray(userGlobalBrandIds);
List<Integer> results = new ArrayList<Integer>();
for (int i = 0; i < brandJsonArray.size(); i++) {
results.add(Integer.valueOf(brandJsonArray.getString(i)));
}
logger.warn("[getUserGlobalBrandIds,uid is[{}], brandIds is [{}] ]", uid, results);
logger.info("[getUserGlobalBrandIds,uid is[{}], brandIds is [{}] ]", uid, results);
return results;
} catch (Exception e) {
logger.error(e.getMessage(), e);
... ... @@ -330,7 +328,7 @@ public class SortRecallSceneService extends AbstractRecallService {
for (Map<String, Object> result : results) {
brandIds.add(MapUtils.getInteger(result, "id"));
}
logger.warn("[getUserLikeBrandIds,uid is[{}], brandIds is [{}] ]", uid, brandIds);
logger.info("[getUserLikeBrandIds,uid is[{}], brandIds is [{}] ]", uid, brandIds);
return brandIds;
} catch (Exception e) {
logger.error(e.getMessage(), e);
... ... @@ -349,8 +347,12 @@ public class SortRecallSceneService extends AbstractRecallService {
List<IRecallStrategy> recallStrategy = new ArrayList<IRecallStrategy>();
int pageSize = this.getPageSize(paramMap);
// 0、获取用户偏好品牌
// List<Integer> brandIds = this.getUserGlobalBrandIds(paramMap);
List<Integer> brandIds = this.getUserLikeBrandIds(paramMap);
List<Integer> brandIds = null;
if(searchDynamicConfigService.isSortPageRecallUseGlobalBrand()){
brandIds = this.getUserGlobalBrandIds(paramMap);
}else{
brandIds = this.getUserLikeBrandIds(paramMap);
}
// 1、支持firstProductSkn的召回
recallStrategy.add(new FirstProductSknStrategy(1, this.getFirstProductSkns(paramMap)));
// 2、支持直通车的召回-随机召回
... ... @@ -383,7 +385,7 @@ public class SortRecallSceneService extends AbstractRecallService {
protected RecallResult doSketchyRank(Map<String, String> paramMap, RecallResult recallResult) {
Set<String> existProductSkns = new HashSet<String>();
for (RecallSearchResult recallSearchResult : recallResult.getRecallSearchResult()) {
logger.warn("[func=doSketchyRank][type={}][results={}]", recallSearchResult.getRecallType(), recallSearchResult.getResultList().size());
logger.info("[func=doSketchyRank][type={}][results={}]", recallSearchResult.getRecallType(), recallSearchResult.getResultList().size());
Iterator<Map<String, Object>> iterator = recallSearchResult.getResultList().iterator();
while (iterator.hasNext()) {
Map<String, Object> product = iterator.next();
... ... @@ -403,7 +405,7 @@ public class SortRecallSceneService extends AbstractRecallService {
// 1、数据组装
List<Map<String, Object>> productList = new ArrayList<Map<String, Object>>();
for (RecallSearchResult recallSearchResult : recallResult.getRecallSearchResult()) {
logger.warn("[func=doCarefulRank][type={}][results={}]", recallSearchResult.getRecallType(), recallSearchResult.getResultList().size());
logger.info("[func=doCarefulRank][type={}][results={}]", recallSearchResult.getRecallType(), recallSearchResult.getResultList().size());
for (Map<String, Object> product : recallSearchResult.getResultList()) {
product.put("recallType", recallSearchResult.getRecallType());
productList.add(product);
... ... @@ -462,7 +464,7 @@ public class SortRecallSceneService extends AbstractRecallService {
int count = newProductList.size();
int maxPage = count / pageSize;
recallResult.setProductList(newProductList.subList(0, maxPage * pageSize));
logger.warn("[func=doReRank][total product size is ={}]", recallResult.getProductList().size());
logger.info("[func=doReRank][total product size is ={}]", recallResult.getProductList().size());
return recallResult;
}
... ...