org.apache.lucene.search

## Class ConstantScoreWeight

- java.lang.Object
- - org.apache.lucene.search.Weight
  - - org.apache.lucene.search.ConstantScoreWeight

- Direct Known Subclasses:
    RandomAccessWeight

      public abstract class ConstantScoreWeight
      extends Weight

  A Weight that has a constant score equal to the boost of the wrapped query. This is typically useful when building queries which do not produce meaningful scores and are mostly useful for filtering.
  NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.lucene.search.Weight

      `Weight.DefaultBulkScorer`

  - ### Field Summary

    - ### Fields inherited from class org.apache.lucene.search.Weight

      `parentQuery`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ConstantScoreWeight(Query query)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected float` | `boost()` Return the boost for this weight.
    `Explanation` | `explain(LeafReaderContext context, int doc)` An explanation of the score computation for the named document.
    `void` | `extractTerms(Set<Term> terms)` Expert: adds all terms occurring in this query to the terms set.
    `float` | `getValueForNormalization()` The value for normalization of contained query clauses (e.g.
    `void` | `normalize(float norm, float boost)` Assigns the query normalization factor and boost to this.
    `protected float` | `queryNorm()` Return the normalization factor for this weight.
    `protected float` | `score()` Return the score produced by this `Weight`.

    - ### Methods inherited from class org.apache.lucene.search.Weight

      `bulkScorer, getQuery, scorer, scorerSupplier`

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

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

- - ### Constructor Detail

    - #### ConstantScoreWeight

          protected ConstantScoreWeight(Query query)

  - ### Method Detail

    - #### extractTerms

          public void extractTerms(Set<Term> terms)

      Description copied from class: `Weight`
      Expert: adds all terms occurring in this query to the terms set. If the `Weight` was created with `needsScores == true` then this method will only extract terms which are used for scoring, otherwise it will extract all terms which are used for matching.
      Specified by:
        `extractTerms` in class `Weight`

    - #### getValueForNormalization

          public final float getValueForNormalization()
                                               throws IOException

      Description copied from class: `Weight`
      The value for normalization of contained query clauses (e.g. sum of squared weights).
      Specified by:
        `getValueForNormalization` in class `Weight`
      Throws:
        `IOException`

    - #### normalize

          public void normalize(float norm,
                                float boost)

      Description copied from class: `Weight`
      Assigns the query normalization factor and boost to this.
      Specified by:
        `normalize` in class `Weight`

    - #### queryNorm

          protected final float queryNorm()

      Return the normalization factor for this weight.

    - #### boost

          protected final float boost()

      Return the boost for this weight.

    - #### score

          protected final float score()

      Return the score produced by this `Weight`.

    - #### explain

          public Explanation explain(LeafReaderContext context,
                                     int doc)
                              throws IOException

      Description copied from class: `Weight`
      An explanation of the score computation for the named document.
      Specified by:
        `explain` in class `Weight`
      Parameters:
        `context` - the readers context to create the `Explanation` for.
        `doc` - the document's id relative to the given context's reader
      Returns:
        an Explanation for the score
      Throws:
        `IOException` - if an `IOException` occurs

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