org.apache.lucene.index

## Class TermContext

- java.lang.Object
- - org.apache.lucene.index.TermContext

-     public final class TermContext
      extends Object

  Maintains a `IndexReader` `TermState` view over `IndexReader` instances containing a single term. The `TermContext` doesn't track if the given `TermState` objects are valid, neither if the `TermState` instances refer to the same terms in the associated readers.
  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `IndexReaderContext` | `topReaderContext` Holds the `IndexReaderContext` of the top-level `IndexReader`, used internally only for asserting.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TermContext(IndexReaderContext context)` Creates an empty `TermContext` from a `IndexReaderContext`
    `TermContext(IndexReaderContext context, TermState state, int ord, int docFreq, long totalTermFreq)` Creates a `TermContext` with an initial `TermState`, `IndexReader` pair.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static TermContext` | `build(IndexReaderContext context, Term term, boolean cache)` Creates a `TermContext` from a top-level `IndexReaderContext` and the given `Term`.
    `void` | `clear()` Clears the `TermContext` internal state and removes all registered `TermState`s
    `int` | `docFreq()` Returns the accumulated document frequency of all `TermState` instances passed to `register(TermState, int, int, long)`.
    `TermState` | `get(int ord)` Returns the `TermState` for an leaf ordinal or `null` if no `TermState` for the ordinal was registered.
    `void` | `register(TermState state, int ord, int docFreq, long totalTermFreq)` Registers and associates a `TermState` with an leaf ordinal.
    `void` | `setDocFreq(int docFreq)` expert: only available for queries that want to lie about docfreq
    `long` | `totalTermFreq()` Returns the accumulated term frequency of all `TermState` instances passed to `register(TermState, int, int, long)`.

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

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### topReaderContext

          public final IndexReaderContext topReaderContext

      Holds the `IndexReaderContext` of the top-level `IndexReader`, used internally only for asserting.
      NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

  - ### Constructor Detail

    - #### TermContext

          public TermContext(IndexReaderContext context)

      Creates an empty `TermContext` from a `IndexReaderContext`

    - #### TermContext

          public TermContext(IndexReaderContext context,
                     TermState state,
                     int ord,
                     int docFreq,
                     long totalTermFreq)

      Creates a `TermContext` with an initial `TermState`, `IndexReader` pair.

  - ### Method Detail

    - #### build

          public static TermContext build(IndexReaderContext context,
                          Term term,
                          boolean cache)
                                   throws IOException

      Creates a `TermContext` from a top-level `IndexReaderContext` and the given `Term`. This method will lookup the given term in all context's leaf readers and register each of the readers containing the term in the returned `TermContext` using the leaf reader's ordinal.

      Note: the given context must be a top-level context.

      Throws:
        `IOException`

    - #### clear

          public void clear()

      Clears the `TermContext` internal state and removes all registered `TermState`s

    - #### register

          public void register(TermState state,
                      int ord,
                      int docFreq,
                      long totalTermFreq)

      Registers and associates a `TermState` with an leaf ordinal. The leaf ordinal should be derived from a `IndexReaderContext`'s leaf ord.

    - #### get

          public TermState get(int ord)

      Returns the `TermState` for an leaf ordinal or `null` if no `TermState` for the ordinal was registered.
      Parameters:
        `ord` - the readers leaf ordinal to get the `TermState` for.
      Returns:
        the `TermState` for the given readers ord or `null` if no `TermState` for the reader was registered

    - #### docFreq

          public int docFreq()

      Returns the accumulated document frequency of all `TermState` instances passed to `register(TermState, int, int, long)`.
      Returns:
        the accumulated document frequency of all `TermState` instances passed to `register(TermState, int, int, long)`.

    - #### totalTermFreq

          public long totalTermFreq()

      Returns the accumulated term frequency of all `TermState` instances passed to `register(TermState, int, int, long)`.
      Returns:
        the accumulated term frequency of all `TermState` instances passed to `register(TermState, int, int, long)`.

    - #### setDocFreq

          public void setDocFreq(int docFreq)

      expert: only available for queries that want to lie about docfreq
      NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

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