Package org.apache.lucene.search

# Record Class TermStatistics

java.lang.Object
java.lang.Record
org.apache.lucene.search.TermStatistics

Record Components:
  `term` - Term bytes.

  This value is never `null`.

  `docFreq` - number of documents containing the term in the collection, in the range [1 .. `totalTermFreq()`].

  This is the document-frequency for the term: the count of documents where the term appears at least one time.

  This value is always a positive number, and never exceeds `totalTermFreq`. It also cannot exceed `CollectionStatistics.sumDocFreq()`. @see TermsEnum#docFreq()

  `totalTermFreq` - number of occurrences of the term in the collection, in the range [`docFreq()` .. `CollectionStatistics.sumTotalTermFreq()`].

  This is the token count for the term: the number of times it appears in the field across all documents.

  This value is always a positive number, always at least `docFreq()`, and never exceeds `CollectionStatistics.sumTotalTermFreq()`. @see TermsEnum#totalTermFreq()

public record TermStatistics(BytesRef term, long docFreq, long totalTermFreq) extends Record
Contains statistics for a specific term

This class holds statistics for this term across all documents for scoring purposes:

- `docFreq`: number of documents this term occurs in.
- `totalTermFreq`: number of tokens for this term.

The following conditions are always true:

- All statistics are positive integers: never zero or negative.
- `docFreq` <= `totalTermFreq`
- `docFreq` <= `sumDocFreq` of the collection
- `totalTermFreq` <= `sumTotalTermFreq` of the collection

Values may include statistics on deleted documents that have not yet been merged away.

Be careful when performing calculations on these values because they are represented as 64-bit integer values, you may need to cast to `double` for your use.

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

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TermStatistics(BytesRef term, long docFreq, long totalTermFreq)`
  Creates statistics instance for a term.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `long`
  `docFreq()`
  Returns the value of the `docFreq` record component.
  `final boolean`
  `equals(Object o)`
  Indicates whether some other object is "equal to" this one.
  `final int`
  `hashCode()`
  Returns a hash code value for this object.
  `BytesRef`
  `term()`
  Returns the value of the `term` record component.
  `final String`
  `toString()`
  Returns a string representation of this record class.
  `long`
  `totalTermFreq()`
  Returns the value of the `totalTermFreq` record component.

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

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

- ## Constructor Details

  - ### TermStatistics

    public TermStatistics(BytesRef term, long docFreq, long totalTermFreq)
    Creates statistics instance for a term.
    Throws:
      `NullPointerException` - if `term` is `null`.
      `IllegalArgumentException` - if `docFreq` is negative or zero.
      `IllegalArgumentException` - if `totalTermFreq` is less than `docFreq`.

- ## Method Details

  - ### toString

    public final String toString()
    Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
    Specified by:
      `toString` in class `Record`
    Returns:
      a string representation of this object

  - ### hashCode

    public final int hashCode()
    Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
    Specified by:
      `hashCode` in class `Record`
    Returns:
      a hash code value for this object

  - ### equals

    public final boolean equals(Object o)
    Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with `Objects::equals(Object,Object)`; primitive components are compared with '=='.
    Specified by:
      `equals` in class `Record`
    Parameters:
      `o` - the object with which to compare
    Returns:
      `true` if this object is the same as the `o` argument; `false` otherwise.

  - ### term

    public BytesRef term()
    Returns the value of the `term` record component.
    Returns:
      the value of the `term` record component

  - ### docFreq

    public long docFreq()
    Returns the value of the `docFreq` record component.
    Returns:
      the value of the `docFreq` record component

  - ### totalTermFreq

    public long totalTermFreq()
    Returns the value of the `totalTermFreq` record component.
    Returns:
      the value of the `totalTermFreq` record component