Class MultiReader
- All Implemented Interfaces:
Closeable,AutoCloseable
CompositeReader which reads multiple indexes, appending their content. It can be used
to create a view on several sub-readers (like DirectoryReader) and execute searches on
it.
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: IndexReader instances are completely thread safe, meaning multiple
threads can call any of its methods, concurrently. If your application requires external
synchronization, you should not synchronize on the IndexReader instance; use
your own (non-Lucene) objects instead.
-
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.BaseCompositeReader
subReadersSorter -
Constructor Summary
ConstructorsConstructorDescriptionMultiReader(IndexReader... subReaders) Construct a MultiReader aggregating the named set of (sub)readers.MultiReader(IndexReader[] subReaders, boolean closeSubReaders) Construct a MultiReader aggregating the named set of (sub)readers.MultiReader(IndexReader[] subReaders, Comparator<IndexReader> subReadersSorter, boolean closeSubReaders) Construct a MultiReader aggregating the named set of (sub)readers. -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoClose()Implements close.Optional method: Return aIndexReader.CacheHelperthat can be used to cache based on the content of this reader.Methods inherited from class org.apache.lucene.index.BaseCompositeReader
docFreq, getDocCount, getSequentialSubReaders, getSumDocFreq, getSumTotalTermFreq, maxDoc, numDocs, readerBase, readerIndex, storedFields, termVectors, totalTermFreqMethods inherited from class org.apache.lucene.index.CompositeReader
getContext, toStringMethods inherited from class org.apache.lucene.index.IndexReader
close, decRef, ensureOpen, equals, getRefCount, hasDeletions, hashCode, incRef, leaves, notifyReaderClosedListeners, numDeletedDocs, registerParentReader, tryIncRef
-
Constructor Details
-
MultiReader
Construct a MultiReader aggregating the named set of (sub)readers.Note that all subreaders are closed if this Multireader is closed.
- Parameters:
subReaders- set of (sub)readers- Throws:
IOException
-
MultiReader
Construct a MultiReader aggregating the named set of (sub)readers.- Parameters:
subReaders- set of (sub)readers; this array will be cloned.closeSubReaders- indicates whether the subreaders should be closed when this MultiReader is closed- Throws:
IOException
-
MultiReader
public MultiReader(IndexReader[] subReaders, Comparator<IndexReader> subReadersSorter, boolean closeSubReaders) throws IOException Construct a MultiReader aggregating the named set of (sub)readers.- Parameters:
subReaders- set of (sub)readers; this array will be cloned.subReadersSorter- – a comparator, that if notnullis used for sorting sub readers.closeSubReaders- indicates whether the subreaders should be closed when this MultiReader is closed- Throws:
IOException
-
-
Method Details
-
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
-
doClose
Description copied from class:IndexReaderImplements close.- Specified by:
doClosein classIndexReader- Throws:
IOException
-