Class IndexReader
IndexReader is an abstract class, providing an interface for accessing an index. Search of an index is done entirely through this abstract interface, so that any subclass which implements it is searchable.
There are two different types of IndexReaders:
- AtomicReader: These indexes do not consist of several sub-readers, they are atomic. They support retrieval of stored fields, doc values, terms, and postings.
- CompositeReader: Instances (like DirectoryReader) of this reader can only be used to get stored fields from the underlying AtomicReaders, but it is not possible to directly retrieve postings. To do that, get the sub-readers via GetSequentialSubReaders(). Alternatively, you can mimic an AtomicReader (with a serious slowdown), by wrapping composite readers with SlowCompositeReaderWrapper.
IndexReader instances for indexes on disk are usually constructed
with a call to one of the static DirectoryReader.Open()
methods,
e.g. Open(Directory). DirectoryReader inherits
the CompositeReader abstract class, it is not possible to directly get postings.
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
Assembly: DistributedLucene.Net.dll
Syntax
public abstract class IndexReader : IDisposable, IIdentifiableSurrogate
Constructors
Name | Description |
---|---|
IndexReader() | |
IndexReader(String, IRPCTransport, Type) |
Fields
Name | Description |
---|---|
_basesurrogateObject | |
Partitions |
Properties
Name | Description |
---|---|
AllowPartialResults | Set to false to return an overall failure if the request would produce partial results. Set to true, which will allow partial results in the case of partial cluster. |
CombinedCoreAndDeletesKey | Expert: Returns a key for this IndexReader that also includes deletions, so IFieldCache/CachingWrapperFilter can find it again. This key must not have Equals()/GetHashCode() methods, so "equals" means "identical". |
Context | Expert: Returns the root IndexReaderContext for this IndexReader's sub-reader tree. Iff this reader is composed of sub readers, i.e. this reader being a composite reader, this method returns a CompositeReaderContext holding the reader's direct children as well as a view of the reader tree's atomic leaf contexts. All sub- IndexReaderContext instances referenced from this readers top-level context are private to this reader and are not shared with another context tree. For example, IndexSearcher uses this API to drive searching by one atomic leaf reader at a time. If this reader is not composed of child readers, this method returns an AtomicReaderContext. Note: Any of the sub-CompositeReaderContext instances referenced from this top-level context do not support Leaves. Only the top-level context maintains the convenience leaf-view for performance reasons. |
CoreCacheKey | Expert: Returns a key for this IndexReader, so IFieldCache/CachingWrapperFilter can find it again. This key must not have Equals()/GetHashCode() methods, so "equals" means "identical". |
HasDeletions | Returns |
Leaves | Returns the reader's leaves, or itself if this reader is atomic.
This is a convenience method calling |
LuceneRPCTransportLayer | |
MaxDoc | Returns one greater than the largest possible document number. this may be used to, e.g., determine how big to allocate an array which will have an element for every document number in an index. |
NumDeletedDocs | Returns the number of deleted documents. |
NumDocs | Returns the number of documents in this index. |
RefCount | Expert: returns the current refCount for this reader |
Methods
Name | Description |
---|---|
AddReaderClosedListener(IndexReader.IReaderClosedListener) | Expert: adds a IndexReader.IReaderClosedListener. The provided listener will be invoked when this reader is closed. @lucene.experimental |
DecRef() | Expert: decreases the RefCount of this IndexReader instance. If the RefCount drops to 0, then this reader is disposed. If an exception is hit, the RefCount is unchanged. |
Dispose() | Closes files associated with this index. Also saves any new deletions to disk. No other methods should be called after this has been called. |
Dispose(Boolean) | Closes files associated with this index.
This method implements the disposable pattern.
It may be overridden to dispose any managed or unmanaged resources,
but be sure to call |
DocFreq(Term) | Returns the number of documents containing the
|
DoClose() | Implements close. |
Document(Int64) | Returns the stored fields of the NOTE: for performance reasons, this method does not check if the requested document is deleted, and therefore asking for a deleted document may yield unspecified results. Usually this is not required, however you can test if the doc is deleted by checking the IBits returned from GetLiveDocs(IndexReader). NOTE: only the content of a field is returned, if that field was stored during indexing. Metadata like boost, omitNorm, IndexOptions, tokenized, etc., are not preserved. |
Document(Int64, ISet<String>) | Like Document(Int64) but only loads the specified fields. Note that this is simply sugar for DocumentStoredFieldVisitor(ISet<String>). |
Document(Int64, StoredFieldVisitor) | Expert: visits the fields of a stored document, for
custom processing/loading of each field. If you
simply want to load all fields, use
|
EnsureOpen() | Throws |
GetDocCount(String) | Returns the number of documents that have at least one term for this field, or -1 if this measure isn't stored by the codec. Note that, just like other term measures, this measure does not take deleted documents into account. |
GetMaxDocsPerIndex() | |
GetSumDocFreq(String) | Returns the sum of DocFreq for all terms in this field, or -1 if this measure isn't stored by the codec. Note that, just like other term measures, this measure does not take deleted documents into account. |
GetSumTotalTermFreq(String) | Returns the sum of TotalTermFreq for all terms in this field, or -1 if this measure isn't stored by the codec (or if this fields omits term freq and positions). Note that, just like other term measures, this measure does not take deleted documents into account. |
GetSurrogateId() | |
GetTermVector(Int64, String) | Retrieve term vector for this document and field, or
|
GetTermVectors(Int64) | Retrieve term vectors for this document, or |
IncRef() | Expert: increments the RefCount of this IndexReader instance. RefCounts are used to determine when a reader can be disposed safely, i.e. as soon as there are no more references. Be sure to always call a corresponding DecRef(), in a finally clause; otherwise the reader may never be disposed. Note that Dispose(Boolean) simply calls DecRef(), which means that the IndexReader will not really be disposed until DecRef() has been called for all outstanding references. |
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. |
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 |
RegisterParentReader(IndexReader) | Expert: this method is called by IndexReaders which wrap other readers
(e.g. CompositeReader or |
RemoveReaderClosedListener(IndexReader.IReaderClosedListener) | Expert: remove a previously added IndexReader.IReaderClosedListener. @lucene.experimental |
TotalTermFreq(Term) | Returns the total number of occurrences of |
TryIncRef() | Expert: increments the RefCount of this IndexReader
instance only if the IndexReader has not been disposed yet
and returns RefCounts are used to determine when a reader can be disposed safely, i.e. as soon as there are no more references. Be sure to always call a corresponding DecRef(), in a finally clause; otherwise the reader may never be disposed. Note that Dispose(Boolean) simply calls DecRef(), which means that the IndexReader will not really be disposed until DecRef() has been called for all outstanding references. |