...
|
...
|
@@ -56,7 +56,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@SearchCacheAble(cacheInMinute = 60, cacheName = "SUGGEST", includeParams = { "query", "app_type", "contain_global", "size" }, returnClass = SuggestApiResult.class)
|
|
|
@SearchCacheAble(cacheInMinute = 60, cacheName = "SUGGEST", includeParams = { "query", "app_type", "contain_global"}, returnClass = SuggestApiResult.class)
|
|
|
public SuggestApiResult suggest(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
logger.info("[func=suggest][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis());
|
...
|
...
|
@@ -72,7 +72,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
}
|
|
|
|
|
|
// 2)构建查询参数
|
|
|
SearchParam searchParam = buildSuggestSearchParam(paramMap);
|
|
|
SearchParam searchParam = this.buildSuggestSearchParam(paramMap);
|
|
|
|
|
|
// 3)进行ES检索
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_SUGGEST, searchParam);
|
...
|
...
|
@@ -127,7 +127,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
newParamMap.putAll(paramMap);
|
|
|
newParamMap.put(SearchRequestParams.PARAM_SEARCH_QUERY, newKeyword);
|
|
|
|
|
|
SearchParam newSearchParam = buildSuggestSearchParam(newParamMap);
|
|
|
SearchParam newSearchParam = this.buildSuggestSearchParam(newParamMap);
|
|
|
return searchCommonService.doSearch(ISearchConstants.INDEX_NAME_SUGGEST, newSearchParam);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("Get new suggest result by keyword [" + newKeyword + "] failed!", e);
|
...
|
...
|
@@ -144,18 +144,11 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
private SearchParam buildSuggestSearchParam(Map<String, String> paramMap) {
|
|
|
String keyword = paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY).toLowerCase();
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
int size = SearchRequestParams.RESULT_SIZE_SUGGEST;
|
|
|
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_SIZE)) {
|
|
|
size = Integer.parseInt(paramMap.get(SearchRequestParams.PARAM_SEARCH_SIZE));
|
|
|
}
|
|
|
if (size > 10) {
|
|
|
size = 10;
|
|
|
}
|
|
|
QueryBuilder query = QueryBuilders.boolQuery().should(QueryBuilders.prefixQuery("keyword", keyword)).should(QueryBuilders.prefixQuery("keyword.keyword_pinyin", keyword))
|
|
|
.should(QueryBuilders.prefixQuery("keyword.keyword_jianpin", keyword));
|
|
|
searchParam.setQuery(query);
|
|
|
searchParam.setSize(10);
|
|
|
searchParam.setOffset(0);
|
|
|
searchParam.setSize(10);
|
|
|
|
|
|
// count数量要>=2
|
|
|
final String countEsField = getCountField(paramMap);
|
...
|
...
|
|