6.3. Running Infinispan Query DSL-based Queries
Once Infinispan Query DSL-based queries have been enabled, obtain a
QueryFactory
from the Search
in order to run a DSL-based query.
Obtain a QueryFactory for a Cache
In Library mode, obtain a QueryFactory
as follows:
QueryFactory qf = org.infinispan.query.Search.getQueryFactory(Cache<?, ?> cache)
QueryFactory qf = org.infinispan.query.Search.getQueryFactory(Cache<?, ?> cache)
Example 6.1. Constructing a DSL-based Query
When using Remote Querying in Remote Client-Server mode, the
Search
object resides in package org.infinispan.client.hotrod
. See the example in Section 7.2, “Performing Remote Queries via the Hot Rod Java Client” for details.
It is also possible to combine multiple conditions with boolean operators, including sub-conditions. For example:
Example 6.2. Combining Multiple Conditions
This query API simplifies the way queries are written by not exposing the user to the low level details of constructing Lucene query objects. It also has the benefit of being available to remote Hot Rod clients.
The following example shows how to write a query for the
Book
entity.
Example 6.3. Querying the Book
Entity