4.3. Reader Strategies
When executing a query, Hibernate Search uses a reader strategy to interact with the Apache Lucene indexes. Choose a reader strategy based on the profile of the application (frequent updates, read mostly, asynchronous index update, etc). For details, see Section 4.3.4, “Reader Strategy Configuration”.
4.3.1. The Shared Strategy
Using the
shared strategy, Hibernate Search shares the same IndexReader for a given Lucene index across multiple queries and threads provided that the IndexReader remains updated. If the IndexReader is not updated, a new one is opened and provided. Each IndexReader is made of several SegmentReaders. The shared strategy reopens segments that have been modified or created after the last opening and shares the already loaded segments from the previous instance. This is the default strategy.
4.3.2. The Not-shared Strategy
Using the
not-shared strategy, a Lucene IndexReader opens every time a query executes. Opening and starting up a IndexReader is an expensive operation. As a result, opening an IndexReader for each query execution is not an efficient strategy.
4.3.3. Custom Reader Strategies
You can write a custom reader strategy using an implementation of
org.hibernate.search.reader.ReaderProvider. The implementation must be thread safe.
4.3.4. Reader Strategy Configuration
Change the strategy from the default (
shared) to not-shared as follows:
hibernate.search.[default|<indexname>].reader.strategy = not-shared
Alternately, customize the reader strategy by replacing
my.corp.myapp.CustomReaderProvider with the custom strategy implementation:
hibernate.search.[default|<indexname>].reader.strategy = my.corp.myapp.CustomReaderProvider