Chapter 6. Querying with Hibernate Search
This chapter covers
- Creating and executing a Hibernate Search query
- Using pagination
- Using projection
- Converting results in a different structure (ResultTransformer)
- Defining a fetching strategy
Hibernate Search queries are the key component shielding your application from the mismatches between the index model and the domain model and helping you to migrate queries from SQL, HQL, or Criteria to full-text queries easily. Building a full-text query with Hibernate Search consists of two steps:
- Build a Lucene query to express the full-text search (either through the query parser or the programmatic API).
- Build a Hibernate Search query that wraps the Lucene query.
You may wonder why we’d use Hibernate Search to execute our query rather than plain Lucene. After all, chapters 3, 4, and 5 showed how Hibernate Search helps us index data in a regular Lucene index. Let’s imagine that we use plain Lucene to find our data and explore the problems we’d face.