Choosing an index manager

An index manager is a component responsible for how and when changes are applied to a Lucene index. It coordinates the optimization strategy, the directory provider, and worker back ends (seen later in this chapter), and various other low-level components.

Hibernate Search includes two index manager implementations out of the box. The default is directory-based, and is a very sensible choice in most situations.

The other built-in alternative is near-real-time. It is a subclass inheriting from the directory-based index manager, but is designed for low-latency index writes. Rather than performing adds or deletes on the disk right away, this implementation queues them in the memory so they may be written more efficiently in batches.

Note

The near-real-time implementation offers greater performance than the directory-based default, but there are two trade-offs. First, the near-real-time implementation is not available when using Lucene in a clustered environment (refer to Chapter 7, Advanced Performance Strategies). Secondly, because Lucene operations are not written to disk right away, they may be permanently lost in the event of an application crash.

As with most of the configuration properties covered in this chapter, an index manager may be selected on a global default or on a per-index basis. The difference is including default, or an entity index name (for example, App) in the property:

...
<property name="hibernate.search.default.indexmanager">
   directory-based
</property>
<property name="hibernate.search.App.indexmanager">
   near-real-time
</property>
...

It is possible to write your own index manager implementation. To get a deeper sense of how index managers function, review the source code of the two implementations provided out of the box. The directory-based manager is implemented by DirectoryBasedIndexManager, and the near-real-time manager by NRTIndexManager.

Tip

An easy approach to writing a custom implementation is to subclass one of the two built-in options, and override methods only as needed. If you want to create a custom index manager completely from scratch, then it would need to implement the org.hibernate.search.indexes.spi.IndexManager interface.

Applying a custom index manager, at the global or the per-index level, works the same as the built-in options. Just set the appropriate property to your implementation's fully qualified class name (for example, com.packtpub.hibernatesearch.util.MyIndexManager) rather than the directory-based or near-real-time strings.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset