Class AtomicReader
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
FilterAtomicReader,ParallelAtomicReader,SegmentReader,SlowCompositeReaderWrapper
AtomicReader is an abstract class, providing an interface for accessing an
index. Search of an index is done entirely through this abstract interface,
so that any subclass which implements it is searchable. IndexReaders implemented
by this subclass do not consist of several sub-readers,
they are atomic. They support retrieval of stored fields, doc values, terms,
and postings.
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.ReaderClosedListener -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal intReturns the number of documents containing theterm.abstract Fieldsfields()ReturnsFieldsfor this reader.abstract BinaryDocValuesgetBinaryDocValues(String field) ReturnsBinaryDocValuesfor this field, or null if noBinaryDocValueswere indexed for this field.final AtomicReaderContextExpert: Returns the rootIndexReaderContextfor thisIndexReader's sub-reader tree.final intgetDocCount(String field) Returns the number of documents that have at least one term for this field, or -1 if this measure isn't stored by the codec.abstract BitsgetDocsWithField(String field) Returns aBitsat the size ofreader.maxDoc(), with turned on bits for each docid that does have a value for this field, or null if no DocValues were indexed for this field.abstract FieldInfosGet theFieldInfosdescribing all fields in this reader.abstract BitsReturns theBitsrepresenting live (not deleted) docs.abstract NumericDocValuesgetNormValues(String field) ReturnsNumericDocValuesrepresenting norms for this field, or null if noNumericDocValueswere indexed.abstract NumericDocValuesgetNumericDocValues(String field) ReturnsNumericDocValuesfor this field, or null if noNumericDocValueswere indexed for this field.abstract SortedDocValuesgetSortedDocValues(String field) ReturnsSortedDocValuesfor this field, or null if noSortedDocValueswere indexed for this field.abstract SortedSetDocValuesgetSortedSetDocValues(String field) ReturnsSortedSetDocValuesfor this field, or null if noSortedSetDocValueswere indexed for this field.final longgetSumDocFreq(String field) Returns the sum ofTermsEnum.docFreq()for all terms in this field, or -1 if this measure isn't stored by the codec.final longgetSumTotalTermFreq(String field) Returns the sum ofTermsEnum.totalTermFreq()for all terms in this field, or -1 if this measure isn't stored by the codec (or if this fields omits term freq and positions).final booleanDeprecated.final DocsEnumtermDocsEnum(Term term) ReturnsDocsEnumfor the specified term.final DocsAndPositionsEnumtermPositionsEnum(Term term) ReturnsDocsAndPositionsEnumfor the specified term.final TermsThis may return null if the field does not exist.final longtotalTermFreq(Term term) Returns the number of documents containing the termt.Methods inherited from class org.apache.lucene.index.IndexReader
addReaderClosedListener, close, decRef, doClose, document, document, document, ensureOpen, equals, getCombinedCoreAndDeletesKey, getCoreCacheKey, getRefCount, getTermVector, getTermVectors, hasDeletions, hashCode, incRef, leaves, maxDoc, numDeletedDocs, numDocs, open, open, open, open, open, registerParentReader, removeReaderClosedListener, tryIncRef
-
Constructor Details
-
AtomicReader
protected AtomicReader()Sole constructor. (For invocation by subclass constructors, typically implicit.)
-
-
Method Details
-
getContext
Description copied from class:IndexReaderExpert: Returns the rootIndexReaderContextfor thisIndexReader's sub-reader tree.Iff this reader is composed of sub readers, i.e. this reader being a composite reader, this method returns a
CompositeReaderContextholding the reader's direct children as well as a view of the reader tree's atomic leaf contexts. All sub-IndexReaderContextinstances referenced from this readers top-level context are private to this reader and are not shared with another context tree. For example, IndexSearcher uses this API to drive searching by one atomic leaf reader at a time. If this reader is not composed of child readers, this method returns anAtomicReaderContext.Note: Any of the sub-
CompositeReaderContextinstances referenced from this top-level context do not supportCompositeReaderContext.leaves(). Only the top-level context maintains the convenience leaf-view for performance reasons.- Specified by:
getContextin classIndexReader
-
hasNorms
Deprecated.(4.0) usegetFieldInfos()and checkFieldInfo.hasNorms()for the field instead.Returns true if there are norms stored for this field.- Throws:
IOException
-
fields
ReturnsFieldsfor this reader. This method may return null if the reader has no postings.- 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
Returns the number of documents containing the termt. 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:
totalTermFreqin classIndexReader- Throws:
IOException
-
getSumDocFreq
Description copied from class:IndexReaderReturns the sum ofTermsEnum.docFreq()for all terms in this field, or -1 if this measure isn't stored by the codec. 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, or -1 if this measure isn't stored by the codec. 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, or -1 if this measure isn't stored by the codec (or if this fields omits term freq and positions). Note that, just like other term measures, this measure does not take deleted documents into account.- Specified by:
getSumTotalTermFreqin classIndexReader- Throws:
IOException- See Also:
-
terms
This may return null if the field does not exist.- Throws:
IOException
-
termDocsEnum
ReturnsDocsEnumfor the specified term. This will return null if either the field or term does not exist.- Throws:
IOException- See Also:
-
termPositionsEnum
ReturnsDocsAndPositionsEnumfor the specified term. This will return null if the field or term does not exist or positions weren't indexed.- Throws:
IOException- See Also:
-
getNumericDocValues
ReturnsNumericDocValuesfor this field, or null if noNumericDocValueswere indexed for this field. The returned instance should only be used by a single thread.- Throws:
IOException
-
getBinaryDocValues
ReturnsBinaryDocValuesfor this field, or null if noBinaryDocValueswere indexed for this field. The returned instance should only be used by a single thread.- Throws:
IOException
-
getSortedDocValues
ReturnsSortedDocValuesfor this field, or null if noSortedDocValueswere indexed for this field. The returned instance should only be used by a single thread.- Throws:
IOException
-
getSortedSetDocValues
ReturnsSortedSetDocValuesfor this field, or null if noSortedSetDocValueswere indexed for this field. The returned instance should only be used by a single thread.- Throws:
IOException
-
getDocsWithField
Returns aBitsat the size ofreader.maxDoc(), with turned on bits for each docid that does have a value for this field, or null if no DocValues were indexed for this field. The returned instance should only be used by a single thread- Throws:
IOException
-
getNormValues
ReturnsNumericDocValuesrepresenting norms for this field, or null if noNumericDocValueswere indexed. The returned instance should only be used by a single thread.- Throws:
IOException
-
getFieldInfos
Get theFieldInfosdescribing all fields in this reader. -
getLiveDocs
Returns theBitsrepresenting live (not deleted) docs. A set bit indicates the doc ID has not been deleted. If this method returns null it means there are no deleted documents (all documents are live). The returned instance has been safely published for use by multiple threads without additional synchronization.
-
getFieldInfos()and checkFieldInfo.hasNorms()for the field instead.