Class DirectoryReader
DirectoryReader is an implementation of CompositeReader that can read indexes in a Directory.
DirectoryReader instances are usually constructed with a call to
one of the static Open()
methods, e.g. Open(Directory).
For efficiency, in this API documents are often referred to via document numbers, non-negative integers which each name a unique document in the index. These document numbers are ephemeral -- they may change as documents are added to and deleted from an index. Clients should thus not rely on a given document having the same number between sessions.
NOTE: IndexReader instances are completely thread safe, meaning multiple threads can call any of its methods, concurrently. If your application requires external synchronization, you should not synchronize on the IndexReader instance; use your own (non-Lucene) objects instead.
Inheritance
Inherited Members
Assembly: DistributedLucene.Net.dll
Syntax
public abstract class DirectoryReader : BaseCompositeReader<AtomicReader>, IIdentifiableSurrogate
Constructors
Name | Description |
---|---|
DirectoryReader(Directory, AtomicReader[]) | Expert: Constructs a DirectoryReader on the given |
DirectoryReader(String, NCacheDirectory, Type) |
Fields
Name | Description |
---|---|
DEFAULT_TERMS_INDEX_DIVISOR | Default termInfosIndexDivisor. |
m_directory | The index directory. |
Properties
Name | Description |
---|---|
AllowPartialResutls | Set behaviour of result in case of partial cluster |
Directory | Returns the directory this index resides in. |
IndexCommit | Expert: return the IndexCommit that this reader has opened. @lucene.experimental |
Version | Version number when this IndexReader was opened. This method returns the version recorded in the commit that the reader opened. This version is advanced every time a change is made with IndexWriter. |
Methods
Name | Description |
---|---|
DoOpenIfChanged() | Implement this method to support OpenIfChanged(DirectoryReader).
If this reader does not support reopen, return |
DoOpenIfChanged(IndexCommit) | Implement this method to support OpenIfChanged(DirectoryReader, IndexCommit).
If this reader does not support reopen from a specific IndexCommit,
throw |
DoOpenIfChanged(IndexWriter, Boolean) | Implement this method to support OpenIfChanged(DirectoryReader, IndexWriter, Boolean).
If this reader does not support reopen from IndexWriter,
throw |
IndexExists(Directory) | Returns |
IsCurrent() | Check whether any new changes have occurred to the index since this reader was opened. If this reader was created by calling an overload of Open(Directory), then this method checks if any further commits (see Commit()) have occurred in the directory. If instead this reader is a near real-time reader
(ie, obtained by a call to
Open(IndexWriter, Boolean), or by calling an overload of OpenIfChanged(DirectoryReader)
on a near real-time reader), then this method checks if
either a new commit has occurred, or any new
uncommitted changes have taken place via the writer.
Note that even if the writer has only performed
merging, this method will still return In any event, if this returns |
ListCommits(Directory) | Returns all commit points that exist in the Directory. Normally, because the default is KeepOnlyLastCommitDeletionPolicy, there would be only one commit point. But if you're using a custom IndexDeletionPolicy then there could be many commits. Once you have a given commit, you can open a reader on it by calling Open(IndexCommit) There must be at least one commit in the Directory, else this method throws IndexNotFoundException. Note that if a commit is in progress while this method is running, that commit may or may not be returned. |
Open(IndexCommit) | Expert: returns an IndexReader reading the index in the given IndexCommit. |
Open(IndexCommit, Int32) | Expert: returns an IndexReader reading the index in the given
IndexCommit and |
Open(IndexWriter, Boolean) | Open a near real time IndexReader from the IndexWriter. @lucene.experimental |
Open(Directory) | Returns a IndexReader reading the index in the given Directory |
Open(Directory, Int32) | Expert: Returns a IndexReader reading the index in the given Directory with the given termInfosIndexDivisor. |
OpenIfChanged(DirectoryReader) | If the index has changed since the provided reader was
opened, open and return a new reader; else, return
This method is typically far less costly than opening a fully new DirectoryReader as it shares resources (for example sub-readers) with the provided DirectoryReader, when possible. The provided reader is not disposed (you are responsible for doing so); if a new reader is returned you also must eventually dispose it. Be sure to never dispose a reader while other threads are still using it; see SearcherManager to simplify managing this. |
OpenIfChanged(DirectoryReader, IndexCommit) | If the IndexCommit differs from what the
provided reader is searching, open and return a new
reader; else, return |
OpenIfChanged(DirectoryReader, IndexWriter, Boolean) | Expert: If there changes (committed or not) in the
IndexWriter versus what the provided reader is
searching, then open and return a new
IndexReader searching both committed and uncommitted
changes from the writer; else, return 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(). 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 fast enough. As this is a new and experimental feature, please report back on your findings so we can learn, improve and iterate. 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 (on IndexWriterConfig) 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 disposed, any
outstanding readers may continue to be used. However,
if you attempt to reopen any of those readers, you'll
hit an @lucene.experimental |