|
|
package com.yoho.search.service.scene;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
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 com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.base.utils.SearchPageIdDefine;
|
|
|
import com.yoho.search.common.utils.SearchApiResultUtils;
|
...
|
...
|
@@ -19,7 +11,18 @@ import com.yoho.search.service.helper.SearchKeyWordHelper; |
|
|
import com.yoho.search.service.scene.common.AbstractSceneService;
|
|
|
import com.yoho.search.service.scene.common.SceneProductListService;
|
|
|
import com.yoho.search.service.scene.common.SceneSelectionsService;
|
|
|
import com.yoho.search.service.service.IProductIndexService;
|
|
|
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 FuzzySceneService extends AbstractSceneService {
|
...
|
...
|
@@ -38,6 +41,10 @@ public class FuzzySceneService extends AbstractSceneService { |
|
|
private SearchDynamicConfigService searchDynamicConfigService;
|
|
|
@Autowired
|
|
|
private SearchKeyWordHelper searchKeyWordService;
|
|
|
@Autowired
|
|
|
private IProductIndexService productIndexService;
|
|
|
|
|
|
private ExecutorService executorService = Executors.newFixedThreadPool(100);
|
|
|
|
|
|
// 当少于20个商品时 返回智能搜索词提示
|
|
|
private static final int SMART_SUGGESTION_PRODUCT_LIMIT = 20;
|
...
|
...
|
@@ -62,22 +69,29 @@ public class FuzzySceneService extends AbstractSceneService { |
|
|
@Override
|
|
|
public SearchApiResult productList(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 0、参数校验
|
|
|
// 1、参数校验
|
|
|
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY))) {
|
|
|
return new SearchApiResult().setCode(400).setMessage("请传query参数");
|
|
|
}
|
|
|
// 1、添加默认参数
|
|
|
// 2、添加默认参数
|
|
|
this.addParamsToParamMap(paramMap);
|
|
|
// 2、获取商品列表
|
|
|
// 3、获取商品列表
|
|
|
SearchApiResult searchApiResult = sceneProductListService.productList(paramMap);
|
|
|
// 3、加入建议词
|
|
|
// 4、加入建议词
|
|
|
this.addSuggestion(searchApiResult, paramMap);
|
|
|
// 4、模糊搜索页记录关键字对应的查询结果
|
|
|
// 5、模糊搜索页记录关键字对应的查询结果
|
|
|
String queryWord = paramMap.get("query");
|
|
|
if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySknOrSku(queryWord)) {
|
|
|
long total = ((JSONObject) searchApiResult.getData()).getLongValue("total");
|
|
|
searchKeyWordService.recordKeyWordByResultCount(queryWord, total);
|
|
|
}
|
|
|
// 6、获取自定义标签聚合结果
|
|
|
CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
return productIndexService.aggCustomizeTag(paramMap);
|
|
|
}, executorService);
|
|
|
SearchApiResult customizeTags = customizeTagFuture.get();
|
|
|
JSONObject dataMap = (JSONObject)searchApiResult.getData();
|
|
|
dataMap.put("customize_tag", customizeTags.getData());
|
|
|
return searchApiResult;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
...
|
...
|
|