Authored by hugufei

添加首页个性化接口

package com.yoho.search.restapi.scene;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.pages.FirstPageSceneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
/**
* 首页-猜你喜欢个性化接口
*
* @author gufei.hu
*/
@Controller
public class FirstPageSceneController {
@Autowired
private FirstPageSceneService firstPageSceneService;
/**
* 首页-猜你喜欢个性化接口
*
* @return
*/
@PersionalRateLimit(isOrderUseable = true)
@RequestMapping(method = RequestMethod.GET, value = "/firstPage/productList")
@ResponseBody
public SearchApiResult firstPageProductList(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return firstPageSceneService.productList(paramMap);
}
}
... ...
... ... @@ -21,7 +21,8 @@ import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.shopbrand.BrandListService;
@Controller
public class BrandController {
public class
BrandController {
@Autowired
private BrandListService brandListService;
... ...
... ... @@ -32,11 +32,13 @@ public class CommonRecallRequestBuilder {
requests.add(this.buildFirstSknRequest(userRecallRequest, firstProductSkns));
//1.2) 直通车召回
requests.add(this.buildDirectTrainRequest(userRecallRequest));
//1.3) 新开店铺的召回
//1.3) 直通车-ufo召回
requests.add(this.buildUfoDirectTrainRequest(userRecallRequest));
//1.4) 新开店铺的召回
requests.add(this.buildNewShopRequest(userRecallRequest));
//1.4) 流量补偿的召回
//1.5) 流量补偿的召回
requests.add(this.buildAddFlowRequest(userRecallRequest));
//1.5) 页面的兜底召回
//1.6) 页面的兜底召回
requests.add(this.buildCommonHeatValueStrategy(userRecallRequest, pageSize));
return requests;
}
... ... @@ -60,19 +62,31 @@ public class CommonRecallRequestBuilder {
* @return
*/
private RecallRequest buildDirectTrainRequest(UserRecallRequest userRecallRequest) {
int size = recallConfigService.queryStrategyConfigSize(userRecallRequest, StrategyEnum.DIRECT_TRAIN);
int size = recallConfigService.queryStrategyConfigSize(userRecallRequest, StrategyEnum.DIRECT_TRAIN,60);
CommonDirectTrainStrategy strategy = new CommonDirectTrainStrategy(size);
return new RecallRequest(userRecallRequest.getParamQueryFilter(), strategy);
}
/**
* 构建【按UFO直通车召回】的请求参数
*
* @param userRecallRequest
* @return
*/
private RecallRequest buildUfoDirectTrainRequest(UserRecallRequest userRecallRequest) {
int size = recallConfigService.queryStrategyConfigSize(userRecallRequest, StrategyEnum.DIRECT_TRAIN_UFO,40);
CommonDirectTrainUfoStrategy strategy = new CommonDirectTrainUfoStrategy(size);
return new RecallRequest(userRecallRequest.getParamQueryFilter(), strategy);
}
/**
* 构建【按新开店铺召回】的请求参数
*
* @param userRecallRequest
* @return
*/
private RecallRequest buildNewShopRequest(UserRecallRequest userRecallRequest) {
int size = recallConfigService.queryStrategyConfigSize(userRecallRequest, StrategyEnum.NEW_SHOP);
int size = recallConfigService.queryStrategyConfigSize(userRecallRequest, StrategyEnum.NEW_SHOP,10);
CommonNewShopStrategy strategy = new CommonNewShopStrategy(size);
return new RecallRequest(userRecallRequest.getParamQueryFilter(), strategy);
}
... ... @@ -84,7 +98,7 @@ public class CommonRecallRequestBuilder {
* @return
*/
private RecallRequest buildAddFlowRequest(UserRecallRequest userRecallRequest) {
int size = recallConfigService.queryStrategyConfigSize(userRecallRequest, StrategyEnum.ADD_FLOW);
int size = recallConfigService.queryStrategyConfigSize(userRecallRequest, StrategyEnum.ADD_FLOW,10);
CommonAddFlowStrategy strategy = new CommonAddFlowStrategy(size);
return new RecallRequest(userRecallRequest.getParamQueryFilter(), strategy);
}
... ...
... ... @@ -279,7 +279,7 @@ public class UserRecallResponseBuilder {
// 3、占坑
int fromIndex = 1;
for (StrategyEnum strategyEnum : intervalStrategyEnums) {
int recallInterval = recallConfigService.queryStrategyConfigInterval(userRecallRequest, strategyEnum);
int recallInterval = recallConfigService.queryStrategyConfigInterval(userRecallRequest, strategyEnum,10);
this.addByIndexIndex(sknResultList, results, fromIndex++, recallInterval, (sknResult -> strategyEnum.equals(sknResult.getStrategy())), dropTransfer);
}
return results;
... ...
... ... @@ -26,7 +26,6 @@ import com.yoho.search.service.recall.models.req.RecallRequest;
import com.yoho.search.service.recall.models.req.RecallRequestResponse;
import com.yoho.search.service.recall.models.req.RecallResponse;
import com.yoho.search.service.recall.models.req.UserRecallRequest;
import com.yoho.search.service.scene.shopbrand.RecommendBrandService;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
... ... @@ -69,21 +68,21 @@ public class SknRecallCacheBean {
try {
List<Integer> filterSknList = new ArrayList<>();
//1、获取实时点击skn的配置
int recSknCount = recallConfigService.queryStrategyConfigSize(userRecallRequest, StrategyEnum.REC_SKN);
int recSknCount = recallConfigService.queryStrategyConfigSize(userRecallRequest, StrategyEnum.REC_SKN, 8);
if (recSknCount > 0 && userPersonalFactor.getRecommendSknList() != null) {
filterSknList.addAll(userPersonalFactor.getRecommendSknList());
} else {
recSknCount = 0;
}
//2、获取相似skn的配置
int youtubeSknCount = recallConfigService.queryStrategyConfigSize(userRecallRequest, StrategyEnum.RT_YOUTUBE_SKN);
int youtubeSknCount = recallConfigService.queryStrategyConfigSize(userRecallRequest, StrategyEnum.RT_YOUTUBE_SKN, 8);
if (youtubeSknCount > 0 && userPersonalFactor.getRealTimeYoutubeSknList() != null) {
filterSknList.addAll(userPersonalFactor.getRealTimeYoutubeSknList());
} else {
youtubeSknCount = 0;
}
//3、获取相似skn的配置
int rtSimSknCount = recallConfigService.queryStrategyConfigSize(userRecallRequest, StrategyEnum.RT_SIM_SKN);
int rtSimSknCount = recallConfigService.queryStrategyConfigSize(userRecallRequest, StrategyEnum.RT_SIM_SKN, 8);
if (rtSimSknCount > 0 && userPersonalFactor.getRealTimeSimilarSknList() != null) {
filterSknList.addAll(userPersonalFactor.getRealTimeSimilarSknList());
} else {
... ...
... ... @@ -26,6 +26,7 @@ public class ExtendFilterHelper {
filter.must(QueryBuilders.termQuery(ProductIndexEsField.flowType, "1"));
//filter.mustNot(QueryBuilders.rangeQuery(ProductIndexEsField.breakSizePercent).gt(50));
filter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.isGlobal, "Y"));
filter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.isUfo, "Y"));
filter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.shopId, SpecialShopConstants.DOWNGRADE_SHOPIDS));
return filter;
}
... ... @@ -38,7 +39,21 @@ public class ExtendFilterHelper {
public static QueryBuilder directTrainFilter() {
BoolQueryBuilder filter = QueryBuilders.boolQuery();
filter.must(QueryBuilders.termQuery(ProductIndexEsField.toAddScore, "Y"));
//filter.mustNot(QueryBuilders.rangeQuery(ProductIndexEsField.breakSizePercent).gt(50));
filter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.isUfo, "Y"));
filter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.isGlobal, "Y"));
filter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.shopId, SpecialShopConstants.DOWNGRADE_SHOPIDS));
return filter;
}
/**
* ufo直通车的过滤器
*
* @return
*/
public static QueryBuilder ufoDirectTrainFilter() {
BoolQueryBuilder filter = QueryBuilders.boolQuery();
filter.must(QueryBuilders.termQuery(ProductIndexEsField.toAddScore, "Y"));
filter.must(QueryBuilders.termQuery(ProductIndexEsField.isUfo, "Y"));
filter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.isGlobal, "Y"));
filter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.shopId, SpecialShopConstants.DOWNGRADE_SHOPIDS));
return filter;
... ... @@ -223,7 +238,7 @@ public class ExtendFilterHelper {
BoolQueryBuilder filter = QueryBuilders.boolQuery();
filter.should(QueryBuilders.termQuery(ProductIndexEsField.flowType, "2"));
filter.should(QueryBuilders.termQuery(ProductIndexEsField.isGlobal, "Y"));
//filter.should(QueryBuilders.rangeQuery(ProductIndexEsField.breakSizePercent).gt(50));
filter.should(QueryBuilders.termQuery(ProductIndexEsField.isUfo, "Y"));
filter.should(QueryBuilders.termsQuery(ProductIndexEsField.storeShowStatus, Arrays.asList("3", "4")));
filter.should(QueryBuilders.termsQuery(ProductIndexEsField.shopId, SpecialShopConstants.DOWNGRADE_SHOPIDS));
return filter;
... ...
... ... @@ -29,11 +29,11 @@ public class StrategyHelper {
* @return
*/
public static List<StrategyEnum> getIntervalStrategyEnums() {
return Arrays.asList(StrategyEnum.REC_SKN, StrategyEnum.RT_YOUTUBE_SKN, StrategyEnum.RT_SIM_SKN, StrategyEnum.DIRECT_TRAIN, StrategyEnum.ADD_FLOW, StrategyEnum.NEW_SHOP);
return Arrays.asList(StrategyEnum.REC_SKN, StrategyEnum.RT_YOUTUBE_SKN, StrategyEnum.RT_SIM_SKN, StrategyEnum.DIRECT_TRAIN, StrategyEnum.DIRECT_TRAIN_UFO, StrategyEnum.ADD_FLOW, StrategyEnum.NEW_SHOP);
}
/**
*推荐类型枚举
* 推荐类型枚举
*
* @return
*/
... ... @@ -45,7 +45,7 @@ public class StrategyHelper {
}
/**
*按class生成IRecallSknStrategy
* 按class生成IRecallSknStrategy
*
* @return
*/
... ... @@ -72,6 +72,9 @@ public class StrategyHelper {
if (strategyEnum.equals(StrategyEnum.DIRECT_TRAIN)) {
return RecallConfigConstants.DIRECT_TRAIN;
}
if (strategyEnum.equals(StrategyEnum.DIRECT_TRAIN_UFO)) {
return RecallConfigConstants.DIRECT_TRAIN_UFO;
}
if (strategyEnum.equals(StrategyEnum.NEW_SHOP)) {
return RecallConfigConstants.NEW_SHOP;
}
... ...
... ... @@ -2,8 +2,9 @@ package com.yoho.search.service.recall.beans.strategy;
public enum StrategyEnum {
FIRST_SKN(110),//配置的skn
DIRECT_TRAIN(109),//直通车
FIRST_SKN(111),//配置的skn
DIRECT_TRAIN(110),//直通车
DIRECT_TRAIN_UFO(109),//UFO直通车
REC_SKN(108),//实时推荐的skn
RT_YOUTUBE_SKN(107),//实时推荐的skn的相似skn
RT_SIM_SKN(106),//实时推荐的skn的相似skn
... ...
package com.yoho.search.service.recall.beans.strategy.impls;
import com.yoho.search.cache.CacheTimeConstants;
import com.yoho.search.service.recall.beans.helper.ExtendFilterHelper;
import com.yoho.search.service.recall.beans.helper.SortBuilderHelper;
import com.yoho.search.service.recall.beans.strategy.IStrategy;
import com.yoho.search.service.recall.beans.strategy.StrategyEnum;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.sort.SortBuilder;
/**
* 直通车的召回
*
* @author gufei.hu
*
*/
public class CommonDirectTrainUfoStrategy implements IStrategy {
private int size;
public CommonDirectTrainUfoStrategy(int size) {
this.size = size;
}
@Override
public StrategyEnum strategtEnum() {
return StrategyEnum.DIRECT_TRAIN_UFO;
}
@Override
public QueryBuilder extendFilter() {
return ExtendFilterHelper.ufoDirectTrainFilter();
}
@Override
public SortBuilder<?> sortBuilder() {
return SortBuilderHelper.getRandomSort();
}
@Override
public int size() {
return size;
}
@Override
public int cacheTimeInMinute() {
return CacheTimeConstants.COMMON_RECALL_STRATEGY_CACHE_TIME;
}
@Override
public String strategyCacheKey() {
StringBuilder sb = defaultStrategyKey();
return sb.toString();
}
}
... ...
... ... @@ -7,6 +7,7 @@ public class RecallConfigConstants {
public static final int DEFAULT_PAGE_ID = 0;
public static final String DIRECT_TRAIN = "DIRECT_TRAIN";
public static final String DIRECT_TRAIN_UFO = "DIRECT_TRAIN_UFO";
public static final String REC_SKN = "REC_SKN";
public static final String RT_SIM_SKN = "RT_SIM_SKN";
public static final String RT_YOUTUBE_SKN = "RT_YOUTUBE_SKN";
... ...
... ... @@ -40,9 +40,9 @@ public class RecallConfigService {
* @param strategyEnum
* @return
*/
public int queryStrategyConfigSize(UserRecallRequest userRecallRequest, StrategyEnum strategyEnum) {
public int queryStrategyConfigSize(UserRecallRequest userRecallRequest, StrategyEnum strategyEnum,int defaultSize) {
String configKey = StrategyHelper.getStrategyConfigKey(strategyEnum);
int size = recallConfigCommonService.queryConfigSize(userRecallRequest.getPageId(), configKey, 0);
int size = recallConfigCommonService.queryConfigSize(userRecallRequest.getPageId(), configKey, defaultSize);
size = this.legallValue(size, 0, 100);
if (userRecallRequest.openDetailLog()) {
RECALL_LOGGER.info("queryStrategyConfigSize,pageId is [{}],strategyEnum is [{}],size is[{}]", userRecallRequest.getPageId(), strategyEnum.name(), size);
... ... @@ -57,7 +57,7 @@ public class RecallConfigService {
* @param strategyEnum
* @return
*/
public int queryStrategyConfigInterval(UserRecallRequest userRecallRequest, StrategyEnum strategyEnum) {
public int queryStrategyConfigInterval(UserRecallRequest userRecallRequest, StrategyEnum strategyEnum,int defaultInterval) {
String configKey = StrategyHelper.getStrategyConfigKey(strategyEnum);
int interval = recallConfigCommonService.queryConfigInterval(userRecallRequest.getPageId(), configKey, 10);
interval = this.legallValue(interval, 2, 40);
... ...
package com.yoho.search.service.scene.pages;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.core.es.utils.PageUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.pages.entrance.ProductListSwitchService;
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.Map;
@Service
public class FirstPageSceneService extends AbstractPageSceneService {
private static final Logger logger = LoggerFactory.getLogger(CouponPageSceneService.class);
@Autowired
private ProductListSwitchService productListSwitchService;
@Override
public String pageId() {
return SearchPageIdDefine.PAGE_ID_FIESTPAGE_GUESSLIKE;
}
@Override
public void addParamsToParamMap(Map<String, String> paramMap) {
super.addDefaultParamsToParamMap(paramMap);
}
@Override
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、返回商品列表
SearchApiResult searchApiResult = productListSwitchService.productList(this.newParamMap(paramMap));
JSONObject jsonObject = (JSONObject) searchApiResult.getData();
// 3、限制最大返回条数为200条
long total = Math.min(MapUtils.getIntValue(jsonObject, "total", 0), 200L);
int page_size = MapUtils.getIntValue(jsonObject, "page_size", 0);
jsonObject.put("total", total);
jsonObject.put("page_total", PageUtils.getTotalPage(total,page_size));
return searchApiResult;
} catch (Exception e) {
return SearchApiResultUtils.errorSearchApiResult(logger, paramMap, e);
}
}
@Override
public SearchApiResult aggregations(Map<String, String> paramMap) {
return new SearchApiResult();
}
}
... ...