Class IndexReader
Index
There are two different types of Index
- Atomic
Reader : These indexes do not consist of several sub-readers, they are atomic. They support retrieval of stored fields, doc values, terms, and postings. - Composite
Reader : Instances (like DirectoryReader ) of this reader can only be used to get stored fields from the underlying AtomicReader s, but it is not possible to directly retrieve postings. To do that, get the sub-readers via GetSequential . Alternatively, you can mimic an AtomicSub Readers() Reader (with a serious slowdown), by wrapping composite readers with SlowComposite .Reader Wrapper
IndexDirectoryReader.Open()
methods,
e.g. Open(Directory). 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: Index
Namespace: Lucene.Net.Index
Assembly: Lucene.Net.dll
Syntax
public abstract class IndexReader : IDisposable
Properties
| Improve this Doc View SourceCombinedCoreAndDeletesKey
Expert: Returns a key for this Index
Declaration
public virtual object CombinedCoreAndDeletesKey { get; }
Property Value
Type | Description |
---|---|
System. |
Context
Expert: Returns the root Index
Iff this reader is composed of sub
readers, i.e. this reader being a composite reader, this method returns a
Composite
Note: Any of the sub-Composite
Declaration
public abstract IndexReaderContext Context { get; }
Property Value
Type | Description |
---|---|
Index |
CoreCacheKey
Expert: Returns a key for this Index
Declaration
public virtual object CoreCacheKey { get; }
Property Value
Type | Description |
---|---|
System. |
HasDeletions
Returns true
if any documents have been deleted. Implementers should
consider overriding this property if Max
Declaration
public virtual bool HasDeletions { get; }
Property Value
Type | Description |
---|---|
System. |
Leaves
Returns the reader's leaves, or itself if this reader is atomic.
This is a convenience method calling this.Context.Leaves
.
Declaration
public IList<AtomicReaderContext> Leaves { get; }
Property Value
Type | Description |
---|---|
IList<Atomic |
See Also
| Improve this Doc View SourceMaxDoc
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.
Declaration
public abstract int MaxDoc { get; }
Property Value
Type | Description |
---|---|
System. |
NumDeletedDocs
Returns the number of deleted documents.
Declaration
public int NumDeletedDocs { get; }
Property Value
Type | Description |
---|---|
System. |
NumDocs
Returns the number of documents in this index.
Declaration
public abstract int NumDocs { get; }
Property Value
Type | Description |
---|---|
System. |
RefCount
Expert: returns the current refCount for this reader
Declaration
public int RefCount { get; }
Property Value
Type | Description |
---|---|
System. |
Methods
| Improve this Doc View SourceAddReaderClosedListener(IndexReader.IReaderClosedListener)
Expert: adds a Index
Declaration
public void AddReaderClosedListener(IndexReader.IReaderClosedListener listener)
Parameters
Type | Name | Description |
---|---|---|
Index |
listener |
DecRef()
Expert: decreases the Ref
Declaration
public void DecRef()
See Also
| Improve this Doc View SourceDispose()
Closes files associated with this index. Also saves any new deletions to disk. No other methods should be called after this has been called.
Declaration
public void Dispose()
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 base.Dispose(disposing)
to close files associated with the
underlying Index
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System. |
disposing |
|
DocFreq(Term)
Returns the number of documents containing the
term
. This method returns 0 if the term or
field does not exist. This method does not take into
account deleted documents that have not yet been merged
away.
Declaration
public abstract int DocFreq(Term term)
Parameters
Type | Name | Description |
---|---|---|
Term | term |
Returns
Type | Description |
---|---|
System. |
See Also
| Improve this Doc View SourceDoClose()
Implements close.
Declaration
protected abstract void DoClose()
Document(Int32)
Returns the stored fields of the n
th
Document in this index. This is just
sugar for using Document
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 Get
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.
Declaration
public Document Document(int docID)
Parameters
Type | Name | Description |
---|---|---|
System. |
docID |
Returns
Type | Description |
---|---|
Document |
Document(Int32, ISet<String>)
Like Document(Int32) but only loads the specified fields. Note that this is simply sugar for DocumentStoredFieldVisitor(ISet<String>).
Declaration
public Document Document(int docID, ISet<string> fieldsToLoad)
Parameters
Type | Name | Description |
---|---|---|
System. |
docID | |
ISet<System. |
fieldsToLoad |
Returns
Type | Description |
---|---|
Document |
Document(Int32, 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
Document(Int32). If you want to load a subset, use
Document
Declaration
public abstract void Document(int docID, StoredFieldVisitor visitor)
Parameters
Type | Name | Description |
---|---|---|
System. |
docID | |
Stored |
visitor |
EnsureOpen()
Throws
Declaration
protected void EnsureOpen()
Equals(Object)
Determines whether two object instances are equal.
For caching purposes, Index
Declaration
public override sealed bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System. |
obj |
Returns
Type | Description |
---|---|
System. |
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.
Declaration
public abstract int GetDocCount(string field)
Parameters
Type | Name | Description |
---|---|---|
System. |
field |
Returns
Type | Description |
---|---|
System. |
See Also
| Improve this Doc View SourceGetHashCode()
Serves as the default hash function.
For caching purposes, Index
Declaration
public override sealed int GetHashCode()
Returns
Type | Description |
---|---|
System. |
GetSumDocFreq(String)
Returns the sum of Doc
Declaration
public abstract long GetSumDocFreq(string field)
Parameters
Type | Name | Description |
---|---|---|
System. |
field |
Returns
Type | Description |
---|---|
System. |
See Also
| Improve this Doc View SourceGetSumTotalTermFreq(String)
Returns the sum of Total
Declaration
public abstract long GetSumTotalTermFreq(string field)
Parameters
Type | Name | Description |
---|---|---|
System. |
field |
Returns
Type | Description |
---|---|
System. |
See Also
| Improve this Doc View SourceGetTermVector(Int32, String)
Retrieve term vector for this document and field, or
null
if term vectors were not indexed. The returned
Fields instance acts like a single-document inverted
index (the docID will be 0).
Declaration
public Terms GetTermVector(int docID, string field)
Parameters
Type | Name | Description |
---|---|---|
System. |
docID | |
System. |
field |
Returns
Type | Description |
---|---|
Terms |
GetTermVectors(Int32)
Retrieve term vectors for this document, or null
if
term vectors were not indexed. The returned Fields
instance acts like a single-document inverted index
(the docID will be 0).
Declaration
public abstract Fields GetTermVectors(int docID)
Parameters
Type | Name | Description |
---|---|---|
System. |
docID |
Returns
Type | Description |
---|---|
Fields |
IncRef()
Expert: increments the Ref
Declaration
public void IncRef()
See Also
| Improve this Doc View SourceOpen(IndexCommit)
Expert: returns an Index
Declaration
public static DirectoryReader Open(IndexCommit commit)
Parameters
Type | Name | Description |
---|---|---|
Index |
commit | the commit point to open |
Returns
Type | Description |
---|---|
Directory |
Open(IndexCommit, Int32)
Expert: returns an IndextermInfosIndexDivisor
.
Declaration
public static DirectoryReader Open(IndexCommit commit, int termInfosIndexDivisor)
Parameters
Type | Name | Description |
---|---|---|
Index |
commit | the commit point to open |
System. |
termInfosIndexDivisor | Subsamples which indexed
terms are loaded into RAM. this has the same effect as
Term |
Returns
Type | Description |
---|---|
Directory |
Open(IndexWriter, Boolean)
Open a near real time Index
Declaration
public static DirectoryReader Open(IndexWriter writer, bool applyAllDeletes)
Parameters
Type | Name | Description |
---|---|---|
Index |
writer | The Index |
System. |
applyAllDeletes | If true, all buffered deletes will
be applied (made visible) in the returned reader. If
false, the deletes are not applied but remain buffered
(in Index |
Returns
Type | Description |
---|---|
Directory |
The new Index |
See Also
Open(Directory)
Returns a Index
Declaration
public static DirectoryReader Open(Directory directory)
Parameters
Type | Name | Description |
---|---|---|
Directory | directory | the index directory |
Returns
Type | Description |
---|---|
Directory |
Open(Directory, Int32)
Expert: Returns a IndextermInfosIndexDivisor
.
Declaration
public static DirectoryReader Open(Directory directory, int termInfosIndexDivisor)
Parameters
Type | Name | Description |
---|---|---|
Directory | directory | the index directory |
System. |
termInfosIndexDivisor | Subsamples which indexed
terms are loaded into RAM. this has the same effect as
Term |
Returns
Type | Description |
---|---|
Directory |
RegisterParentReader(IndexReader)
Expert: this method is called by Index
Declaration
public void RegisterParentReader(IndexReader reader)
Parameters
Type | Name | Description |
---|---|---|
Index |
reader |
RemoveReaderClosedListener(IndexReader.IReaderClosedListener)
Expert: remove a previously added Index
Declaration
public void RemoveReaderClosedListener(IndexReader.IReaderClosedListener listener)
Parameters
Type | Name | Description |
---|---|---|
Index |
listener |
TotalTermFreq(Term)
Returns the total number of occurrences of term
across all
documents (the sum of the Freq for each doc that has this term). This
will be -1 if the codec doesn't support this measure. Note that, like other
term measures, this measure does not take deleted documents into account.
Declaration
public abstract long TotalTermFreq(Term term)
Parameters
Type | Name | Description |
---|---|---|
Term | term |
Returns
Type | Description |
---|---|
System. |
TryIncRef()
Expert: increments the Reftrue
iff the Reffalse
.
If this method returns false
the reader is either
already disposed or is currently being disposed. Either way this
reader instance shouldn't be used by an application unless
true
is returned.
Ref
Declaration
public bool TryIncRef()
Returns
Type | Description |
---|---|
System. |