|
|
package com.yoho.search.service.scene.sapp;
|
|
|
|
|
|
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.SearchDynamicConfigService;
|
|
|
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.aggregations.SceneAggregationsHelper;
|
|
|
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 com.yoho.search.service.service.ISearchRecommendService;
|
|
|
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;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
@Service
|
|
|
public class SappFuzzySceneService extends AbstractSceneService {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(SappFuzzySceneService.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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|