org.apache.lucene.index

## Class CompositeReader

- java.lang.Object
- - org.apache.lucene.index.IndexReader
  - - org.apache.lucene.index.CompositeReader

- All Implemented Interfaces:
    Closeable, AutoCloseable
  Direct Known Subclasses:
    BaseCompositeReader

      public abstract class CompositeReader
      extends IndexReader

  Instances of this reader type can only be used to get stored fields from the underlying LeafReaders, but it is not possible to directly retrieve postings. To do that, get the `LeafReaderContext` for all sub-readers via `IndexReader.leaves()`.

  IndexReader instances for indexes on disk are usually constructed with a call to one of the static `DirectoryReader.open()` methods, e.g. `DirectoryReader.open(Directory)`. `DirectoryReader` implements the `CompositeReader` interface, it is not possible to directly get postings.

  Concrete subclasses of IndexReader are usually constructed with a call to one of the static `open()` methods, e.g. `DirectoryReader.open(Directory)`.

  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.CacheHelper, IndexReader.CacheKey, IndexReader.ClosedListener`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `CompositeReader()` Sole constructor.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `CompositeReaderContext` | `getContext()` Expert: Returns the root `IndexReaderContext` for this `IndexReader`'s sub-reader tree.
    `protected abstract List<? extends IndexReader>` | `getSequentialSubReaders()` Expert: returns the sequential sub readers that this reader is logically composed of.
    `String` | `toString()`

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

      `close, decRef, docFreq, doClose, document, document, document, ensureOpen, equals, getDocCount, getReaderCacheHelper, getRefCount, getSumDocFreq, getSumTotalTermFreq, getTermVector, getTermVectors, hasDeletions, hashCode, incRef, leaves, maxDoc, numDeletedDocs, numDocs, registerParentReader, totalTermFreq, tryIncRef`

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

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

- - ### Constructor Detail

    - #### CompositeReader

          protected CompositeReader()

      Sole constructor. (For invocation by subclass constructors, typically implicit.)

  - ### Method Detail

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### getSequentialSubReaders

          protected abstract List<? extends IndexReader> getSequentialSubReaders()

      Expert: returns the sequential sub readers that this reader is logically composed of. This method may not return `null`.

      NOTE: In contrast to previous Lucene versions this method is no longer public, code that wants to get all `LeafReader`s this composite is composed of should use `IndexReader.leaves()`.

      See Also:
        `IndexReader.leaves()`

    - #### getContext

          public final CompositeReaderContext getContext()

      Description copied from class: `IndexReader`
      Expert: Returns the root `IndexReaderContext` for this `IndexReader`'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 an `LeafReaderContext`.

      Note: Any of the sub-`CompositeReaderContext` instances referenced from this top-level context do not support `CompositeReaderContext.leaves()`. Only the top-level context maintains the convenience leaf-view for performance reasons.

      Specified by:
        `getContext` in class `IndexReader`

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