...
|
...
|
@@ -9,7 +9,6 @@ import com.yoho.search.core.es.model.SearchResult; |
|
|
import com.yoho.search.core.es.utils.IgnoreSomeException;
|
|
|
import com.yoho.search.service.service.SearchCacheService;
|
|
|
import com.yoho.search.service.service.SearchCommonService;
|
|
|
import com.yoho.search.service.service.SearchKeyWordService;
|
|
|
import com.yoho.search.service.servicenew.ISuggestService;
|
|
|
import com.yoho.search.service.utils.HttpServletRequestUtils;
|
|
|
import com.yoho.search.service.utils.SearchRequestParams;
|
...
|
...
|
@@ -55,8 +54,6 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
private SearchCommonService searchCommonService;
|
|
|
@Autowired
|
|
|
private SearchCacheService searchCacheService;
|
|
|
@Autowired
|
|
|
private SearchKeyWordService searchKeyWordService;
|
|
|
|
|
|
private ApplicationEventPublisher publisher;
|
|
|
|
...
|
...
|
@@ -223,6 +220,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
* @return 包括term建议和phrase建议。
|
|
|
*/
|
|
|
public JSONObject suggestByTerms(Map<String, String> paramMap) {
|
|
|
// 1) 对query进行判断 为空时不处理
|
|
|
String queryWord = paramMap.get(SearchRequestParams.PARAM_SEARCH_KEYWORD);
|
|
|
if (StringUtils.isEmpty(queryWord)) {
|
|
|
return null;
|
...
|
...
|
@@ -232,15 +230,8 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
long begin = System.currentTimeMillis();
|
|
|
logger.info("[func=suggestByTerms][query={}][begin={}]", queryWord, begin);
|
|
|
|
|
|
// 1) 对query进行分词 不考虑同义词处理 使用ik_smart
|
|
|
List<String> termsForQueryWord = searchKeyWordService.getAnalyzeTerms(queryWord, "ik_smart");
|
|
|
logger.info("[func=suggestByTerms][termsForQueryWord={}]", termsForQueryWord);
|
|
|
if (CollectionUtils.isEmpty(termsForQueryWord) || termsForQueryWord.size() == 1) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
// 2) 根据terms搜索构造搜索请求
|
|
|
SearchParam searchParam = buildSearchParamForTerms(paramMap, termsForQueryWord);
|
|
|
SearchParam searchParam = buildSearchParamForTerms(paramMap);
|
|
|
|
|
|
// 3) 先从缓存中获取
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_SUGGEST;
|
...
|
...
|
@@ -274,7 +265,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
}
|
|
|
}
|
|
|
|
|
|
private SearchParam buildSearchParamForTerms(Map<String, String> paramMap, List<String> termsForQueryWord) {
|
|
|
private SearchParam buildSearchParamForTerms(Map<String, String> paramMap) {
|
|
|
final String countField = getCountField(paramMap);
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(paramMap.get(SearchRequestParams.PARAM_SEARCH_KEYWORD));
|
...
|
...
|
|