...
|
...
|
@@ -63,10 +63,12 @@ public class SearchServiceHelper { |
|
|
queryBuilder.type(multiMatchQueryBuilderType);
|
|
|
}
|
|
|
|
|
|
// 3.如果查询的是skn,则直接走productSkn_ansj这个字段
|
|
|
if (searchCommonHelper.isQuerySkn(query)) {
|
|
|
// 3.如果查询的是skn或skuIds,则走productSkn_ansj和skuIds这个字段
|
|
|
if (searchCommonHelper.isQuerySknOrSku(query)) {
|
|
|
queryBuilder.field(ProductIndexEsField.productSkn_productSkn_ansj);
|
|
|
queryBuilder.field(ProductIndexEsField.skuIds);
|
|
|
queryBuilder.operator(MatchQueryBuilder.Operator.OR);
|
|
|
queryBuilder.minimumShouldMatch("1");
|
|
|
return queryBuilder;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -98,50 +100,11 @@ public class SearchServiceHelper { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 构造关键字查询的query的时候operator默认为or,minimum匹配度是50%
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
QueryBuilder constructOrQueryBuilder(Map<String, String> paramMap) {
|
|
|
// 0、处理查询关键字
|
|
|
String query = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_QUERY);
|
|
|
if (StringUtils.isBlank(query)) {
|
|
|
return QueryBuilders.matchAllQuery();
|
|
|
}
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_QUERY, query);
|
|
|
|
|
|
// 1、处理查询中包含性别的情况
|
|
|
searchCommonHelper.dealKeywordOfGender(query, paramMap);
|
|
|
|
|
|
// 2、构建多字段匹配【keyword需要有一个默认的查询字段以及权重设置,就可以拼接成一个sql】
|
|
|
MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(query);
|
|
|
MultiMatchQueryBuilder.Type multiMatchQueryBuilderType = searchCommonHelper.getMultiMatchQueryBuilderType();
|
|
|
if (multiMatchQueryBuilderType != null) {
|
|
|
queryBuilder.type(multiMatchQueryBuilderType);
|
|
|
}
|
|
|
|
|
|
// 3.如果查询的是skn,则直接走productSkn_ansj这个字段
|
|
|
if (searchCommonHelper.isQuerySkn(query)) {
|
|
|
queryBuilder.field(ProductIndexEsField.productSkn_productSkn_ansj);
|
|
|
queryBuilder.operator(MatchQueryBuilder.Operator.OR);
|
|
|
return queryBuilder;
|
|
|
}
|
|
|
|
|
|
// 4.设置查询字段和比重【AND表示多字段都要匹配,可提高精确度】
|
|
|
this.setDefaultSearchField(queryBuilder, paramMap);
|
|
|
queryBuilder.operator(MatchQueryBuilder.Operator.OR);
|
|
|
queryBuilder.minimumShouldMatch("75%");
|
|
|
|
|
|
return queryBuilder;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置默认搜索字段(字段+权重)
|
|
|
*
|
|
|
* @param queryBuilder
|
|
|
*/
|
|
|
public void setDefaultSearchField(MultiMatchQueryBuilder queryBuilder, Map<String, String> paramMap) {
|
|
|
private void setDefaultSearchField(MultiMatchQueryBuilder queryBuilder, Map<String, String> paramMap) {
|
|
|
List<String> fields = ISearchConstants.SEARCH_DEFAULT_FIELD;
|
|
|
for (String field : fields) {
|
|
|
String[] fieldBoost = field.split("\\^");
|
...
|
...
|
|