Class AtomicReader
- java.lang.Object
-
- org.apache.lucene.index.IndexReader
-
- org.apache.lucene.index.AtomicReader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
FilterAtomicReader
,ParallelAtomicReader
,SegmentReader
,SlowCompositeReaderWrapper
public abstract class AtomicReader extends IndexReader
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 theIndexReader
instance; use your own (non-Lucene) objects instead.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.lucene.index.IndexReader
IndexReader.ReaderClosedListener
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description int
docFreq(Term term)
Returns the number of documents containing theterm
.abstract Fields
fields()
ReturnsFields
for this reader.abstract BinaryDocValues
getBinaryDocValues(java.lang.String field)
ReturnsBinaryDocValues
for this field, or null if noBinaryDocValues
were indexed for this field.AtomicReaderContext
getContext()
Expert: Returns the rootIndexReaderContext
for thisIndexReader
's sub-reader tree.int
getDocCount(java.lang.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 Bits
getDocsWithField(java.lang.String field)
Returns aBits
at 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 FieldInfos
getFieldInfos()
Get theFieldInfos
describing all fields in this reader.abstract Bits
getLiveDocs()
Returns theBits
representing live (not deleted) docs.abstract NumericDocValues
getNormValues(java.lang.String field)
ReturnsNumericDocValues
representing norms for this field, or null if noNumericDocValues
were indexed.abstract NumericDocValues
getNumericDocValues(java.lang.String field)
ReturnsNumericDocValues
for this field, or null if noNumericDocValues
were indexed for this field.abstract SortedDocValues
getSortedDocValues(java.lang.String field)
ReturnsSortedDocValues
for this field, or null if noSortedDocValues
were indexed for this field.abstract SortedSetDocValues
getSortedSetDocValues(java.lang.String field)
ReturnsSortedSetDocValues
for this field, or null if noSortedSetDocValues
were indexed for this field.long
getSumDocFreq(java.lang.String field)
Returns the sum ofTermsEnum.docFreq()
for all terms in this field, or -1 if this measure isn't stored by the codec.long
getSumTotalTermFreq(java.lang.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).boolean
hasNorms(java.lang.String field)
Deprecated.(4.0) usegetFieldInfos()
and checkFieldInfo.hasNorms()
for the field instead.DocsEnum
termDocsEnum(Term term)
ReturnsDocsEnum
for the specified term.DocsAndPositionsEnum
termPositionsEnum(Term term)
ReturnsDocsAndPositionsEnum
for the specified term.Terms
terms(java.lang.String field)
This may return null if the field does not exist.long
totalTermFreq(Term term)
Returns the number of documents containing the termt
.-
Methods inherited from class org.apache.lucene.index.IndexReader
addReaderClosedListener, close, decRef, document, document, document, equals, getCombinedCoreAndDeletesKey, getCoreCacheKey, getRefCount, getTermVector, getTermVectors, hasDeletions, hashCode, incRef, leaves, maxDoc, numDeletedDocs, numDocs, open, open, open, open, open, registerParentReader, removeReaderClosedListener, tryIncRef
-
-
-
-
Method Detail
-
getContext
public final AtomicReaderContext getContext()
Description copied from class:IndexReader
Expert: Returns the rootIndexReaderContext
for 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
CompositeReaderContext
holding the reader's direct children as well as a view of the reader tree's atomic leaf contexts. All sub-IndexReaderContext
instances 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-
CompositeReaderContext
instances 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:
getContext
in classIndexReader
-
hasNorms
@Deprecated public final boolean hasNorms(java.lang.String field) throws java.io.IOException
Deprecated.(4.0) usegetFieldInfos()
and checkFieldInfo.hasNorms()
for the field instead.Returns true if there are norms stored for this field.- Throws:
java.io.IOException
-
fields
public abstract Fields fields() throws java.io.IOException
ReturnsFields
for this reader. This method may return null if the reader has no postings.- Throws:
java.io.IOException
-
docFreq
public final int docFreq(Term term) throws java.io.IOException
Description copied from class:IndexReader
Returns 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:
docFreq
in classIndexReader
- Throws:
java.io.IOException
- See Also:
TermsEnum.docFreq()
-
totalTermFreq
public final long totalTermFreq(Term term) throws java.io.IOException
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:
totalTermFreq
in classIndexReader
- Throws:
java.io.IOException
-
getSumDocFreq
public final long getSumDocFreq(java.lang.String field) throws java.io.IOException
Description copied from class:IndexReader
Returns 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:
getSumDocFreq
in classIndexReader
- Throws:
java.io.IOException
- See Also:
Terms.getSumDocFreq()
-
getDocCount
public final int getDocCount(java.lang.String field) throws java.io.IOException
Description copied from class:IndexReader
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. Note that, just like other term measures, this measure does not take deleted documents into account.- Specified by:
getDocCount
in classIndexReader
- Throws:
java.io.IOException
- See Also:
Terms.getDocCount()
-
getSumTotalTermFreq
public final long getSumTotalTermFreq(java.lang.String field) throws java.io.IOException
Description copied from class:IndexReader
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). Note that, just like other term measures, this measure does not take deleted documents into account.- Specified by:
getSumTotalTermFreq
in classIndexReader
- Throws:
java.io.IOException
- See Also:
Terms.getSumTotalTermFreq()
-
terms
public final Terms terms(java.lang.String field) throws java.io.IOException
This may return null if the field does not exist.- Throws:
java.io.IOException
-
termDocsEnum
public final DocsEnum termDocsEnum(Term term) throws java.io.IOException
ReturnsDocsEnum
for the specified term. This will return null if either the field or term does not exist.- Throws:
java.io.IOException
- See Also:
TermsEnum.docs(Bits, DocsEnum)
-
termPositionsEnum
public final DocsAndPositionsEnum termPositionsEnum(Term term) throws java.io.IOException
ReturnsDocsAndPositionsEnum
for the specified term. This will return null if the field or term does not exist or positions weren't indexed.- Throws:
java.io.IOException
- See Also:
TermsEnum.docsAndPositions(Bits, DocsAndPositionsEnum)
-
getNumericDocValues
public abstract NumericDocValues getNumericDocValues(java.lang.String field) throws java.io.IOException
ReturnsNumericDocValues
for this field, or null if noNumericDocValues
were indexed for this field. The returned instance should only be used by a single thread.- Throws:
java.io.IOException
-
getBinaryDocValues
public abstract BinaryDocValues getBinaryDocValues(java.lang.String field) throws java.io.IOException
ReturnsBinaryDocValues
for this field, or null if noBinaryDocValues
were indexed for this field. The returned instance should only be used by a single thread.- Throws:
java.io.IOException
-
getSortedDocValues
public abstract SortedDocValues getSortedDocValues(java.lang.String field) throws java.io.IOException
ReturnsSortedDocValues
for this field, or null if noSortedDocValues
were indexed for this field. The returned instance should only be used by a single thread.- Throws:
java.io.IOException
-
getSortedSetDocValues
public abstract SortedSetDocValues getSortedSetDocValues(java.lang.String field) throws java.io.IOException
ReturnsSortedSetDocValues
for this field, or null if noSortedSetDocValues
were indexed for this field. The returned instance should only be used by a single thread.- Throws:
java.io.IOException
-
getDocsWithField
public abstract Bits getDocsWithField(java.lang.String field) throws java.io.IOException
Returns aBits
at 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:
java.io.IOException
-
getNormValues
public abstract NumericDocValues getNormValues(java.lang.String field) throws java.io.IOException
ReturnsNumericDocValues
representing norms for this field, or null if noNumericDocValues
were indexed. The returned instance should only be used by a single thread.- Throws:
java.io.IOException
-
getFieldInfos
public abstract FieldInfos getFieldInfos()
Get theFieldInfos
describing all fields in this reader.
-
getLiveDocs
public abstract Bits getLiveDocs()
Returns theBits
representing 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.
-
-