public final class StandardDirectoryReader extends DirectoryReader
DirectoryReader
.Modifier and Type | Class and Description |
---|---|
(package private) static class |
StandardDirectoryReader.ReaderCommit |
IndexReader.CacheHelper, IndexReader.CacheKey, IndexReader.ClosedListener
Modifier and Type | Field and Description |
---|---|
private boolean |
applyAllDeletes |
private IndexReader.CacheHelper |
cacheHelper |
private java.util.Map<java.lang.String,java.lang.String> |
readerAttributes |
private java.util.Set<IndexReader.ClosedListener> |
readerClosedListeners |
(package private) SegmentInfos |
segmentInfos |
private boolean |
writeAllDeletes |
(package private) IndexWriter |
writer |
directory
Constructor and Description |
---|
StandardDirectoryReader(Directory directory,
LeafReader[] readers,
IndexWriter writer,
SegmentInfos sis,
boolean applyAllDeletes,
boolean writeAllDeletes,
java.util.Map<java.lang.String,java.lang.String> readerAttributes)
called only from static open() methods
|
Modifier and Type | Method and 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 support
DirectoryReader.openIfChanged(DirectoryReader) . |
protected DirectoryReader |
doOpenIfChanged(IndexCommit commit)
Implement this method to support
DirectoryReader.openIfChanged(DirectoryReader,IndexCommit) . |
protected DirectoryReader |
doOpenIfChanged(IndexWriter writer,
boolean applyAllDeletes)
Implement this method to support
DirectoryReader.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 a
IndexReader.CacheHelper that can be used to cache
based on the content of this reader. |
SegmentInfos |
getSegmentInfos()
Return the
SegmentInfos 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 DirectoryReader |
open(Directory directory,
IndexCommit commit,
java.util.Map<java.lang.String,java.lang.String> readerAttributes)
called from DirectoryReader.open(...) methods
|
static DirectoryReader |
open(Directory directory,
SegmentInfos infos,
java.util.List<? extends LeafReader> oldReaders,
java.util.Map<java.lang.String,java.lang.String> readerAttributes)
This constructor is only used for
doOpenIfChanged(SegmentInfos) , as well as NRT replication. |
(package private) static DirectoryReader |
open(IndexWriter writer,
SegmentInfos infos,
boolean applyAllDeletes,
boolean writeAllDeletes,
java.util.Map<java.lang.String,java.lang.String> readerAttributes)
Used by near real-time search
|
java.lang.String |
toString() |
directory, indexExists, listCommits, open, open, open, open, open, open, openIfChanged, openIfChanged, openIfChanged, openIfChanged
docFreq, document, getDocCount, getSequentialSubReaders, getSumDocFreq, getSumTotalTermFreq, getTermVectors, maxDoc, numDocs, readerBase, readerIndex, totalTermFreq
getContext
close, decRef, document, document, ensureOpen, equals, getRefCount, getTermVector, hasDeletions, hashCode, incRef, leaves, numDeletedDocs, registerParentReader, tryIncRef
final IndexWriter writer
final SegmentInfos segmentInfos
private final boolean applyAllDeletes
private final boolean writeAllDeletes
private final java.util.Map<java.lang.String,java.lang.String> readerAttributes
private final java.util.Set<IndexReader.ClosedListener> readerClosedListeners
private final IndexReader.CacheHelper cacheHelper
StandardDirectoryReader(Directory directory, LeafReader[] readers, IndexWriter writer, SegmentInfos sis, boolean applyAllDeletes, boolean writeAllDeletes, java.util.Map<java.lang.String,java.lang.String> readerAttributes) throws java.io.IOException
java.io.IOException
static DirectoryReader open(Directory directory, IndexCommit commit, java.util.Map<java.lang.String,java.lang.String> readerAttributes) throws java.io.IOException
java.io.IOException
static DirectoryReader open(IndexWriter writer, SegmentInfos infos, boolean applyAllDeletes, boolean writeAllDeletes, java.util.Map<java.lang.String,java.lang.String> readerAttributes) throws java.io.IOException
java.io.IOException
public static DirectoryReader open(Directory directory, SegmentInfos infos, java.util.List<? extends LeafReader> oldReaders, java.util.Map<java.lang.String,java.lang.String> readerAttributes) throws java.io.IOException
doOpenIfChanged(SegmentInfos)
, as well as NRT replication.java.io.IOException
private static void decRefWhileHandlingException(SegmentReader[] readers)
public java.lang.String toString()
toString
in class CompositeReader
protected DirectoryReader doOpenIfChanged() throws java.io.IOException
DirectoryReader
DirectoryReader.openIfChanged(DirectoryReader)
.
If this reader does not support reopen, return null
, so
client code is happy. This should be consistent with DirectoryReader.isCurrent()
(should always return true
) if reopen is not supported.doOpenIfChanged
in class DirectoryReader
java.io.IOException
- if there is a low-level IO errorprotected DirectoryReader doOpenIfChanged(IndexCommit commit) throws java.io.IOException
DirectoryReader
DirectoryReader.openIfChanged(DirectoryReader,IndexCommit)
.
If this reader does not support reopen from a specific IndexCommit
,
throw UnsupportedOperationException
.doOpenIfChanged
in class DirectoryReader
java.io.IOException
- if there is a low-level IO errorprotected DirectoryReader doOpenIfChanged(IndexWriter writer, boolean applyAllDeletes) throws java.io.IOException
DirectoryReader
DirectoryReader.openIfChanged(DirectoryReader,IndexWriter,boolean)
.
If this reader does not support reopen from IndexWriter
,
throw UnsupportedOperationException
.doOpenIfChanged
in class DirectoryReader
java.io.IOException
- if there is a low-level IO errorprivate DirectoryReader doOpenFromWriter(IndexCommit commit) throws java.io.IOException
java.io.IOException
private DirectoryReader doOpenNoWriter(IndexCommit commit) throws java.io.IOException
java.io.IOException
private DirectoryReader doOpenFromCommit(IndexCommit commit) throws java.io.IOException
java.io.IOException
DirectoryReader doOpenIfChanged(SegmentInfos infos) throws java.io.IOException
java.io.IOException
public long getVersion()
DirectoryReader
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
.
getVersion
in class DirectoryReader
public SegmentInfos getSegmentInfos()
SegmentInfos
for this reader.public boolean isCurrent() throws java.io.IOException
DirectoryReader
If this reader was created by calling DirectoryReader.open(org.apache.lucene.store.Directory)
,
then this method checks if any further commits
(see IndexWriter.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 calling DirectoryReader.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.
isCurrent
in class DirectoryReader
java.io.IOException
- if there is a low-level IO errorprotected void doClose() throws java.io.IOException
IndexReader
doClose
in class IndexReader
java.io.IOException
public IndexCommit getIndexCommit() throws java.io.IOException
DirectoryReader
getIndexCommit
in class DirectoryReader
java.io.IOException
void notifyReaderClosedListeners() throws java.io.IOException
notifyReaderClosedListeners
in class IndexReader
java.io.IOException
public IndexReader.CacheHelper getReaderCacheHelper()
IndexReader
IndexReader.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.
getReaderCacheHelper
in class IndexReader