I am studying the Hibernate Search Query DSL , and I am not sure how to create queries using boolean arguments such as AND or OR.
For example, let's say that I want to return all the records of people that have the value firstName "bill" or "bob".
Following the docs of sleep mode, one example uses the bool () w / two subqueries method, for example:
QueryBuilder b = fts.getSearchFactory().buildQueryBuilder().forEntity(Person.class).get(); Query luceneQuery = b.bool() .should(b.keyword().onField("firstName").matching("bill").createQuery()) .should(b.keyword().onField("firstName").matching("bob").createQuery()) .createQuery(); logger.debug("query 1:{}", luceneQuery.toString());
This ultimately creates the lucene query that I want, but is this the correct way to use logic with sleep search? Is "should ()" the equivalent of "OR" (similarly, "must ()" matches "AND")?
In addition, recording a request in this way seems cumbersome. For example, what if I had a collection of firstNames for matching? Is this type of query a good match for DSL?
java hibernate-search
Nobodman
source share