...
|
...
|
@@ -21,6 +21,8 @@ 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.functionscore.FunctionScoreQueryBuilder;
|
|
|
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
|
|
|
import org.elasticsearch.search.sort.SortBuilder;
|
|
|
import org.elasticsearch.search.sort.SortBuilders;
|
|
|
import org.elasticsearch.search.sort.SortOrder;
|
...
|
...
|
@@ -293,14 +295,22 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
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());
|
|
|
QueryBuilder query = QueryBuilders.termsQuery("keyword.keyword_lowercase", keywordsInDest);
|
|
|
searchParam.setQuery(query);
|
|
|
QueryBuilder queryBuilder = QueryBuilders.termsQuery("keyword.keyword_lowercase", keywordsInDest);
|
|
|
FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder);
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.termQuery("type",2), ScoreFunctionBuilders.weightFactorFunction(keywordsInDest.size()));
|
|
|
for (int index = 0; index < keywordsInDest.size(); index++) {
|
|
|
// 根据顺序从高到低加分
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.termQuery("keyword.keyword_lowercase", keywordsInDest.get(index)),
|
|
|
ScoreFunctionBuilders.weightFactorFunction(keywordsInDest.size() - index));
|
|
|
}
|
|
|
|
|
|
searchParam.setQuery(functionScoreQueryBuilder);
|
|
|
searchParam.setPage(1);
|
|
|
searchParam.setSize(SMART_SUGGESTION_TERM_COUNT);
|
|
|
searchParam.setFiter(QueryBuilders.rangeQuery(getCountField(paramMap)).gte(20));
|
|
|
searchParam.setSortBuilders(Arrays.asList(SortBuilders.fieldSort("weight").order(SortOrder.DESC)));
|
|
|
searchParam.setFiter(QueryBuilders.rangeQuery(countFiled).gte(20));
|
|
|
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_SUGGEST;
|
|
|
JSONObject jsonObject = searchCacheService.getJSONObjectFromCache(indexName, searchParam);
|
...
|
...
|
@@ -310,7 +320,7 @@ public class SuggestServiceImpl implements ISuggestService, ApplicationEventPubl |
|
|
}
|
|
|
|
|
|
SearchResult searchResult = searchCommonService.doSearch(indexName, searchParam);
|
|
|
if (searchResult == null || CollectionUtils.isEmpty(searchResult.getResultList())) {
|
|
|
if (searchResult == null) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
|
...
|
...
|
|