5.1. Architecture

5.1. Architecture

Hibernate Search is made of an indexing engine and an index search engine. Both are backed by Apache Lucene.

When an entity is inserted, updated or removed to/from the database, Hibernate Search™ will keep track of this event (through the Hibernate event system) and schedule an index update. When out of transaction, the update is executed right after the actual database operation. It is however recommended, for both your database and Hibernate Search, to execute your operation in a transaction (whether JDBC or JTA). When in a transaction, the index update is schedule for the transaction commit (and discarded in case of transaction rollback). You can think of this as the regular (infamous) autocommit vs transactional behavior. From a performance perspective, the in transaction mode is recommended. All the index updates are handled for you without you having to use the Apache Lucene APIs.

To interact with Apache Lucene indexes, Hibernate Search has the notion of DirectoryProvider. A directory provider will manage a given Lucene Directory type. You can configure directory providers to adjust the directory target.

Hibernate Search™ can also use a Lucene index to search an entity and return a (list of) managed entity saving you from the tedious Object / Lucene Document mapping and low level Lucene APIs. The application code use the unified org.hibernate.Query API exactly the way a HQL or native query would be done.