...
|
...
|
@@ -5,10 +5,6 @@ import com.yoho.search.base.utils.CharUtils; |
|
|
import com.yoho.search.base.utils.ISearchConstants;
|
|
|
import com.yoho.search.base.utils.RedisKeys;
|
|
|
import com.yoho.search.base.utils.SearchCollectionUtils;
|
|
|
import com.yoho.search.cache.beans.SearchCacheFactory;
|
|
|
import com.yoho.search.cache.beans.SearchCacheService;
|
|
|
import com.yoho.search.cache.log.SearchCacheMatchLogger;
|
|
|
import com.yoho.search.cache.model.SearchCache;
|
|
|
import com.yoho.search.common.SearchCommonService;
|
|
|
import com.yoho.search.common.SearchRequestParams;
|
|
|
import com.yoho.search.core.es.model.SearchParam;
|
...
|
...
|
@@ -33,7 +29,6 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
...
|
...
|
@@ -60,17 +55,6 @@ public class RecommendWordsService { |
|
|
private SearchKeyWordHelper searchKeyWordService;
|
|
|
@Autowired
|
|
|
private ProductIndexBaseService productIndexBaseService;
|
|
|
@Autowired
|
|
|
protected SearchCacheService searchCacheService;
|
|
|
@Autowired
|
|
|
protected SearchCacheFactory searchCacheFactory;
|
|
|
|
|
|
private SearchCache searchCache;
|
|
|
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
|
searchCache = searchCacheFactory.getRecommendCache();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据query关键词和搜索结果获取搜索推荐词。 用于搜索结果数量太少或者无结果的时候给予用户的搜索建议。
|
...
|
...
|
@@ -260,26 +244,16 @@ public class RecommendWordsService { |
|
|
sortBuilders.add(SortBuilders.fieldSort(countField).order(SortOrder.DESC));
|
|
|
searchParam.setSortBuilders(sortBuilders);
|
|
|
|
|
|
// 4) 先从缓存中获取
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_SUGGEST;
|
|
|
JSONObject suggestResult = searchCacheService.getJSONObjectFromCache(this.searchCache, indexName, searchParam);
|
|
|
if (suggestResult != null) {
|
|
|
SearchCacheMatchLogger.doSearchCacheMatchLog("recommendBySuggestIndex", paramMap);
|
|
|
return suggestResult;
|
|
|
}
|
|
|
// 5) 调用ES执行搜索
|
|
|
// 4) 调用ES执行搜索
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_SUGGEST, searchParam);
|
|
|
if (searchResult == null) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
// 6) 构建结果加入缓存
|
|
|
suggestResult = new JSONObject();
|
|
|
JSONObject suggestResult = new JSONObject();
|
|
|
List<String> resultTerms = searchResult.getResultList().stream().map(map -> (String) map.get("keyword")).collect(Collectors.toList());
|
|
|
suggestResult.put("terms_suggestion", resultTerms);
|
|
|
searchCacheService.addJSONObjectToCache(this.searchCache, indexName, searchParam, suggestResult);
|
|
|
logger.info("[func=recommendBySuggestIndex][srcQueryWord={}][keywordsToSearch={}][resultTerms={}][cost={}]", srcQueryWord, keywordsToSearch, resultTerms,
|
|
|
System.currentTimeMillis() - begin);
|
|
|
return suggestResult;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -388,11 +362,6 @@ public class RecommendWordsService { |
|
|
|
|
|
// 缓存和列表的很难命中 所以单独自己调 而没有走ProductListServiceImpl的代码
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
|
|
|
JSONObject jsonObject = searchCacheService.getJSONObjectFromCache(this.searchCache, indexName, productIndexSearchParam);
|
|
|
if (jsonObject != null) {
|
|
|
SearchCacheMatchLogger.doSearchCacheMatchLog("aggKeywordsBySkns", queryWord);
|
|
|
return jsonObject.getString("aggKeyword");
|
|
|
}
|
|
|
|
|
|
SearchResult productIndexSearchResult = searchCommonService.doSearch(indexName, productIndexSearchParam);
|
|
|
if (productIndexSearchResult == null) {
|
...
|
...
|
@@ -400,9 +369,6 @@ public class RecommendWordsService { |
|
|
}
|
|
|
List<Map<String, Object>> productList = productIndexBaseService.buildProductReturnInfoList(productIndexSearchResult.getResultList());
|
|
|
String aggKeyword = aggKeywordsByProductList(productList);
|
|
|
jsonObject = new JSONObject();
|
|
|
jsonObject.put("aggKeyword", aggKeyword);
|
|
|
searchCacheService.addJSONObjectToCache(this.searchCache, indexName, productIndexSearchParam, jsonObject);
|
|
|
return aggKeyword;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -438,15 +404,8 @@ public class RecommendWordsService { |
|
|
searchParam.setSize(1);
|
|
|
searchParam.setFiter(QueryBuilders.termQuery("status", 1));
|
|
|
|
|
|
// 3) 先从缓存中获取
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_CONVERSION;
|
|
|
JSONObject suggestResult = searchCacheService.getJSONObjectFromCache(this.searchCache, indexName, searchParam);
|
|
|
if (suggestResult != null) {
|
|
|
SearchCacheMatchLogger.doSearchCacheMatchLog("getSuggestConversionDestBySource", queryWord);
|
|
|
return suggestResult.getString("dest");
|
|
|
}
|
|
|
|
|
|
// 4) 调用ES执行搜索
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_CONVERSION;
|
|
|
SearchResult searchResult = searchCommonService.doSearch(indexName, searchParam);
|
|
|
if (searchResult == null) {
|
|
|
return null;
|
...
|
...
|
@@ -461,10 +420,8 @@ public class RecommendWordsService { |
|
|
}
|
|
|
|
|
|
// 6) 加入缓存
|
|
|
suggestResult = new JSONObject();
|
|
|
JSONObject suggestResult = new JSONObject();
|
|
|
suggestResult.put("dest", dest);
|
|
|
searchCacheService.addJSONObjectToCache(this.searchCache, indexName, searchParam, suggestResult);
|
|
|
logger.info("[func=getSuggestConversionDestBySource][query={}][cost={}]", queryWord, System.currentTimeMillis() - begin);
|
|
|
return dest;
|
|
|
}
|
|
|
|
...
|
...
|
|