...
|
...
|
@@ -18,10 +18,7 @@ import com.yoho.search.service.vo.SearchApiResult; |
|
|
import com.yoho.search.service.vo.SuggestApiResult;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.elasticsearch.index.query.MatchQueryBuilder;
|
|
|
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.elasticsearch.index.query.*;
|
|
|
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
|
|
|
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
|
|
|
import org.elasticsearch.search.sort.SortBuilder;
|
...
|
...
|
@@ -267,7 +264,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
// 2) 根据terms搜索构造搜索请求
|
|
|
final String countField = getCountField(paramMap);
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(paramMap.get(SearchRequestParams.PARAM_SEARCH_KEYWORD));
|
|
|
MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(queryWord);
|
|
|
queryBuilder.field("keyword").field("keyword.keyword_ik", 10F).field("keyword.keyword_pinyin").field("keyword.keyword_jianpin")
|
|
|
.analyzer("ik_smart")
|
|
|
.type(MultiMatchQueryBuilder.Type.BEST_FIELDS)
|
...
|
...
|
@@ -277,7 +274,11 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
searchParam.setQuery(queryBuilder);
|
|
|
searchParam.setPage(1);
|
|
|
searchParam.setSize(SMART_SUGGESTION_TERM_COUNT);
|
|
|
searchParam.setFiter(QueryBuilders.rangeQuery(countField).gte(SMART_SUGGESTION_COUNT_LIMIT));
|
|
|
|
|
|
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
|
|
boolFilter.must(QueryBuilders.rangeQuery(countField).gte(SMART_SUGGESTION_COUNT_LIMIT));
|
|
|
boolFilter.mustNot(QueryBuilders.termQuery("keyword.keyword_lowercase", queryWord.trim().toLowerCase()));
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
|
|
|
// 3) 先从缓存中获取
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_SUGGEST;
|
...
|
...
|
@@ -326,6 +327,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
final String countFiled = getCountField(paramMap);
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
List<String> keywordsInDest = Arrays.stream(dest.split(",")).map(String::toLowerCase).map(String::trim).collect(Collectors.toList());
|
|
|
keywordsInDest.remove(queryWord);
|
|
|
|
|
|
// 4.2) 设置keyword列表
|
|
|
QueryBuilder queryBuilder = QueryBuilders.termsQuery("keyword.keyword_lowercase", keywordsInDest);
|
...
|
...
|
|