Method GetReader
GetReader()
Expert: returns a readonly reader, covering all committed as well as un-committed changes to the index. This provides "near real-time" searching, in that changes made during an IndexWriter session can be quickly made available for searching without closing the writer nor calling Commit().
Note that this is functionally equivalent to calling {#commit} and then using Open(Directory, Boolean) to open a new reader. But the turarnound time of this method should be faster since it avoids the potentially costly Commit().
You must close the IndexReader returned by this method once you are done using it.
It's near real-time because there is no hard guarantee on how quickly you can get a new reader after making changes with IndexWriter. You'll have to experiment in your situation to determine if it's faster enough. As this is a new and experimental feature, please report back on your findings so we can learn, improve and iterate.
The resulting reader suppports Reopen() , but that call will simply forward back to this method (though this may change in the future).
The very first time this method is called, this writer instance will make every effort to pool the readers that it opens for doing merges, applying deletes, etc. This means additional resources (RAM, file descriptors, CPU time) will be consumed.
For lower latency on reopening a reader, you should call MergedSegmentWarmer to call MergedSegmentWarmer to pre-warm a newly merged segment before it's committed to the index. This is important for minimizing index-to-search delay after a large merge.
If an addIndexes* call is running in another thread, then this reader will only search those segments from the foreign index that have been successfully copied over, so far
.
NOTE: Once the writer is closed, any outstanding readers may continue to be used. However, if you attempt to reopen any of those readers, you'll hit an AlreadyClosedException.
NOTE: This API is experimental and might change in incompatible ways in the next release.
Declaration
public virtual IndexReader GetReader()
Returns
Type | Description |
---|---|
IndexReader | IndexReader that covers entire index plus all changes made so far by this IndexWriter instance |
GetReader(Int32)
Expert: like GetReader(), except you can specify which termInfosIndexDivisor should be used for any newly opened readers.
Declaration
public virtual IndexReader GetReader(int termInfosIndexDivisor)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | termInfosIndexDivisor | Subsambles which indexed terms are loaded into RAM. This has the same effect as TermIndexInterval except that setting must be done at indexing time while this setting can be set per reader. When set to N, then one in every N*termIndexInterval terms in the index is loaded into memory. By setting this to a value > 1 you can reduce memory usage, at the expense of higher latency when loading a TermInfo. The default value is 1. Set this to -1 to skip loading the terms index entirely. |
Returns
Type | Description |
---|---|
IndexReader |