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:
java.io.Closeable
,java.lang.AutoCloseable
public final class StandardDirectoryReader extends DirectoryReader
Default implementation ofDirectoryReader
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
StandardDirectoryReader.ReaderCommit
-
Nested classes/interfaces inherited from class org.apache.lucene.index.IndexReader
IndexReader.CacheHelper, IndexReader.CacheKey, IndexReader.ClosedListener
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
applyAllDeletes
private IndexReader.CacheHelper
cacheHelper
private java.util.Set<IndexReader.ClosedListener>
readerClosedListeners
(package private) SegmentInfos
segmentInfos
private boolean
writeAllDeletes
(package private) IndexWriter
writer
-
Fields inherited from class org.apache.lucene.index.DirectoryReader
directory
-
-
Constructor Summary
Constructors Constructor Description StandardDirectoryReader(Directory directory, LeafReader[] readers, IndexWriter writer, SegmentInfos sis, boolean applyAllDeletes, boolean writeAllDeletes)
called only from static open() methods
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
decRefWhileHandlingException(SegmentReader[] readers)
protected void
doClose()
Implements close.private DirectoryReader
doOpenFromCommit(IndexCommit commit)
private DirectoryReader
doOpenFromWriter(IndexCommit commit)
protected DirectoryReader
doOpenIfChanged()
Implement this method to supportDirectoryReader.openIfChanged(DirectoryReader)
.protected DirectoryReader
doOpenIfChanged(IndexCommit commit)
Implement this method to supportDirectoryReader.openIfChanged(DirectoryReader,IndexCommit)
.protected DirectoryReader
doOpenIfChanged(IndexWriter writer, boolean applyAllDeletes)
Implement this method to supportDirectoryReader.openIfChanged(DirectoryReader,IndexWriter,boolean)
.(package private) DirectoryReader
doOpenIfChanged(SegmentInfos infos)
private DirectoryReader
doOpenNoWriter(IndexCommit commit)
IndexCommit
getIndexCommit()
Expert: return the IndexCommit that this reader has opened.IndexReader.CacheHelper
getReaderCacheHelper()
Optional method: Return aIndexReader.CacheHelper
that can be used to cache based on the content of this reader.SegmentInfos
getSegmentInfos()
Return theSegmentInfos
for this reader.long
getVersion()
Version number when this IndexReader was opened.boolean
isCurrent()
Check whether any new changes have occurred to the index since this reader was opened.(package private) void
notifyReaderClosedListeners()
(package private) static StandardDirectoryReader
open(IndexWriter writer, IOUtils.IOFunction<SegmentCommitInfo,SegmentReader> readerFunction, SegmentInfos infos, boolean applyAllDeletes, boolean writeAllDeletes)
Used by near real-time search(package private) static DirectoryReader
open(Directory directory, IndexCommit commit)
called from DirectoryReader.open(...) methodsstatic DirectoryReader
open(Directory directory, SegmentInfos infos, java.util.List<? extends LeafReader> oldReaders)
This constructor is only used fordoOpenIfChanged(SegmentInfos)
, as well as NRT replication.java.lang.String
toString()
-
Methods inherited from class org.apache.lucene.index.DirectoryReader
directory, indexExists, listCommits, 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, 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
-
-
-
-
Field Detail
-
writer
final IndexWriter writer
-
segmentInfos
final SegmentInfos segmentInfos
-
applyAllDeletes
private final boolean applyAllDeletes
-
writeAllDeletes
private final boolean writeAllDeletes
-
readerClosedListeners
private final java.util.Set<IndexReader.ClosedListener> readerClosedListeners
-
cacheHelper
private final IndexReader.CacheHelper cacheHelper
-
-
Constructor Detail
-
StandardDirectoryReader
StandardDirectoryReader(Directory directory, LeafReader[] readers, IndexWriter writer, SegmentInfos sis, boolean applyAllDeletes, boolean writeAllDeletes) throws java.io.IOException
called only from static open() methods- Throws:
java.io.IOException
-
-
Method Detail
-
open
static DirectoryReader open(Directory directory, IndexCommit commit) throws java.io.IOException
called from DirectoryReader.open(...) methods- Throws:
java.io.IOException
-
open
static StandardDirectoryReader open(IndexWriter writer, IOUtils.IOFunction<SegmentCommitInfo,SegmentReader> readerFunction, SegmentInfos infos, boolean applyAllDeletes, boolean writeAllDeletes) throws java.io.IOException
Used by near real-time search- Throws:
java.io.IOException
-
open
public static DirectoryReader open(Directory directory, SegmentInfos infos, java.util.List<? extends LeafReader> oldReaders) throws java.io.IOException
This constructor is only used fordoOpenIfChanged(SegmentInfos)
, as well as NRT replication.- Throws:
java.io.IOException
-
decRefWhileHandlingException
private static void decRefWhileHandlingException(SegmentReader[] readers)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classCompositeReader
-
doOpenIfChanged
protected DirectoryReader doOpenIfChanged() throws java.io.IOException
Description copied from class:DirectoryReader
Implement 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:
doOpenIfChanged
in classDirectoryReader
- Returns:
- null if there are no changes; else, a new DirectoryReader instance.
- Throws:
java.io.IOException
- if there is a low-level IO error
-
doOpenIfChanged
protected DirectoryReader doOpenIfChanged(IndexCommit commit) throws java.io.IOException
Description copied from class:DirectoryReader
Implement this method to supportDirectoryReader.openIfChanged(DirectoryReader,IndexCommit)
. If this reader does not support reopen from a specificIndexCommit
, throwUnsupportedOperationException
.- Specified by:
doOpenIfChanged
in classDirectoryReader
- Returns:
- null if there are no changes; else, a new DirectoryReader instance.
- Throws:
java.io.IOException
- if there is a low-level IO error
-
doOpenIfChanged
protected DirectoryReader doOpenIfChanged(IndexWriter writer, boolean applyAllDeletes) throws java.io.IOException
Description copied from class:DirectoryReader
Implement this method to supportDirectoryReader.openIfChanged(DirectoryReader,IndexWriter,boolean)
. If this reader does not support reopen fromIndexWriter
, throwUnsupportedOperationException
.- Specified by:
doOpenIfChanged
in classDirectoryReader
- Returns:
- null if there are no changes; else, a new DirectoryReader instance.
- Throws:
java.io.IOException
- if there is a low-level IO error
-
doOpenFromWriter
private DirectoryReader doOpenFromWriter(IndexCommit commit) throws java.io.IOException
- Throws:
java.io.IOException
-
doOpenNoWriter
private DirectoryReader doOpenNoWriter(IndexCommit commit) throws java.io.IOException
- Throws:
java.io.IOException
-
doOpenFromCommit
private DirectoryReader doOpenFromCommit(IndexCommit commit) throws java.io.IOException
- Throws:
java.io.IOException
-
doOpenIfChanged
DirectoryReader doOpenIfChanged(SegmentInfos infos) throws java.io.IOException
- Throws:
java.io.IOException
-
getVersion
public long getVersion()
Description copied from class:DirectoryReader
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
.- Specified by:
getVersion
in classDirectoryReader
-
getSegmentInfos
public SegmentInfos getSegmentInfos()
Return theSegmentInfos
for this reader.
-
isCurrent
public boolean isCurrent() throws java.io.IOException
Description copied from class:DirectoryReader
Check 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:
isCurrent
in classDirectoryReader
- Throws:
java.io.IOException
- if there is a low-level IO error
-
doClose
protected void doClose() throws java.io.IOException
Description copied from class:IndexReader
Implements close.- Specified by:
doClose
in classIndexReader
- Throws:
java.io.IOException
-
getIndexCommit
public IndexCommit getIndexCommit() throws java.io.IOException
Description copied from class:DirectoryReader
Expert: return the IndexCommit that this reader has opened.- Specified by:
getIndexCommit
in classDirectoryReader
- Throws:
java.io.IOException
-
notifyReaderClosedListeners
void notifyReaderClosedListeners() throws java.io.IOException
- Overrides:
notifyReaderClosedListeners
in classIndexReader
- Throws:
java.io.IOException
-
getReaderCacheHelper
public IndexReader.CacheHelper getReaderCacheHelper()
Description copied from class:IndexReader
Optional method: Return aIndexReader.CacheHelper
that 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
null
indicates 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:
getReaderCacheHelper
in classIndexReader
-
-