Show Table of Contents
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 Books.
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();
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.