## org.apache.lucene.search.function
Class CustomScoreQuery

    java.lang.Object
      org.apache.lucene.search.Query
          org.apache.lucene.search.function.CustomScoreQuery

All Implemented Interfaces:
  java.io.Serializable, java.lang.Cloneable

    public class CustomScoreQuery

extends Query

Query that sets document score as a programmatic function of several (sub) scores:

1. the score of its subQuery (any query)
2. (optional) the score of its ValueSourceQuery (or queries). For most simple/convenient use cases this query is likely to be a `FieldScoreQuery`

Subclasses can modify the computation by overriding `getCustomScoreProvider(org.apache.lucene.index.IndexReader)`.

WARNING: The status of the search.function package is experimental. The APIs introduced here might change in the future and will not be supported anymore in such a case.

See Also:
  Serialized Form

Constructor Summary
`CustomScoreQuery(Query subQuery)` Create a CustomScoreQuery over input subQuery.
`CustomScoreQuery(Query subQuery, ValueSourceQuery valSrcQuery)` Create a CustomScoreQuery over input subQuery and a `ValueSourceQuery`.
`CustomScoreQuery(Query subQuery, ValueSourceQuery[] valSrcQueries)` Create a CustomScoreQuery over input subQuery and a `ValueSourceQuery`.

Method Summary
`java.lang.Object` `clone()` Returns a clone of this query.
`Weight` `createWeight(Searcher searcher)` Expert: Constructs an appropriate Weight implementation for this query.

`Explanation`

`customExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl)`
Deprecated. Will be removed in Lucene 3.1. The doc is relative to the current reader, which is unknown to CustomScoreQuery when using per-segment search (since Lucene 2.9). Please override `getCustomScoreProvider(org.apache.lucene.index.IndexReader)` and return a subclass of `CustomScoreProvider` for the given `IndexReader`.

`Explanation`

`customExplain(int doc, Explanation subQueryExpl, Explanation[] valSrcExpls)`
Deprecated. Will be removed in Lucene 3.1. The doc is relative to the current reader, which is unknown to CustomScoreQuery when using per-segment search (since Lucene 2.9). Please override `getCustomScoreProvider(org.apache.lucene.index.IndexReader)` and return a subclass of `CustomScoreProvider` for the given `IndexReader`.

`float` `customScore(int doc, float subQueryScore, float valSrcScore)` Deprecated. Will be removed in Lucene 3.1. The doc is relative to the current reader, which is unknown to CustomScoreQuery when using per-segment search (since Lucene 2.9). Please override `getCustomScoreProvider(org.apache.lucene.index.IndexReader)` and return a subclass of `CustomScoreProvider` for the given `IndexReader`.
`float` `customScore(int doc, float subQueryScore, float[] valSrcScores)` Deprecated. Will be removed in Lucene 3.1. The doc is relative to the current reader, which is unknown to CustomScoreQuery when using per-segment search (since Lucene 2.9). Please override `getCustomScoreProvider(org.apache.lucene.index.IndexReader)` and return a subclass of `CustomScoreProvider` for the given `IndexReader`.
`boolean` `equals(java.lang.Object o)` Returns true if `o` is equal to this.
`void` `extractTerms(java.util.Set terms)` Expert: adds all terms occurring in this query to the terms set.
`protected CustomScoreProvider` `getCustomScoreProvider(IndexReader reader)` Returns a `CustomScoreProvider` that calculates the custom scores for the given `IndexReader`.
`int` `hashCode()` Returns a hash code value for this object.
`boolean` `isStrict()` Checks if this is strict custom scoring.
`java.lang.String` `name()` A short name of this query, used in `toString(String)`.
`Query` `rewrite(IndexReader reader)` Expert: called to re-write queries into primitive queries.
`void` `setStrict(boolean strict)` Set the strict mode of this query.
`java.lang.String` `toString(java.lang.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
`combine, getBoost, getSimilarity, mergeBooleanQueries, setBoost, toString, weight`

Methods inherited from class java.lang.Object
`finalize, getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### CustomScoreQuery

    public CustomScoreQuery(Query subQuery)

  Create a CustomScoreQuery over input subQuery.

  Parameters:
    `subQuery` - the sub query whose scored is being customed. Must not be null.

### CustomScoreQuery

    public CustomScoreQuery(Query subQuery,
                            ValueSourceQuery valSrcQuery)

  Create a CustomScoreQuery over input subQuery and a `ValueSourceQuery`.

  Parameters:
    `subQuery` - the sub query whose score is being customized. Must not be null.
    `valSrcQuery` - a value source query whose scores are used in the custom score computation. For most simple/convenient use case this would be a `FieldScoreQuery`. This parameter is optional - it can be null.

