Apache Lucene has a notion of Directory
to store
the index files. The Directory
implementation can
be customized, but Lucene comes bundled with a file system
(FSDirectoryProvider
) and an in memory
(RAMDirectoryProvider
) implementation.
DirectoryProvider
s are the Hibernate Search abstraction
around a Lucene Directory
and handle the
configuration and the initialization of the underlying Lucene resources.
Table 3.1, “List of built-in Directory Providers” shows the list of the
directory providers bundled with Hibernate Search.
Table 3.1. List of built-in Directory Providers
Class | Description | Properties |
---|---|---|
org.hibernate.search.store.FSDirectoryProvider | File system based directory. The directory used will be <indexBase>/< indexName > |
|
org.hibernate.search.store.FSMasterDirectoryProvider |
File system based directory. Like FSDirectoryProvider. It also copies the index to a source directory (aka copy directory) on a regular basis. The recommended value for the refresh period is (at least) 50% higher that the time to copy the information (default 3600 seconds - 60 minutes). Note that the copy is based on an incremental copy mechanism reducing the average copy time. DirectoryProvider typically used on the master node in a JMS back end cluster. The |
|
org.hibernate.search.store.FSSlaveDirectoryProvider |
File system based directory. Like FSDirectoryProvider, but retrieves a master version (source) on a regular basis. To avoid locking and inconsistent search results, 2 local copies are kept. The recommended value for the refresh period is (at least) 50% higher that the time to copy the information (default 3600 seconds - 60 minutes). Note that the copy is based on an incremental copy mechanism reducing the average copy time. DirectoryProvider typically used on slave nodes using a JMS back end. The
|
|
org.hibernate.search.store.RAMDirectoryProvider | Memory based directory, the directory will be uniquely
identified (in the same deployment unit) by the
@Indexed.index element
|
none |
If the built-in directory providers do 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
Example 3.1. Configuring directory providers
hibernate.search.default.directory_provider org.hibernate.search.store.FSDirectoryProvider hibernate.search.default.indexBase=/usr/lucene/indexes hibernate.search.Rules.directory_provider org.hibernate.search.store.RAMDirectoryProvider
applied on
Example 3.2. Specifying the index name using the index
parameter of @Indexed
@Indexed(index="Status") public class Status { ... } @Indexed(index="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.
You can easily define common rules like the directory provider and base directory, and override those defaults later on on a per index basis.
Writing your own DirectoryProvider
, you can
utilize this configuration mechanism as well.