Authored by wangnan

修改suggest逻辑,用wildcard

... ... @@ -84,34 +84,39 @@ public class SearchServiceHelper {
return QueryBuilders.matchAllQuery();
}
//构建MultiMatch
MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(keyword);
if (isSuggest) {
WildcardQueryBuilder wildcardQueryBuilder = QueryBuilders.wildcardQuery("suggest", "*" + keyword + "*");
return wildcardQueryBuilder;
} else {
//构建MultiMatch
MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(keyword);
//获取MultiMatchQueryType
MultiMatchQueryBuilder.Type multiMatchQueryBuilderType = this.getMultiMatchQueryBuilderType();
if (multiMatchQueryBuilderType != null) {
queryBuilder.type(multiMatchQueryBuilderType);
}
//获取MultiMatchQueryType
MultiMatchQueryBuilder.Type multiMatchQueryBuilderType = this.getMultiMatchQueryBuilderType();
if (multiMatchQueryBuilderType != null) {
queryBuilder.type(multiMatchQueryBuilderType);
}
if (paramMap.containsKey("queryField") && StringUtils.isNotBlank(paramMap.get("queryField"))) {
String[] fields = paramMap.get("queryField").split(",");
for (int i = 0; i < fields.length; i++) {
queryBuilder.field(fields[i]);
if (paramMap.containsKey("queryField") && StringUtils.isNotBlank(paramMap.get("queryField"))) {
String[] fields = paramMap.get("queryField").split(",");
for (int i = 0; i < fields.length; i++) {
queryBuilder.field(fields[i]);
}
} else {
//设置searchfield和权重
this.setDefaultSearchField(queryBuilder, indexName);
}
} else {
//设置searchfield和权重
this.setDefaultSearchField(queryBuilder, indexName, isSuggest);
}
//设置Operator
if (ISearchConstans.SEARCH_OPERATOR.equalsIgnoreCase("or")) {
queryBuilder.operator(MatchQueryBuilder.Operator.OR);
queryBuilder.minimumShouldMatch(ISearchConstans.SEARCH_MINIMUM_SHOULD_MATCH);
} else {
queryBuilder.operator(MatchQueryBuilder.Operator.AND);
//设置Operator
if (ISearchConstans.SEARCH_OPERATOR.equalsIgnoreCase("or")) {
queryBuilder.operator(MatchQueryBuilder.Operator.OR);
queryBuilder.minimumShouldMatch(ISearchConstans.SEARCH_MINIMUM_SHOULD_MATCH);
} else {
queryBuilder.operator(MatchQueryBuilder.Operator.AND);
}
return queryBuilder;
}
return queryBuilder;
}
... ... @@ -223,17 +228,18 @@ public class SearchServiceHelper {
*
* @param queryBuilder
*/
private void setDefaultSearchField(MultiMatchQueryBuilder queryBuilder, String indexName, boolean isSuggest) {
private void setDefaultSearchField(MultiMatchQueryBuilder queryBuilder, String indexName) {
List<String> fields = new ArrayList<>();
if (isSuggest) {
fields = ISearchConstans.SEARCH_SUGGUST_FIELD;
} else if (indexName.equals(ISearchConstans.INDEX_NAME_BIZAREA)) {
if (indexName.equals(ISearchConstans.INDEX_NAME_BIZAREA)) {
fields = ISearchConstans.SEARCH_DEFAULT_FIELD_BIZAREA;
} else if (indexName.equals(ISearchConstans.INDEX_NAME_COMMENT)) {
}
if (indexName.equals(ISearchConstans.INDEX_NAME_COMMENT)) {
fields = ISearchConstans.SEARCH_DEFAULT_FIELD_COMMENT;
} else if (indexName.equals(ISearchConstans.INDEX_NAME_LINE)) {
}
if (indexName.equals(ISearchConstans.INDEX_NAME_LINE)) {
fields = ISearchConstans.SEARCH_DEFAULT_FIELD_LINE;
} else if (indexName.equals(ISearchConstans.INDEX_NAME_STORE)) {
}
if (indexName.equals(ISearchConstans.INDEX_NAME_STORE)) {
fields = ISearchConstans.SEARCH_DEFAULT_FIELD_STORE;
}
if (indexName.equals(ISearchConstans.INDEX_NAME_TOPIC)) {
... ...