Class OpenSearchDirectoryReader
java.lang.Object
org.apache.lucene.index.IndexReader
org.apache.lucene.index.CompositeReader
org.apache.lucene.index.BaseCompositeReader<org.apache.lucene.index.LeafReader>
org.apache.lucene.index.DirectoryReader
org.apache.lucene.index.FilterDirectoryReader
org.opensearch.common.lucene.index.OpenSearchDirectoryReader
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public final class OpenSearchDirectoryReader
extends org.apache.lucene.index.FilterDirectoryReader
A
FilterDirectoryReader
that exposes
OpenSearch internal per shard / index information like the shard ID.-
Nested Class Summary
-
Field Summary
-
Method Summary
Modifier and Type Method Description static void
addReaderCloseListener(org.apache.lucene.index.DirectoryReader reader, org.apache.lucene.index.IndexReader.ClosedListener listener)
Adds the given listener to the provided directory reader.protected org.apache.lucene.index.DirectoryReader
doWrapDirectoryReader(org.apache.lucene.index.DirectoryReader in)
static OpenSearchDirectoryReader
getOpenSearchDirectoryReader(org.apache.lucene.index.DirectoryReader reader)
Tries to unwrap the given reader until the firstOpenSearchDirectoryReader
instance is found ornull
if no instance is found.org.apache.lucene.index.IndexReader.CacheHelper
getReaderCacheHelper()
ShardId
shardId()
Returns the shard id this index belongs to.static OpenSearchDirectoryReader
wrap(org.apache.lucene.index.DirectoryReader reader, ShardId shardId)
Wraps the given reader in aOpenSearchDirectoryReader
as well as all it's sub-readers inOpenSearchLeafReader
to expose the given shard Id.Methods inherited from class org.apache.lucene.index.FilterDirectoryReader
doClose, doOpenIfChanged, doOpenIfChanged, doOpenIfChanged, getDelegate, getIndexCommit, getVersion, isCurrent, unwrap
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, totalTermFreq
-
Method Details
-
shardId
Returns the shard id this index belongs to. -
getReaderCacheHelper
public org.apache.lucene.index.IndexReader.CacheHelper getReaderCacheHelper()- Specified by:
getReaderCacheHelper
in classorg.apache.lucene.index.IndexReader
-
doWrapDirectoryReader
protected org.apache.lucene.index.DirectoryReader doWrapDirectoryReader(org.apache.lucene.index.DirectoryReader in) throws java.io.IOException- Specified by:
doWrapDirectoryReader
in classorg.apache.lucene.index.FilterDirectoryReader
- Throws:
java.io.IOException
-
wrap
public static OpenSearchDirectoryReader wrap(org.apache.lucene.index.DirectoryReader reader, ShardId shardId) throws java.io.IOExceptionWraps the given reader in aOpenSearchDirectoryReader
as well as all it's sub-readers inOpenSearchLeafReader
to expose the given shard Id.- Parameters:
reader
- the reader to wrapshardId
- the shard ID to expose via the opensearch internal reader wrappers.- Throws:
java.io.IOException
-
addReaderCloseListener
public static void addReaderCloseListener(org.apache.lucene.index.DirectoryReader reader, org.apache.lucene.index.IndexReader.ClosedListener listener)Adds the given listener to the provided directory reader. The reader must contain anOpenSearchDirectoryReader
in it's hierarchy otherwise we can't safely install the listener.- Throws:
java.lang.IllegalArgumentException
- if the reader doesn't contain anOpenSearchDirectoryReader
in it's hierarchy
-
getOpenSearchDirectoryReader
public static OpenSearchDirectoryReader getOpenSearchDirectoryReader(org.apache.lucene.index.DirectoryReader reader)Tries to unwrap the given reader until the firstOpenSearchDirectoryReader
instance is found ornull
if no instance is found.
-