5.2.1. Directory configuration
Apache Lucene has a notion of Directory where the index is stored. The Directory implementation can be customized but Lucene comes bundled with a file system and a full memory implementation. Hibernate Search™ has the notion of DirectoryProvider that handle the configuration and the initialization of the Lucene Directory.
| Class | description | Properties |
|---|---|---|
| org.hibernate.search.store.FSDirectoryProvider |
File system based directory. The directory used will be <indexBase>/<@Indexed.name>
|
indexBase: Base directory
|
| org.hibernate.search.store.RAMDirectoryProvider |
Memory based directory, the directory will be uniquely indentified by the @Indexed.name element
|
none |
Table 5.1. List of built-in Directory Providers
If the built-in directory providers does not fit your needs, you can write your own directory provider by implementing the org.hibernate.store.DirectoryProvider interface
Each indexed entity is associated to a Lucene index (an index can be shared by several entities but this is not usually the case). You can configure the index through properties prefixed by hibernate.search.indexname. Default properties inherited to all indexes can be defined using the prefix hibernate.search.default.
To define the directory provider of a given index, you use the hibernate.search.
indexname.directory_provider
hibernate.search.default.directory_provider org.hibernate.search.store.FSDirectoryProvider hibernate.search.default.indexDir=/usr/lucene/indexes hibernate.search.Rules.directory_provider org.hibernate.search.store.RAMDirectoryProvider
applied on
@Indexed(name="Status")
public class Status { ... }
@Indexed(name="Rules")
public class Rule { ... }
will create a file system directory in /usr/lucene/indexes/Status where the Status entities will be indexed, and use an in memory directory named Rules where Rule entities will be indexed.
So you can easily defined common rules like the directory provider and base directory, and overide those default later on on a per index basis.
Writing your own DirectoryProvider, you can benefit this configuration mechanism too.