combine queries in hibernate search

hibernate, hibernate-search, lucene

Solution

Note: This works, but for the more Hibernate-esque approach, see my other answer

`createQuery()` returns a standard Lucene Query. So, the typical way to merge two queries in Lucene would be with a 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));

Problem

is there a possibility in Hibernate Search (lucene) to combine two different queries. For example when I want to search with 2 fields that should have one corresponding matching value: ``` firstname - John lastname - Doe qBuilder.keyword().onField("firstname").matching("John").createQuery()); qBuilder.keyword().onField("lastname").matching("Doe").createQuery()); ``` is a way to make from this one query?

Original source