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.

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

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `accumulateStatistics(int docFreq, long totalTermFreq)` Expert: Accumulate term statistics.
    `static TermContext` | `build(IndexReaderContext context, Term term)` 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)` Expert: Registers and associates a `TermState` with an leaf ordinal.
    `void` | `register(TermState state, int ord, int docFreq, long totalTermFreq)` Registers and associates a `TermState` with an leaf ordinal.
    `String` | `toString()`
    `long` | `totalTermFreq()` Returns the accumulated term frequency of all `TermState` instances passed to `register(TermState, int, int, long)`.
    `boolean` | `wasBuiltFor(IndexReaderContext context)` Expert: Return whether this `TermContext` was built for the given `IndexReaderContext`.

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

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

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

    - #### wasBuiltFor

          public boolean wasBuiltFor(IndexReaderContext context)

      Expert: Return whether this `TermContext` was built for the given `IndexReaderContext`. This is typically used for assertions.
      NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

    - #### build

          public static TermContext build(IndexReaderContext context,
                                          Term term)
                                   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.

    - #### register

          public void register(TermState state,
                               int ord)

      Expert: Registers and associates a `TermState` with an leaf ordinal. The leaf ordinal should be derived from a `IndexReaderContext`'s leaf ord. On the contrary to `register(TermState, int, int, long)` this method does NOT update term statistics.

    - #### accumulateStatistics

          public void accumulateStatistics(int docFreq,
                                           long totalTermFreq)

      Expert: Accumulate term statistics.

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

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

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