12.5. Searching
To execute a search, create a Lucene query (see Section 15.1.1, “Building a Lucene Query Using the Lucene-based Query API”). Wrap the query in a
org.infinispan.query.CacheQuery
to get the required functionality from the Lucene-based API. The following code prepares a query against the indexed fields. Executing the code returns a list of Book
s.
Example 12.2. Using Infinispan Query to Create and Execute a Search
QueryBuilder qb = Search.getSearchManager(cache).buildQueryBuilderForClass(Book.class).get(); org.apache.lucene.search.Query query = qb .keyword() .onFields("title", "author") .matching("Java rocks!") .createQuery(); // wrap Lucene query in a org.infinispan.query.CacheQuery CacheQuery cacheQuery = Search.getSearchManager(cache).getQuery(query); List list = cacheQuery.list();