注意: 这行得通,但对于更多的 Hibernate-esque 方法,请参阅我的其他答案
createQuery()
返回一个标准的 Lucene Query。因此,在 Lucene 中合并两个查询的典型方法是使用BooleanQuery:
Query query1 = qBuilder.keyword().onField("firstname").matching("John").createQuery();
Query query2 = qBuilder.keyword().onField("lastname").matching("Doe").createQuery();
BooleanQuery bq = new BooleanQuery();
//Assuming you want to require a match on both first and last names.
//If a match on either is enough, use BooleanClause.Occur.SHOULD
bq.add(new BooleanClause(query1, BooleanClause.Occur.MUST));
bq.add(new BooleanClause(query2, BooleanClause.Occur.MUST));