org.apache.lucene.search

## Class ConstantScoreQuery

- java.lang.Object
- - org.apache.lucene.search.Query
  - - org.apache.lucene.search.ConstantScoreQuery

- All Implemented Interfaces:
    Cloneable

      public final class ConstantScoreQuery
      extends Query

  A query that wraps another query and simply returns a constant score equal to 1 for every document that matches the query. It therefore simply strips of all scores and always returns 1.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `ConstantScoreQuery.ConstantBulkScorer` We return this as our `BulkScorer` so that if the CSQ wraps a query with its own optimized top-level scorer (e.g.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ConstantScoreQuery(Query query)` Strips off scores from the passed in Query.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Weight` | `createWeight(IndexSearcher searcher, boolean needsScores)` Expert: Constructs an appropriate Weight implementation for this query.
    `boolean` | `equals(Object o)`
    `Query` | `getQuery()` Returns the encapsulated query.
    `int` | `hashCode()`
    `Query` | `rewrite(IndexReader reader)` Expert: called to re-write queries into primitive queries.
    `String` | `toString(String field)` Prints a query to a string, with `field` assumed to be the default field and omitted.

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

      `clone, getBoost, setBoost, toString`

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

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

- - ### Constructor Detail

    - #### ConstantScoreQuery

          public ConstantScoreQuery(Query query)

      Strips off scores from the passed in Query. The hits will get a constant score of 1.

  - ### Method Detail

    - #### getQuery

          public Query getQuery()

      Returns the encapsulated query.

    - #### rewrite

          public Query rewrite(IndexReader reader)
                        throws IOException

      Description copied from class: `Query`
      Expert: called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.
      Overrides:
        `rewrite` in class `Query`
      Throws:
        `IOException`

    - #### createWeight

          public Weight createWeight(IndexSearcher searcher,
                            boolean needsScores)
                              throws IOException

      Description copied from class: `Query`
      Expert: Constructs an appropriate Weight implementation for this query.

      Only implemented by primitive queries, which re-write to themselves.

      Overrides:
        `createWeight` in class `Query`
        `needsScores` - True if document scores (`Scorer.score()`) or match frequencies (`Scorer.freq()`) are needed.
      Throws:
        `IOException`

    - #### toString

          public String toString(String field)

      Description copied from class: `Query`
      Prints a query to a string, with `field` assumed to be the default field and omitted.
      Specified by:
        `toString` in class `Query`

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Query`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Query`

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