Class SegmentReader

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public final class SegmentReader
    extends AtomicReader
    IndexReader implementation over a single segment.

    Instances pointing to the same segment (but with different deletes, etc) may share the same core data.

    • Constructor Detail

      • SegmentReader

        public SegmentReader​(SegmentCommitInfo si,
                             int termInfosIndexDivisor,
                             IOContext context)
                      throws java.io.IOException
        Constructs a new SegmentReader with a new core.
        Throws:
        CorruptIndexException - if the index is corrupt
        java.io.IOException - if there is a low-level IO error
    • Method Detail

      • getLiveDocs

        public Bits getLiveDocs()
        Description copied from class: AtomicReader
        Returns the Bits 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.
        Specified by:
        getLiveDocs in class AtomicReader
      • fields

        public Fields fields()
        Description copied from class: AtomicReader
        Returns Fields for this reader. This method may return null if the reader has no postings.
        Specified by:
        fields in class AtomicReader
      • numDocs

        public int numDocs()
        Description copied from class: IndexReader
        Returns the number of documents in this index.
        Specified by:
        numDocs in class IndexReader
      • maxDoc

        public int maxDoc()
        Description copied from class: IndexReader
        Returns 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:
        maxDoc in class IndexReader
      • getTermVectors

        public Fields getTermVectors​(int docID)
                              throws java.io.IOException
        Description copied from class: IndexReader
        Retrieve 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:
        getTermVectors in class IndexReader
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getSegmentName

        public java.lang.String getSegmentName()
        Return the name of the segment this reader is reading.
      • getSegmentInfo

        public SegmentCommitInfo getSegmentInfo()
        Return the SegmentInfoPerCommit of the segment this reader is reading.
      • directory

        public Directory directory()
        Returns the directory this index resides in.
      • getCoreCacheKey

        public java.lang.Object getCoreCacheKey()
        Description copied from class: IndexReader
        Expert: Returns a key for this IndexReader, so FieldCache/CachingWrapperFilter can find it again. This key must not have equals()/hashCode() methods, so "equals" means "identical".
        Overrides:
        getCoreCacheKey in class IndexReader
      • getCombinedCoreAndDeletesKey

        public java.lang.Object getCombinedCoreAndDeletesKey()
        Description copied from class: IndexReader
        Expert: Returns a key for this IndexReader that also includes deletions, so FieldCache/CachingWrapperFilter can find it again. This key must not have equals()/hashCode() methods, so "equals" means "identical".
        Overrides:
        getCombinedCoreAndDeletesKey in class IndexReader
      • getDocsWithField

        public Bits getDocsWithField​(java.lang.String field)
                              throws java.io.IOException
        Description copied from class: AtomicReader
        Returns a Bits at the size of reader.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
        Specified by:
        getDocsWithField in class AtomicReader
        Throws:
        java.io.IOException
      • addCoreClosedListener

        public void addCoreClosedListener​(SegmentReader.CoreClosedListener listener)
        Expert: adds a CoreClosedListener to this reader's shared core
      • removeCoreClosedListener

        public void removeCoreClosedListener​(SegmentReader.CoreClosedListener listener)
        Expert: removes a CoreClosedListener from this reader's shared core
      • ramBytesUsed

        public long ramBytesUsed()
        Returns approximate RAM Bytes used