org.apache.lucene.index

## Class SegmentReader

- java.lang.Object
- - org.apache.lucene.index.IndexReader
  - - org.apache.lucene.index.LeafReader
    - - org.apache.lucene.index.CodecReader
      - - org.apache.lucene.index.SegmentReader

- All Implemented Interfaces:
    Closeable, AutoCloseable, Accountable

      public final class SegmentReader
      extends CodecReader

  IndexReader implementation over a single segment.

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

  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.lucene.index.LeafReader

      `LeafReader.CoreClosedListener`

    - ### Nested classes/interfaces inherited from class org.apache.lucene.index.IndexReader

      `IndexReader.ReaderClosedListener`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SegmentReader(SegmentCommitInfo si, IOContext context)` Constructs a new SegmentReader with a new core.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addCoreClosedListener(LeafReader.CoreClosedListener listener)` Expert: adds a CoreClosedListener to this reader's shared core
    `Directory` | `directory()` Returns the directory this index resides in.
    `protected void` | `doClose()` Implements close.
    `Object` | `getCombinedCoreAndDeletesKey()` Expert: Returns a key for this IndexReader that also includes deletions, so CachingWrapperFilter can find it again.
    `Object` | `getCoreCacheKey()` Expert: Returns a key for this IndexReader, so CachingWrapperFilter can find it again.
    `DocValuesProducer` | `getDocValuesReader()` Expert: retrieve underlying DocValuesProducer
    `FieldInfos` | `getFieldInfos()` Get the `FieldInfos` describing all fields in this reader.
    `StoredFieldsReader` | `getFieldsReader()` Expert: retrieve thread-private StoredFieldsReader
    `Sort` | `getIndexSort()` Returns null if this leaf is unsorted, or the `Sort` that it was sorted by
    `Bits` | `getLiveDocs()` Returns the `Bits` representing live (not deleted) docs.
    `NormsProducer` | `getNormsReader()` Expert: retrieve underlying NormsProducer
    `PointsReader` | `getPointsReader()` Expert: retrieve underlying PointsReader
    `PointValues` | `getPointValues()` Returns the `PointValues` used for numeric or spatial searches, or null if there are no point fields.
    `FieldsProducer` | `getPostingsReader()` Expert: retrieve underlying FieldsProducer
    `SegmentCommitInfo` | `getSegmentInfo()` Return the SegmentInfoPerCommit of the segment this reader is reading.
    `String` | `getSegmentName()` Return the name of the segment this reader is reading.
    `TermVectorsReader` | `getTermVectorsReader()` Expert: retrieve thread-private TermVectorsReader
    `int` | `maxDoc()` Returns one greater than the largest possible document number.
    `int` | `numDocs()` Returns the number of documents in this index.
    `void` | `removeCoreClosedListener(LeafReader.CoreClosedListener listener)` Expert: removes a CoreClosedListener from this reader's shared core
    `String` | `toString()`

    - ### Methods inherited from class org.apache.lucene.index.CodecReader

      `checkIntegrity, document, fields, getBinaryDocValues, getChildResources, getDocsWithField, getNormValues, getNumericDocValues, getSortedDocValues, getSortedNumericDocValues, getSortedSetDocValues, getTermVectors, ramBytesUsed`

    - ### Methods inherited from class org.apache.lucene.index.LeafReader

      `addCoreClosedListenerAsReaderClosedListener, docFreq, getContext, getDocCount, getSumDocFreq, getSumTotalTermFreq, postings, postings, removeCoreClosedListenerAsReaderClosedListener, terms, totalTermFreq`

    - ### Methods inherited from class org.apache.lucene.index.IndexReader

      `addReaderClosedListener, close, decRef, document, document, ensureOpen, equals, getRefCount, getTermVector, hasDeletions, hashCode, incRef, leaves, numDeletedDocs, registerParentReader, removeReaderClosedListener, tryIncRef`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### SegmentReader

          public SegmentReader(SegmentCommitInfo si,
                               IOContext context)
                        throws IOException

      Constructs a new SegmentReader with a new core.
      Throws:
        `CorruptIndexException` - if the index is corrupt
        `IOException` - if there is a low-level IO error

  - ### Method Detail

    - #### getLiveDocs

          public Bits getLiveDocs()

      Description copied from class: `LeafReader`
      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 `LeafReader`

    - #### doClose

          protected void doClose()
                          throws IOException

      Description copied from class: `IndexReader`
      Implements close.
      Overrides:
        `doClose` in class `CodecReader`
      Throws:
        `IOException`

    - #### getFieldInfos

          public FieldInfos getFieldInfos()

      Description copied from class: `LeafReader`
      Get the `FieldInfos` describing all fields in this reader.
      Specified by:
        `getFieldInfos` in class `LeafReader`

    - #### 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`

    - #### getTermVectorsReader

          public TermVectorsReader getTermVectorsReader()

      Description copied from class: `CodecReader`
      Expert: retrieve thread-private TermVectorsReader
      Specified by:
        `getTermVectorsReader` in class `CodecReader`

    - #### getFieldsReader

          public StoredFieldsReader getFieldsReader()

      Description copied from class: `CodecReader`
      Expert: retrieve thread-private StoredFieldsReader
      Specified by:
        `getFieldsReader` in class `CodecReader`

    - #### getPointValues

          public PointValues getPointValues()

      Description copied from class: `LeafReader`
      Returns the `PointValues` used for numeric or spatial searches, or null if there are no point fields.
      Specified by:
        `getPointValues` in class `LeafReader`

    - #### getNormsReader

          public NormsProducer getNormsReader()

      Description copied from class: `CodecReader`
      Expert: retrieve underlying NormsProducer
      Specified by:
        `getNormsReader` in class `CodecReader`

    - #### getDocValuesReader

          public DocValuesProducer getDocValuesReader()

      Description copied from class: `CodecReader`
      Expert: retrieve underlying DocValuesProducer
      Specified by:
        `getDocValuesReader` in class `CodecReader`

    - #### getPostingsReader

          public FieldsProducer getPostingsReader()

      Description copied from class: `CodecReader`
      Expert: retrieve underlying FieldsProducer
      Specified by:
        `getPostingsReader` in class `CodecReader`

    - #### getPointsReader

          public PointsReader getPointsReader()

      Description copied from class: `CodecReader`
      Expert: retrieve underlying PointsReader
      Specified by:
        `getPointsReader` in class `CodecReader`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### getSegmentName

          public 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 Object getCoreCacheKey()

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

    - #### getCombinedCoreAndDeletesKey

          public Object getCombinedCoreAndDeletesKey()

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

    - #### addCoreClosedListener

          public void addCoreClosedListener(LeafReader.CoreClosedListener listener)

      Description copied from class: `LeafReader`
      Expert: adds a CoreClosedListener to this reader's shared core
      Specified by:
        `addCoreClosedListener` in class `LeafReader`

    - #### removeCoreClosedListener

          public void removeCoreClosedListener(LeafReader.CoreClosedListener listener)

      Description copied from class: `LeafReader`
      Expert: removes a CoreClosedListener from this reader's shared core
      Specified by:
        `removeCoreClosedListener` in class `LeafReader`

    - #### getIndexSort

          public Sort getIndexSort()

      Description copied from class: `LeafReader`
      Returns null if this leaf is unsorted, or the `Sort` that it was sorted by
      Specified by:
        `getIndexSort` in class `LeafReader`

Copyright © 2000-2018 Apache Software Foundation. All Rights Reserved.