Authored by hugufei

Merge branch 'master' into hongren

Showing 17 changed files with 328 additions and 106 deletions
package com.yoho.search.recall.scene.beans.builder;
import com.alibaba.fastjson.JSON;
import com.yoho.search.recall.scene.beans.strategy.StrategyEnum;
import com.yoho.search.recall.scene.models.common.RecallMergerResult;
import com.yoho.search.recall.scene.models.req.RecallRequest;
... ...
... ... @@ -178,7 +178,7 @@ public class UserRecallResponseBuilder {
continue;
}
//2)如果是推荐出来的,则单独加分[以减分的方式依次保证顺序]
if (strategy.equals(StrategyEnum.REC_SKN)) {
if (strategy.equals(StrategyEnum.REC_SKN)||strategy.equals(StrategyEnum.RT_SIM_SKN)) {
sknResult.setScore((double) recommendSknIndex--);
continue;
}
... ... @@ -246,19 +246,22 @@ public class UserRecallResponseBuilder {
}
}
// 2、加入全部【除直通车和直接推荐】外的商品
// 2、加入全部【除直通车和推荐】外的商品
iterator = sknResultList.iterator();
while (iterator.hasNext()) {
RecallMergerResult.SknResult sknResult = iterator.next();
if (!Arrays.asList(StrategyEnum.DIRECT_TRAIN,StrategyEnum.REC_SKN).contains(sknResult.getStrategy())){
if (!Arrays.asList(StrategyEnum.DIRECT_TRAIN,StrategyEnum.REC_SKN,StrategyEnum.RT_SIM_SKN).contains(sknResult.getStrategy())){
results.add(sknResult);
iterator.remove();
}
}
// 3、插入【直接推荐】的商品-随机插入
// 3、插入【REC_SKN】的商品-随机插入
this.addByIndexIndex(sknResultList, results, 1, 2, (sknResult -> StrategyEnum.REC_SKN.equals(sknResult.getStrategy())),dropTransfer);
// 4、插入【RT_SIM_SKN】的商品-随机插入
this.addByIndexIndex(sknResultList, results, 2, 3, (sknResult -> StrategyEnum.RT_SIM_SKN.equals(sknResult.getStrategy())),dropTransfer);
// 4、插入【直通车】商品-随机插入
int directTrainIndexInterval = searchDynamicConfigService.directTrainIndexInterval();
this.addByIndexIndex(sknResultList, results, 4, directTrainIndexInterval, (sknResult -> StrategyEnum.DIRECT_TRAIN.equals(sknResult.getStrategy())),dropTransfer);
... ... @@ -269,12 +272,7 @@ public class UserRecallResponseBuilder {
/**
* 单策略召回时,超出数量直接丢弃
*/
private static Transfer<RecallMergerResult.SknResult,Boolean> dropTransfer = new Transfer<RecallMergerResult.SknResult, Boolean>() {
@Override
public Boolean transfer(RecallMergerResult.SknResult sknResult) {
return sknResult.isOnlyOneStrategy()?true:false;
}
};
private static Transfer<RecallMergerResult.SknResult,Boolean> dropTransfer = (sknResult) ->sknResult.isOnlyOneStrategy()?true:false;
private static <T> void addByIndexIndex(List<T> fromList, List<T> toList,int fromIndex, int indexInterval,Transfer<T, Boolean> match,Transfer<T, Boolean> drop) {
Iterator<T> iterator = fromList.iterator();
... ... @@ -307,15 +305,18 @@ public class UserRecallResponseBuilder {
public static void main(String[] args) {
List<Integer> fromList = new ArrayList<>();
for (int index =1;index <=20;index ++){
for (int index =1;index <=30;index ++){
fromList.add(index);
}
List<Integer> toList = new ArrayList<>();
for (int index =0;index <1;index ++){
for (int index =0;index <100;index ++){
toList.add(0);
}
addByIndexIndex(fromList, toList, 1, 2, (value -> value%2==1),null);
addByIndexIndex(fromList, toList, 2, 3, (value -> value%2==0),null);
System.out.println(toList);
// addByIndexIndex(fromList, toList, 4, 4, (value -> value%2==0));
// System.out.println(toList);
... ...
package com.yoho.search.recall.scene.beans.cache;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.base.utils.CollectionUtils;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.common.cache.impls.EhCache;
... ... @@ -9,9 +10,13 @@ import com.yoho.search.common.cache.model.CacheObject;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.recall.scene.beans.persional.PageProductIdBitSetComponent;
import com.yoho.search.recall.scene.beans.strategy.IStrategy;
import com.yoho.search.recall.scene.beans.strategy.impls.IRecallSknStrategy;
import com.yoho.search.recall.scene.beans.strategy.impls.RealTimeSimilarSknStrategy;
import com.yoho.search.recall.scene.beans.strategy.impls.RecommendSknStrategy;
import com.yoho.search.recall.scene.models.common.ParamQueryFilter;
import com.yoho.search.recall.scene.models.personal.PageProductIdBitSet;
import com.yoho.search.recall.scene.models.personal.UserPersonalFactor;
import com.yoho.search.recall.scene.models.req.RecallRequest;
import com.yoho.search.recall.scene.models.req.RecallRequestResponse;
import com.yoho.search.recall.scene.models.req.RecallResponse;
... ... @@ -50,25 +55,63 @@ public class SknRecallCacheBean {
*
* @return
*/
public List<RecallRequestResponse> batchRecallRecommedSknList(UserRecallRequest userRecallRequest, List<Integer> recommedSknList, int maxReturnCount) {
public List<RecallRequestResponse> batchRecallBySknList(UserRecallRequest userRecallRequest, UserPersonalFactor userPersonalFactor, int maxReturnCount) {
try {
if (recommedSknList == null || recommedSknList.isEmpty()) {
return new ArrayList<>();
//1、获取SKN,以及每个skn对应的找回类型
List<Integer> filterSknList = new ArrayList<>();
if (userPersonalFactor.getRecommendSknList() != null) {
filterSknList.addAll(userPersonalFactor.getRecommendSknList());
}
List<Integer> filterSknList;
if (userPersonalFactor.getRealTimeSimilarSknList() != null) {
filterSknList.addAll(userPersonalFactor.getRealTimeSimilarSknList());
}
//2、执行查询
List<Integer> filterSknResults;
if (recallWithCache) {
filterSknList = this.filterRecommendWithCache(userRecallRequest, recommedSknList);
filterSknResults = this.filterRecommendWithCache(userRecallRequest, filterSknList);
} else {
filterSknList = this.filterRecommedSknListByEs(userRecallRequest, recommedSknList);
filterSknResults = this.filterRecommedSknListByEs(userRecallRequest, filterSknList);
}
RECALL_NEW_LOGGER.info("recommedSknList size is [{}], filterSknListSize is[{}]", recommedSknList.size(), filterSknList.size());
return this.buildResults(userRecallRequest, filterSknList, maxReturnCount);
//3、构造结果
List<RecallRequestResponse> results = new ArrayList<>();
ParamQueryFilter paramQueryFilter = userRecallRequest.getParamQueryFilter();
results.addAll(this.buildResults(paramQueryFilter, userPersonalFactor.getRecommendSknList(), RecommendSknStrategy.class, filterSknResults, maxReturnCount));
results.addAll(this.buildResults(paramQueryFilter, userPersonalFactor.getRealTimeSimilarSknList(), RealTimeSimilarSknStrategy.class, filterSknResults, maxReturnCount));
return results;
} catch (Exception e) {
RECALL_NEW_LOGGER.error(e.getMessage(), e);
return new ArrayList<>();
}
}
private List<RecallRequestResponse> buildResults(ParamQueryFilter paramQueryFilter, List<Integer> filterSkns, Class<? extends IRecallSknStrategy> clazz, List<Integer> sknResults, int maxReturnCount) {
if (filterSkns == null || filterSkns.isEmpty() || sknResults == null || sknResults.isEmpty()) {
return new ArrayList<>();
}
List<RecallRequestResponse> results = new ArrayList<>();
for (Integer skn : filterSkns) {
if (results.size() >= maxReturnCount) {
break;
}
if(!sknResults.contains(skn)){
continue;
}
RecallRequest recallRequest = new RecallRequest(paramQueryFilter, this.getRecallSknStrategy(clazz, skn));
RecallRequestResponse recallRequestResponse = new RecallRequestResponse(recallRequest);
recallRequestResponse.setResponse(new RecallResponse(1L, Arrays.asList(skn)), false);
results.add(recallRequestResponse);
}
return results;
}
private IRecallSknStrategy getRecallSknStrategy(Class<? extends IRecallSknStrategy> clazz, Integer skn) {
if (clazz.isAssignableFrom(RecommendSknStrategy.class)) {
return new RecommendSknStrategy(skn);
} else {
return new RealTimeSimilarSknStrategy(skn);
}
}
/**
* 从ehcahc或者redis中构造返回结果
*
... ... @@ -198,27 +241,4 @@ public class SknRecallCacheBean {
return results;
}
/**
* 将推荐的skn构造成召回对象
*
* @return
*/
private List<RecallRequestResponse> buildResults(UserRecallRequest userRecallRequest, final List<Integer> recommedSknList, int maxReturnCount) {
List<RecallRequestResponse> results = new ArrayList<>();
if (recommedSknList == null || recommedSknList.isEmpty()) {
return results;
}
ParamQueryFilter paramQueryFilter = userRecallRequest.getParamQueryFilter();
for (Integer recommendSkn : recommedSknList) {
if (results.size() >= maxReturnCount) {
break;
}
RecallRequest recallRequest = new RecallRequest(paramQueryFilter, new RecommendSknStrategy(recommendSkn));
RecallRequestResponse recallRequestResponse = new RecallRequestResponse(recallRequest);
recallRequestResponse.setResponse(new RecallResponse(1L, Arrays.asList(recommendSkn)), false);
results.add(recallRequestResponse);
}
return results;
}
}
... ...
... ... @@ -104,7 +104,7 @@ public class UserRecallCacheBean extends AbstractCacheBean<UserRecallRequest, Us
long begin = System.currentTimeMillis();
//1、处理实时推荐SKN的召回
CompletableFuture<List<RecallRequestResponse>> recommendSknCompletableFuture = this.doRecallRecommendSkn(userRecallRequest, userPersonalFactor);
CompletableFuture<List<RecallRequestResponse>> recallBySknListCompletableFuture = this.doRecallBySknList(userRecallRequest, userPersonalFactor);
//2、处理通用召回
CompletableFuture<List<RecallRequestResponse>> commonCompletableFuture = this.doRecallCommon(userRecallRequest, userPersonalFactor);
... ... @@ -118,7 +118,7 @@ public class UserRecallCacheBean extends AbstractCacheBean<UserRecallRequest, Us
//5、构造最终返回结果投入额
List<RecallRequestResponse> batchRequestResults = new ArrayList<>();
batchRequestResults.addAll(this.getResultFromCompletableFuture(recommendSknCompletableFuture));//推荐的skn放在第一个,不然merger的时候可能会无序
batchRequestResults.addAll(this.getResultFromCompletableFuture(recallBySknListCompletableFuture));//按skn召回放在第一个,不然merger的时候可能会无序
batchRequestResults.addAll(this.getResultFromCompletableFuture(commonCompletableFuture));
batchRequestResults.addAll(this.getResultFromCompletableFuture(realTimeSortBrandCompletableFuture));
batchRequestResults.addAll(this.getResultFromCompletableFuture(forecastSortBrandCompletableFuture));
... ... @@ -169,12 +169,13 @@ public class UserRecallCacheBean extends AbstractCacheBean<UserRecallRequest, Us
* @param userPersonalFactor
* @return
*/
private CompletableFuture<List<RecallRequestResponse>> doRecallRecommendSkn(UserRecallRequest userRecallRequest, UserPersonalFactor userPersonalFactor) {
private CompletableFuture<List<RecallRequestResponse>> doRecallBySknList(UserRecallRequest userRecallRequest, UserPersonalFactor userPersonalFactor) {
return CompletableFuture.supplyAsync(() -> {
long begin = System.currentTimeMillis();
int requestCount = userPersonalFactor.getRecommendSknList() == null ? 0 : userPersonalFactor.getRecommendSknList().size();
List<RecallRequestResponse> recommendSknRequestResponses = sknRecallCacheBean.batchRecallRecommedSknList(userRecallRequest, userPersonalFactor.getRecommendSknList(), 8);
RECALL_NEW_LOGGER.info("UserRecallCacheBean[2]-doRecallRecommendSkn,requestCount is [{}], cost is [{}]", requestCount, System.currentTimeMillis() - begin);
int recommendSknCount = userPersonalFactor.getRecommendSknList() == null ? 0 : userPersonalFactor.getRecommendSknList().size();
int realTimeSimilarSknCount = userPersonalFactor.getRealTimeSimilarSknList() == null ? 0 : userPersonalFactor.getRealTimeSimilarSknList().size();
List<RecallRequestResponse> recommendSknRequestResponses = sknRecallCacheBean.batchRecallBySknList(userRecallRequest,userPersonalFactor, 8);
RECALL_NEW_LOGGER.info("UserRecallCacheBean[2]-doRecallRecommendSkn,recommendSknCount is [{}],realTimeSimilarSknCount is[{}] ,cost is [{}]", recommendSknCount, realTimeSimilarSknCount,System.currentTimeMillis() - begin);
return recommendSknRequestResponses;
}, recallExecutorService);
}
... ...
... ... @@ -98,8 +98,9 @@ public class QueryUserPersionalFactorBean {
List<SortPriceAreas> sortPriceAreasList = this.getSortPriceAreasListWithSort(userFactor, pageFactor);
//5、构造推荐的skn列表
List<Integer> recommendSknList = userFactor.getRecommendSknList();
List<Integer> realTimeSimilarSknList = userFactor.getRealTimeSimilarSknList();
//6、返回最终结果
return new UserPersonalFactor(realTimeSortBrandList, forecastSortBrandList, sortPriceAreasList, recommendSknList, userFactor.getVector());
return new UserPersonalFactor(realTimeSortBrandList, forecastSortBrandList, sortPriceAreasList, recommendSknList,realTimeSimilarSknList, userFactor.getVector());
}
private Map<Integer, List<Integer>> getPageBrand2MiSortIdsMap(PagePersonalFactor pageFactor) {
... ...
... ... @@ -6,6 +6,7 @@ public enum StrategyEnum {
DIRECT_TRAIN(109),//直通车
REC_SKN(99),//实时推荐的商品
RT_SIM_SKN(98),//实时推荐的相似商品
REC_S_B_HEAT_VALUE(41),//实时的品牌+品类的人气值
REC_S_B_REDUCE_PRICE(42),//实时的品牌+品类的最新降价
... ...
package com.yoho.search.recall.scene.beans.strategy.impls;
import com.yoho.search.recall.scene.beans.helper.ExtendFilterHelper;
import com.yoho.search.recall.scene.beans.helper.SortBuilderHelper;
import com.yoho.search.recall.scene.beans.strategy.IStrategy;
import com.yoho.search.recall.scene.beans.strategy.StrategyEnum;
import com.yoho.search.recall.scene.constants.CacheTimeConstants;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.sort.SortBuilder;
public abstract class IRecallSknStrategy implements IStrategy {
private Integer skn;
public IRecallSknStrategy(Integer skn) {
this.skn = skn;
}
public abstract StrategyEnum strategtEnum();
@Override
public QueryBuilder extendFilter() {
return ExtendFilterHelper.productSknFilter(this.skn);
}
@Override
public SortBuilder<?> sortBuilder() {
return SortBuilderHelper.getIdDescSort();
}
@Override
public int size() {
return 1;
}
@Override
public int cacheTimeInMinute() {
return CacheTimeConstants.SKN_RECALL_CACHE_TIME;
}
@Override
public String strategyCacheKey() {
StringBuilder sb = defaultStrategyKey();
sb.append(this.skn==null?"0": skn.toString());
return sb.toString();
}
}
... ...
package com.yoho.search.recall.scene.beans.strategy.impls;
import com.yoho.search.recall.scene.beans.strategy.StrategyEnum;
/**
* 推荐skn的召回策略
*
* @author gufei.hu
*
*/
public class RealTimeSimilarSknStrategy extends IRecallSknStrategy{
public RealTimeSimilarSknStrategy(Integer recommendSkn) {
super(recommendSkn);
}
@Override
public StrategyEnum strategtEnum() {
return StrategyEnum.RT_SIM_SKN;
}
}
... ...
... ... @@ -14,12 +14,10 @@ import org.elasticsearch.search.sort.SortBuilder;
* @author gufei.hu
*
*/
public class RecommendSknStrategy implements IStrategy {
private Integer recommendSkn;
public class RecommendSknStrategy extends IRecallSknStrategy{
public RecommendSknStrategy(Integer recommendSkn) {
this.recommendSkn = recommendSkn;
super(recommendSkn);
}
@Override
... ... @@ -27,30 +25,4 @@ public class RecommendSknStrategy implements IStrategy {
return StrategyEnum.REC_SKN;
}
@Override
public QueryBuilder extendFilter() {
return ExtendFilterHelper.productSknFilter(this.recommendSkn);
}
@Override
public SortBuilder<?> sortBuilder() {
return SortBuilderHelper.getIdDescSort();
}
@Override
public int size() {
return 1;
}
@Override
public int cacheTimeInMinute() {
return CacheTimeConstants.RECOMMEND_SKN_CACHE_TIME;
}
@Override
public String strategyCacheKey() {
StringBuilder sb = defaultStrategyKey();
sb.append(this.recommendSkn==null?"0": recommendSkn.toString());
return sb.toString();
}
}
... ...
... ... @@ -10,7 +10,7 @@ public class CacheTimeConstants {
public static final int COMMON_RECALL_STRATEGY_CACHE_TIME = 10 ;
//SKN的的缓存 - 60分钟
public static final int RECOMMEND_SKN_CACHE_TIME = 60 ;
public static final int SKN_RECALL_CACHE_TIME = 60 ;
//品类+品牌的缓存 - 60分钟
public static final int SORT_BRAND_RECALL_STRATEGY_CACHE_TIME = 60 ;
... ...
... ... @@ -12,6 +12,7 @@ public class UserPersonalFactor {
private List<SortBrand> forecastSortBrandList;
private List<SortPriceAreas> sortPriceAreasList;
private List<Integer> recommendSknList;
private List<Integer> realTimeSimilarSknList;
private String vector;
public UserPersonalFactor (){
... ... @@ -19,14 +20,16 @@ public class UserPersonalFactor {
this.forecastSortBrandList = new ArrayList<>();
this.sortPriceAreasList = new ArrayList<>();
this.recommendSknList = new ArrayList<>();
this.realTimeSimilarSknList = realTimeSimilarSknList;
this.vector = "";
}
public UserPersonalFactor(List<SortBrand> realTimeSortBrandList,List<SortBrand> forecastSortBrandList,List<SortPriceAreas> sortPriceAreasList,List<Integer> recommendSknList, String vector) {
public UserPersonalFactor(List<SortBrand> realTimeSortBrandList,List<SortBrand> forecastSortBrandList,List<SortPriceAreas> sortPriceAreasList,List<Integer> recommendSknList,List<Integer> realTimeSimilarSknList, String vector) {
this.realTimeSortBrandList = realTimeSortBrandList;
this.forecastSortBrandList = forecastSortBrandList;
this.sortPriceAreasList = sortPriceAreasList;
this.recommendSknList = recommendSknList;
this.realTimeSimilarSknList = realTimeSimilarSknList;
this.vector = vector;
}
... ... @@ -62,5 +65,7 @@ public class UserPersonalFactor {
return sortPriceAreasList==null?0:sortPriceAreasList.size();
}
public List<Integer> getRealTimeSimilarSknList() {
return realTimeSimilarSknList;
}
}
... ...
package com.yoho.search.restapi.miniapp;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.miniapp.MiniappFuzzySceneService;
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;
@Controller
public class MiniappProductListController {
@Autowired
private MiniappFuzzySceneService miniappFuzzySceneService;
/**
* 小程序模糊搜索列表
*
* @return
*/
@PersionalRateLimit(isOrderUseable = true)
@RequestMapping(method = RequestMethod.GET, value = "/miniapp/fuzzy/productList")
@ResponseBody
public SearchApiResult miniappFuzzyProductList(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
SearchApiResult searchApiResult = miniappFuzzySceneService.productList(paramMap);
return searchApiResult;
}
/**
* 小程序模糊搜索筛选项
*
* @return
*/
@PersionalRateLimit(isOrderUseable = false)
@RequestMapping(method = RequestMethod.GET, value = "/miniapp/fuzzy/aggregations")
@ResponseBody
public SearchApiResult miniappFuzzyAggregations(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return miniappFuzzySceneService.aggregations(paramMap);
}
}
... ...
... ... @@ -35,13 +35,7 @@ public class CouponSceneService extends AbstractSceneService {
@Override
public void addParamsToParamMap(Map<String, String> paramMap) {
super.addDefaultParamsToParamMap(paramMap);
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITED, "N");// 不支持限定
paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_SECKILL, "N");// 不支持秒杀
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISADVANCE, "N");// 不支持预售
paramMap.put(SearchRequestParams.PARAM_SEARCH_BUNDLETYPE, "0");// 不支持套餐
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITEDBUY, "N");// 不支持限购
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISDESPOSITADVANCE, "N");// 不支持定金预售
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITTIMEADVANCE, "N");// 不支持定金促销
super.filterNotNormalToMap(paramMap);
}
@Override
... ...
... ... @@ -135,7 +135,7 @@ public class FuzzySceneService extends AbstractSceneService {
* @param paramMap
* @return
*/
private void addSuggestion(SearchApiResult searchResult, Map<String, String> paramMap) {
public void addSuggestion(SearchApiResult searchResult, Map<String, String> paramMap) {
if (searchResult == null || searchResult.getCode() != 200 || searchResult.getData() == null) {
return;
}
... ...
... ... @@ -186,13 +186,4 @@ public class WebProductListService extends AbstractCacheAbleService {
return searchDynamicConfigService.isSearchSuggestionTipsOpen();
}
/**
* pc的商品列表页
*
* @param paramMap
* @return
*/
}
... ...
... ... @@ -17,7 +17,21 @@ public abstract class AbstractSceneService {
protected static final String STANDARD = "standard";
protected Map<String, String> newParamMap(Map<String, String> paramMap) {
return new HashMap<String, String>(paramMap);
return new HashMap<>(paramMap);
}
/**
* 去除非正常商品的显示
* @param paramMap
*/
protected void filterNotNormalToMap(Map<String, String> paramMap) {
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITED, "N");// 不支持限定
paramMap.put(SearchRequestParams.PARAM_SEARCH_CONTAIN_SECKILL, "N");// 不支持秒杀
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISADVANCE, "N");// 不支持预售
paramMap.put(SearchRequestParams.PARAM_SEARCH_BUNDLETYPE, "0");// 不支持套餐
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITEDBUY, "N");// 不支持限购
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISDESPOSITADVANCE, "N");// 不支持定金预售
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISLIMITTIMEADVANCE, "N");// 不支持定金促销
}
/**
... ... @@ -48,10 +62,6 @@ public abstract class AbstractSceneService {
return page;
}
protected String getuid(Map<String, String> paramMap) {
return MapUtils.getString(paramMap, "uid", "0");
}
public abstract void addParamsToParamMap(Map<String, String> paramMap);
public abstract String pageId();
... ...
package com.yoho.search.service.scene.miniapp;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.base.SearchRequestParams;
import com.yoho.search.service.helper.SearchCommonHelper;
import com.yoho.search.service.helper.SearchKeyWordHelper;
import com.yoho.search.service.list.FuzzySceneProductListService;
import com.yoho.search.service.scene.FuzzySceneService;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.common.SceneRecommendBrandsService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import org.apache.commons.lang.StringUtils;
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 MiniappFuzzySceneService extends AbstractSceneService {
private static final Logger logger = LoggerFactory.getLogger(MiniappFuzzySceneService.class);
@Autowired
private SearchCommonHelper searchCommonHelper;
@Autowired
private SearchKeyWordHelper searchKeyWordService;
@Autowired
private FuzzySceneProductListService fuzzySceneProductListService;
@Autowired
private FuzzySceneService fuzzySceneService;
@Autowired
private SceneSelectionsService sceneSelectionsService;
@Autowired
private SceneRecommendBrandsService sceneRecommendBrandsService;
@Override
public String pageId() {
return SearchPageIdDefine.PAGE_ID_SEARCH;
}
@Override
public void addParamsToParamMap(Map<String, String> paramMap) {
super.addDefaultParamsToParamMap(paramMap);
super.filterNotNormalToMap(paramMap);
paramMap.put(SearchRequestParams.PARAM_SEARCH_NEED_SUGGESTION, "Y");// 返回建议词
}
/**
* @1、返回商品列表
* @2、数量太多则返回建议词
*/
@Override
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 1、参数校验
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY))) {
return new SearchApiResult().setCode(400).setMessage("请传query参数");
}
// 2、添加默认参数
this.addParamsToParamMap(paramMap);
// 3、获取列表
SearchApiResult productListResult = fuzzySceneProductListService.productList(paramMap);
// 4、加入建议词
fuzzySceneService.addSuggestion(productListResult, paramMap);
// 5、模糊搜索页记录关键字对应的查询结果
String queryWord = paramMap.get("query");
if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySknOrSku(queryWord)) {
long total = ((JSONObject) productListResult.getData()).getLongValue("total");
searchKeyWordService.recordKeyWordByResultCount(queryWord, total);
}
//6、返回结果
return productListResult;
} catch (Exception e) {
logger.error(e.getMessage(), e);
return SearchApiResultUtils.errorSearchApiResult("SappFuzzySceneService productList Exception", paramMap, e);
}
}
@Override
public SearchApiResult aggregations(Map<String, String> paramMap) {
try {
// 1、参数校验
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY))) {
return new SearchApiResult().setCode(400).setMessage("请传query参数");
}
// 1、添加默认参数
this.addParamsToParamMap(paramMap);
// 2、返回聚合结果
SearchApiResult result = sceneSelectionsService.aggregations(paramMap);
if(result!=null){
sceneRecommendBrandsService.getRecommendBrands(paramMap, result);
}
return result;
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new SearchApiResult().setData(null).setMessage("SappFuzzySceneService Aggregations Exception").setCode(500);
}
}
}
... ...