### CustomScoreQuery

    public CustomScoreQuery(Query subQuery,
                            ValueSourceQuery[] valSrcQueries)

  Create a CustomScoreQuery over input subQuery and a `ValueSourceQuery`.

  Parameters:
    `subQuery` - the sub query whose score is being customized. Must not be null.
    `valSrcQueries` - value source queries whose scores are used in the custom score computation. For most simple/convenient use case these would be `FieldScoreQueries`. This parameter is optional - it can be null or even an empty array.

Method Detail

### rewrite

    public Query rewrite(IndexReader reader)
                  throws java.io.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:
    `java.io.IOException`

### extractTerms

    public void extractTerms(java.util.Set terms)

  Description copied from class: `Query`
  Expert: adds all terms occurring in this query to the terms set. Only works if this query is in its `rewritten` form.

  Overrides:
    `extractTerms` in class `Query`

### clone

    public java.lang.Object clone()

  Description copied from class: `Query`
  Returns a clone of this query.

  Overrides:
    `clone` in class `Query`

### toString

    public java.lang.String toString(java.lang.String field)

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

  The representation used is one that is supposed to be readable by `QueryParser`. However, there are the following limitations:

  - If the query was created by the parser, the printed representation may not be exactly what was parsed. For example, characters that need to be escaped will be represented without the required backslash.
  - Some of the more complicated queries (e.g. span queries) don't have a representation that can be parsed by QueryParser.

  Specified by:
    `toString` in class `Query`

### equals

    public boolean equals(java.lang.Object o)

  Returns true if `o` is equal to this.

  Overrides:
    `equals` in class `Query`

### hashCode

    public int hashCode()

  Returns a hash code value for this object.

  Overrides:
    `hashCode` in class `Query`

### getCustomScoreProvider

    protected CustomScoreProvider getCustomScoreProvider(IndexReader reader)
                                                  throws java.io.IOException

  Returns a `CustomScoreProvider` that calculates the custom scores for the given `IndexReader`. The default implementation returns a default implementation as specified in the docs of `CustomScoreProvider`.

  Throws:
    `java.io.IOException`
  Since:
    2.9.2

### customScore

    public float customScore(int doc,
                             float subQueryScore,
                             float[] valSrcScores)

  Deprecated. Will be removed in Lucene 3.1. The doc is relative to the current reader, which is unknown to CustomScoreQuery when using per-segment search (since Lucene 2.9). Please override `getCustomScoreProvider(org.apache.lucene.index.IndexReader)` and return a subclass of `CustomScoreProvider` for the given `IndexReader`.

  Compute a custom score by the subQuery score and a number of ValueSourceQuery scores.

  See Also:
    `CustomScoreProvider.customScore(int,float,float[])`

### customScore

    public float customScore(int doc,
                             float subQueryScore,
                             float valSrcScore)

  Deprecated. Will be removed in Lucene 3.1. The doc is relative to the current reader, which is unknown to CustomScoreQuery when using per-segment search (since Lucene 2.9). Please override `getCustomScoreProvider(org.apache.lucene.index.IndexReader)` and return a subclass of `CustomScoreProvider` for the given `IndexReader`.

  Compute a custom score by the subQuery score and the ValueSourceQuery score.

  See Also:
    `CustomScoreProvider.customScore(int,float,float)`

### customExplain

    public Explanation customExplain(int doc,
                                     Explanation subQueryExpl,
                                     Explanation[] valSrcExpls)

  Deprecated. Will be removed in Lucene 3.1. The doc is relative to the current reader, which is unknown to CustomScoreQuery when using per-segment search (since Lucene 2.9). Please override `getCustomScoreProvider(org.apache.lucene.index.IndexReader)` and return a subclass of `CustomScoreProvider` for the given `IndexReader`.

  Explain the custom score.

  See Also:
    `CustomScoreProvider.customExplain(int,Explanation,Explanation[])`

### customExplain

    public Explanation customExplain(int doc,
                                     Explanation subQueryExpl,
                                     Explanation valSrcExpl)

  Deprecated. Will be removed in Lucene 3.1. The doc is relative to the current reader, which is unknown to CustomScoreQuery when using per-segment search (since Lucene 2.9). Please override `getCustomScoreProvider(org.apache.lucene.index.IndexReader)` and return a subclass of `CustomScoreProvider` for the given `IndexReader`.

  Explain the custom score.

  See Also:
    `CustomScoreProvider.customExplain(int,Explanation,Explanation[])`

### createWeight

    public Weight createWeight(Searcher searcher)
                        throws java.io.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`
  Throws:
    `java.io.IOException`

### isStrict

    public boolean isStrict()

  Checks if this is strict custom scoring. In strict custom scoring, the ValueSource part does not participate in weight normalization. This may be useful when one wants full control over how scores are modified, and does not care about normalizing by the ValueSource part. One particular case where this is useful if for testing this query.

  Note: only has effect when the ValueSource part is not null.

### setStrict

    public void setStrict(boolean strict)

  Set the strict mode of this query.

  Parameters:
    `strict` - The strict mode to set.
  See Also:
    `isStrict()`

### name

    public java.lang.String name()

  A short name of this query, used in `toString(String)`.

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