2 回答
TA贡献1802条经验 获得超5个赞
尝试这个:
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder
.filter(QueryBuilders.termQuery("user", "kimchy"))
.filter(QueryBuilders.termQuery("city", "london"));
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(boolQueryBuilder);
的filter/must/should方法BoolQueryBuilder,取决于你想要哪个上下文,如果你想要“或”,你可以使用should。
TA贡献2011条经验 获得超2个赞
大家可以试试这个。
BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
foreach (var term in (s + ',' + t).Split(','))
{
booleanQuery.add(new TermQuery(new Term("content", term)), BooleanClause.Occur.SHOULD);
}
//booleanQuery.add(new TermQuery(new Term("content", s)), BooleanClause.Occur.MUST);
//booleanQuery.add(new TermQuery(new Term("content", t)), BooleanClause.Occur.MUST);
TopDocs hits = searcher.search(booleanQuery.build(), int.MaxValue);
添加回答
举报