Chapter 11. Accessing Lucene natively
This chapter covers
- Utilizing the SearchFactory
- Accessing Lucene directories
- Working with
- DirectoryProviders
- Exploiting projections
If you have not realized it by now, or you just started reading this chapter first, Lucene is the driving force behind the Hibernate Search framework. The entire book up to this point has been dedicated to helping you understand how to implement Hibernate Search in your application. Eventually, everyone has questions related to working with Lucene directly. We hear questions similar to the following all the time:
- Hibernate Search’s default constructs won’t work for me. Now what do I do?
- I know Hibernate Search takes care of a lot of things for me, but I need to get at Lucene itself and work with its native constructs. How can I do that?
- Can I get an instance of a Lucene Directory object so I can work at a lower level?
- Hibernate Search has sharded my entity into three separate directories. Is it possible to work with them as a single object? Can I improve retrieval performance?
Do any of these sound familiar? We’re going to answer these questions in this chapter. We’ll start by looking at Hibernate Search’s SearchFactory, which is the key entry point to Lucene. It allows access to Directory objects and IndexReaders. We’ll look at the effects that sharding has on these classes, and along the way we’ll also see what goes on when indexing multiple entities.