- java.lang.Object
-
- org.apache.lucene.index.IndexReader
-
- org.apache.lucene.index.CompositeReader
-
- org.apache.lucene.index.BaseCompositeReader<LeafReader>
-
- org.apache.lucene.index.ParallelCompositeReader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class ParallelCompositeReader extends BaseCompositeReader<LeafReader>
AnCompositeReader
which reads multiple, parallel indexes. Each index added must have the same number of documents, and exactly the same number of leaves (with equalmaxDoc
), but typically each contains different fields. Deletions are taken from the first reader. Each document contains the union of the fields of all documents with the same document number. When searching, matches for a query term are from the first index added that has the field.This is useful, e.g., with collections that have large fields which change rarely and small fields that change more frequently. The smaller fields may be re-indexed in a new index and both indexes may be searched together.
Warning: It is up to you to make sure all indexes are created and modified the same way. For example, if you add documents to one index, you need to add the same documents in the same order to the other indexes. Failure to do so will result in undefined behavior. A good strategy to create suitable indexes with
IndexWriter
is to useLogDocMergePolicy
, as this one does not reorder documents during merging (likeTieredMergePolicy
) and triggers merges by number of documents per segment. If you use differentMergePolicy
s it might happen that the segment structure of your index is no longer predictable.
-
-
Nested Class Summary
-
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 IndexReader.CacheHelper
cacheHelper
private boolean
closeSubReaders
private java.util.Set<IndexReader>
completeReaderSet
-
Fields inherited from class org.apache.lucene.index.BaseCompositeReader
subReadersSorter
-
-
Constructor Summary
Constructors Constructor Description ParallelCompositeReader(boolean closeSubReaders, CompositeReader... readers)
Create a ParallelCompositeReader based on the provided readers.ParallelCompositeReader(boolean closeSubReaders, CompositeReader[] readers, CompositeReader[] storedFieldReaders)
Expert: create a ParallelCompositeReader based on the provided readers and storedFieldReaders; when a document is loaded, only storedFieldsReaders will be used.ParallelCompositeReader(CompositeReader... readers)
Create a ParallelCompositeReader based on the provided readers; auto-closes the given readers onIndexReader.close()
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doClose()
Implements close.IndexReader.CacheHelper
getReaderCacheHelper()
Optional method: Return aIndexReader.CacheHelper
that can be used to cache based on the content of this reader.private static LeafReader[]
prepareLeafReaders(CompositeReader[] readers, CompositeReader[] storedFieldsReaders)
private static void
validate(CompositeReader[] readers, int maxDoc, int[] leafMaxDoc)
-
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, toString
-
Methods inherited from class org.apache.lucene.index.IndexReader
close, decRef, document, document, ensureOpen, equals, getRefCount, getTermVector, hasDeletions, hashCode, incRef, leaves, notifyReaderClosedListeners, numDeletedDocs, registerParentReader, tryIncRef
-
-
-
-
Field Detail
-
closeSubReaders
private final boolean closeSubReaders
-
completeReaderSet
private final java.util.Set<IndexReader> completeReaderSet
-
cacheHelper
private final IndexReader.CacheHelper cacheHelper
-
-
Constructor Detail
-
ParallelCompositeReader
public ParallelCompositeReader(CompositeReader... readers) throws java.io.IOException
Create a ParallelCompositeReader based on the provided readers; auto-closes the given readers onIndexReader.close()
.- Throws:
java.io.IOException
-
ParallelCompositeReader
public ParallelCompositeReader(boolean closeSubReaders, CompositeReader... readers) throws java.io.IOException
Create a ParallelCompositeReader based on the provided readers.- Throws:
java.io.IOException
-
ParallelCompositeReader
public ParallelCompositeReader(boolean closeSubReaders, CompositeReader[] readers, CompositeReader[] storedFieldReaders) throws java.io.IOException
Expert: create a ParallelCompositeReader based on the provided readers and storedFieldReaders; when a document is loaded, only storedFieldsReaders will be used.- Throws:
java.io.IOException
-
-
Method Detail
-
prepareLeafReaders
private static LeafReader[] prepareLeafReaders(CompositeReader[] readers, CompositeReader[] storedFieldsReaders) throws java.io.IOException
- Throws:
java.io.IOException
-
validate
private static void validate(CompositeReader[] readers, int maxDoc, int[] leafMaxDoc)
-
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
-
doClose
protected void doClose() throws java.io.IOException
Description copied from class:IndexReader
Implements close.- Specified by:
doClose
in classIndexReader
- Throws:
java.io.IOException
-
-