Class BaseCompositeReader<R extends IndexReader>
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
DirectoryReader,MultiReader,ParallelCompositeReader
CompositeReaders based on an array of sub-readers. The
implementing class has to add code for correctly refcounting and closing the sub-readers.
User code will most likely use MultiReader to build a composite reader on a set of
sub-readers (like several DirectoryReaders).
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.
- See Also:
- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.index.IndexReader
IndexReader.CacheHelper, IndexReader.CacheKey, IndexReader.ClosedListener -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Comparator<R>A comparator for sorting sub-readers -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseCompositeReader(R[] subReaders, Comparator<R> subReadersSorter) Constructs aBaseCompositeReaderon the given subReaders. -
Method Summary
Modifier and TypeMethodDescriptionfinal intReturns the number of documents containing theterm.final voiddocument(int docID, StoredFieldVisitor visitor) Expert: visits the fields of a stored document, for custom processing/loading of each field.final intgetDocCount(String field) Returns the number of documents that have at least one term for this field.Expert: returns the sequential sub readers that this reader is logically composed of.final longgetSumDocFreq(String field) Returns the sum ofTermsEnum.docFreq()for all terms in this field.final longgetSumTotalTermFreq(String field) Returns the sum ofTermsEnum.totalTermFreq()for all terms in this field.final FieldsgetTermVectors(int docID) Retrieve term vectors for this document, or null if term vectors were not indexed.final intmaxDoc()Returns one greater than the largest possible document number.final intnumDocs()Returns the number of documents in this index.protected final intreaderBase(int readerIndex) Helper method for subclasses to get the docBase of the given sub-reader index.protected final intreaderIndex(int docID) Helper method for subclasses to get the corresponding reader for a doc IDfinal longtotalTermFreq(Term term) Returns the total number of occurrences oftermacross all documents (the sum of the freq() for each doc that has this term).Methods inherited from class org.apache.lucene.index.CompositeReader
getContext, toStringMethods inherited from class org.apache.lucene.index.IndexReader
close, decRef, doClose, document, document, ensureOpen, equals, getReaderCacheHelper, getRefCount, getTermVector, hasDeletions, hashCode, incRef, leaves, notifyReaderClosedListeners, numDeletedDocs, registerParentReader, tryIncRef
-
Field Details
-
subReadersSorter
A comparator for sorting sub-readers
-
-
Constructor Details
-
BaseCompositeReader
Constructs aBaseCompositeReaderon the given subReaders.- Parameters:
subReaders- the wrapped sub-readers. This array is returned bygetSequentialSubReaders()and used to resolve the correct subreader for docID-based methods. Please note: This array is not cloned and not protected for modification, the subclass is responsible to do this.subReadersSorter- – a comparator for sorting sub readers. If notnull, this comparator is used to sort sub readers, before using the for resolving doc IDs.- Throws:
IOException
-
-
Method Details
-
getTermVectors
Description copied from class:IndexReaderRetrieve term vectors for this document, or null if term vectors were not indexed. The returned Fields instance acts like a single-document inverted index (the docID will be 0).- Specified by:
getTermVectorsin classIndexReader- Throws:
IOException
-
numDocs
public final int numDocs()Description copied from class:IndexReaderReturns the number of documents in this index.NOTE: This operation may run in O(maxDoc). Implementations that can't return this number in constant-time should cache it.
- Specified by:
numDocsin classIndexReader
-
maxDoc
public final int maxDoc()Description copied from class:IndexReaderReturns one greater than the largest possible document number. This may be used to, e.g., determine how big to allocate an array which will have an element for every document number in an index.- Specified by:
maxDocin classIndexReader
-
document
Description copied from class:IndexReaderExpert: visits the fields of a stored document, for custom processing/loading of each field. If you simply want to load all fields, useIndexReader.document(int). If you want to load a subset, useDocumentStoredFieldVisitor.- Specified by:
documentin classIndexReader- Throws:
IOException
-
docFreq
Description copied from class:IndexReaderReturns the number of documents containing theterm. This method returns 0 if the term or field does not exists. This method does not take into account deleted documents that have not yet been merged away.- Specified by:
docFreqin classIndexReader- Throws:
IOException- See Also:
-
totalTermFreq
Description copied from class:IndexReaderReturns the total number of occurrences oftermacross all documents (the sum of the freq() for each doc that has this term). Note that, like other term measures, this measure does not take deleted documents into account.- Specified by:
totalTermFreqin classIndexReader- Throws:
IOException
-
getSumDocFreq
Description copied from class:IndexReaderReturns the sum ofTermsEnum.docFreq()for all terms in this field. Note that, just like other term measures, this measure does not take deleted documents into account.- Specified by:
getSumDocFreqin classIndexReader- Throws:
IOException- See Also:
-
getDocCount
Description copied from class:IndexReaderReturns the number of documents that have at least one term for this field. Note that, just like other term measures, this measure does not take deleted documents into account.- Specified by:
getDocCountin classIndexReader- Throws:
IOException- See Also:
-
getSumTotalTermFreq
Description copied from class:IndexReaderReturns the sum ofTermsEnum.totalTermFreq()for all terms in this field. Note that, just like other term measures, this measure does not take deleted documents into account.- Specified by:
getSumTotalTermFreqin classIndexReader- Throws:
IOException- See Also:
-
readerIndex
protected final int readerIndex(int docID) Helper method for subclasses to get the corresponding reader for a doc ID -
readerBase
protected final int readerBase(int readerIndex) Helper method for subclasses to get the docBase of the given sub-reader index. -
getSequentialSubReaders
Description copied from class:CompositeReaderExpert: returns the sequential sub readers that this reader is logically composed of. This method may not returnnull.NOTE: In contrast to previous Lucene versions this method is no longer public, code that wants to get all
LeafReaders this composite is composed of should useIndexReader.leaves().- Specified by:
getSequentialSubReadersin classCompositeReader- See Also:
-