Class StandardDirectoryReader
- java.lang.Object
-
- org.apache.lucene.index.IndexReader
-
- org.apache.lucene.index.CompositeReader
-
- org.apache.lucene.index.BaseCompositeReader<LeafReader>
-
- org.apache.lucene.index.DirectoryReader
-
- org.apache.lucene.index.StandardDirectoryReader
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public final class StandardDirectoryReader extends DirectoryReader
Default implementation ofDirectoryReader.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.lucene.index.IndexReader
IndexReader.CacheHelper, IndexReader.CacheKey, IndexReader.ClosedListener
-
-
Field Summary
-
Fields inherited from class org.apache.lucene.index.DirectoryReader
directory
-
Fields inherited from class org.apache.lucene.index.BaseCompositeReader
subReadersSorter
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoClose()Implements close.protected DirectoryReaderdoOpenIfChanged()Implement this method to supportDirectoryReader.openIfChanged(DirectoryReader).protected DirectoryReaderdoOpenIfChanged(IndexCommit commit)Implement this method to supportDirectoryReader.openIfChanged(DirectoryReader,IndexCommit).protected DirectoryReaderdoOpenIfChanged(IndexWriter writer, boolean applyAllDeletes)Implement this method to supportDirectoryReader.openIfChanged(DirectoryReader,IndexWriter,boolean).IndexCommitgetIndexCommit()Expert: return the IndexCommit that this reader has opened.IndexReader.CacheHelpergetReaderCacheHelper()Optional method: Return aIndexReader.CacheHelperthat can be used to cache based on the content of this reader.SegmentInfosgetSegmentInfos()Return theSegmentInfosfor this reader.longgetVersion()Version number when this IndexReader was opened.booleanisCurrent()Check whether any new changes have occurred to the index since this reader was opened.protected voidnotifyReaderClosedListeners()For test framework use only.static DirectoryReaderopen(Directory directory, SegmentInfos infos, List<? extends LeafReader> oldReaders, Comparator<LeafReader> leafSorter)This constructor is only used fordoOpenIfChanged(SegmentInfos), as well as NRT replication.StringtoString()-
Methods inherited from class org.apache.lucene.index.DirectoryReader
directory, indexExists, listCommits, open, open, open, open, open, open, openIfChanged, openIfChanged, openIfChanged, openIfChanged
-
Methods inherited from class org.apache.lucene.index.BaseCompositeReader
docFreq, document, getDocCount, getSequentialSubReaders, getSumDocFreq, getSumTotalTermFreq, getTermVectors, maxDoc, numDocs, readerBase, readerIndex, storedFields, termVectors, totalTermFreq
-
Methods inherited from class org.apache.lucene.index.CompositeReader
getContext
-
Methods inherited from class org.apache.lucene.index.IndexReader
close, decRef, document, document, ensureOpen, equals, getRefCount, getTermVector, hasDeletions, hashCode, incRef, leaves, numDeletedDocs, registerParentReader, tryIncRef
-
-
-
-
Method Detail
-
open
public static DirectoryReader open(Directory directory, SegmentInfos infos, List<? extends LeafReader> oldReaders, Comparator<LeafReader> leafSorter) throws IOException
This constructor is only used fordoOpenIfChanged(SegmentInfos), as well as NRT replication.- Throws:
IOException- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
toString
public String toString()
- Overrides:
toStringin classCompositeReader
-
doOpenIfChanged
protected DirectoryReader doOpenIfChanged() throws IOException
Description copied from class:DirectoryReaderImplement this method to supportDirectoryReader.openIfChanged(DirectoryReader). If this reader does not support reopen, returnnull, so client code is happy. This should be consistent withDirectoryReader.isCurrent()(should always returntrue) if reopen is not supported.- Specified by:
doOpenIfChangedin classDirectoryReader- Returns:
- null if there are no changes; else, a new DirectoryReader instance.
- Throws:
IOException- if there is a low-level IO error
-
doOpenIfChanged
protected DirectoryReader doOpenIfChanged(IndexCommit commit) throws IOException
Description copied from class:DirectoryReaderImplement this method to supportDirectoryReader.openIfChanged(DirectoryReader,IndexCommit). If this reader does not support reopen from a specificIndexCommit, throwUnsupportedOperationException.- Specified by:
doOpenIfChangedin classDirectoryReader- Returns:
- null if there are no changes; else, a new DirectoryReader instance.
- Throws:
IOException- if there is a low-level IO error
-
doOpenIfChanged
protected DirectoryReader doOpenIfChanged(IndexWriter writer, boolean applyAllDeletes) throws IOException
Description copied from class:DirectoryReaderImplement this method to supportDirectoryReader.openIfChanged(DirectoryReader,IndexWriter,boolean). If this reader does not support reopen fromIndexWriter, throwUnsupportedOperationException.- Specified by:
doOpenIfChangedin classDirectoryReader- Returns:
- null if there are no changes; else, a new DirectoryReader instance.
- Throws:
IOException- if there is a low-level IO error
-
getVersion
public long getVersion()
Description copied from class:DirectoryReaderVersion 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.- Specified by:
getVersionin classDirectoryReader
-
getSegmentInfos
public SegmentInfos getSegmentInfos()
Return theSegmentInfosfor this reader.- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
isCurrent
public boolean isCurrent() throws IOExceptionDescription copied from class:DirectoryReaderCheck whether any new changes have occurred to the index since this reader was opened.If this reader was created by calling
DirectoryReader.open(org.apache.lucene.store.Directory), then this method checks if any further commits (seeIndexWriter.commit()) have occurred in the directory.If instead this reader is a near real-time reader (ie, obtained by a call to
DirectoryReader.open(IndexWriter), or by callingDirectoryReader.openIfChanged(org.apache.lucene.index.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 false.In any event, if this returns false, you should call
DirectoryReader.openIfChanged(org.apache.lucene.index.DirectoryReader)to get a new reader that sees the changes.- Specified by:
isCurrentin classDirectoryReader- Throws:
IOException- if there is a low-level IO error
-
doClose
protected void doClose() throws IOExceptionDescription copied from class:IndexReaderImplements close.- Specified by:
doClosein classIndexReader- Throws:
IOException
-
getIndexCommit
public IndexCommit getIndexCommit() throws IOException
Description copied from class:DirectoryReaderExpert: return the IndexCommit that this reader has opened.- Specified by:
getIndexCommitin classDirectoryReader- Throws:
IOException
-
notifyReaderClosedListeners
protected void notifyReaderClosedListeners() throws IOExceptionDescription copied from class:IndexReaderFor test framework use only.- Overrides:
notifyReaderClosedListenersin classIndexReader- Throws:
IOException
-
getReaderCacheHelper
public IndexReader.CacheHelper getReaderCacheHelper()
Description copied from class:IndexReaderOptional method: Return aIndexReader.CacheHelperthat can be used to cache based on the content of this reader. Two readers that have different data or different sets of deleted documents will be considered different.A return value of
nullindicates that this reader is not suited for caching, which is typically the case for short-lived wrappers that alter the content of the wrapped reader.- Specified by:
getReaderCacheHelperin classIndexReader
-
-