Skip to content

Commit

Permalink
!58 优化es默认搜索
Browse files Browse the repository at this point in the history
Merge pull request !58 from OceansDeep/feature/pg
  • Loading branch information
OceansDeep authored and gitee-org committed Nov 17, 2021
2 parents f61f98d + f1c0207 commit 74abc4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public <T> QueryWrapper<T> queryWrapper() {
wrapper.like(CharSequenceUtil.isNotEmpty(clientType), "o.client_type", clientType);

//按评价状态
wrapper.like(CharSequenceUtil.isNotEmpty(commentStatus), "oi.comment_status", commentStatus);
wrapper.eq(CharSequenceUtil.isNotEmpty(commentStatus), "oi.comment_status", commentStatus);

//按标签查询
if (CharSequenceUtil.isNotEmpty(tag)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,17 @@ private NativeSearchQueryBuilder createSearchQueryBuilder(EsGoodsSearchDTO searc

//关键字检索
if (CharSequenceUtil.isEmpty(searchDTO.getKeyword())) {
nativeSearchQueryBuilder.withQuery(QueryBuilders.matchAllQuery());
List<FunctionScoreQueryBuilder.FilterFunctionBuilder> filterFunctionBuilders = new ArrayList<>();
GaussDecayFunctionBuilder skuNoScore = ScoreFunctionBuilders.gaussDecayFunction("skuSource", 100, 10).setWeight(10);
FunctionScoreQueryBuilder.FilterFunctionBuilder skuNoBuilder = new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.matchAllQuery(), skuNoScore);
filterFunctionBuilders.add(skuNoBuilder);
FunctionScoreQueryBuilder.FilterFunctionBuilder[] builders = new FunctionScoreQueryBuilder.FilterFunctionBuilder[filterFunctionBuilders.size()];
filterFunctionBuilders.toArray(builders);
FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery(builders)
.scoreMode(FunctionScoreQuery.ScoreMode.SUM)
.setMinScore(2);
//聚合搜索则将结果放入过滤条件
filterBuilder.must(functionScoreQueryBuilder);
} else {
this.keywordSearch(filterBuilder, searchDTO.getKeyword());
}
Expand Down

0 comments on commit 74abc4b

Please sign in to comment.