## org.apache.lucene.search.highlight
Class QueryTermScorer

    java.lang.Object
      org.apache.lucene.search.highlight.QueryTermScorer

All Implemented Interfaces:
  Scorer

    public class QueryTermScorer

extends java.lang.Object
implements Scorer

`Scorer` implementation which scores text fragments by the number of unique query terms found. This class uses the `QueryTermExtractor` class to process determine the query terms and their boosts to be used.

Constructor Summary
`QueryTermScorer(org.apache.lucene.search.Query query)`
`QueryTermScorer(org.apache.lucene.search.Query query, org.apache.lucene.index.IndexReader reader, java.lang.String fieldName)`
`QueryTermScorer(org.apache.lucene.search.Query query, java.lang.String fieldName)`
`QueryTermScorer(WeightedTerm[] weightedTerms)`

Method Summary
`void` `allFragmentsProcessed()`
`float` `getFragmentScore()` Called when the `Highlighter` has no more tokens for the current fragment - the Scorer returns the weighting it has derived for the most recent fragment, typically based on the results of `Scorer.getTokenScore()`.
`float` `getMaxTermWeight()`
`float` `getTokenScore()` Called for each token in the current fragment.
`org.apache.lucene.analysis.TokenStream` `init(org.apache.lucene.analysis.TokenStream tokenStream)` Called to init the Scorer with a `TokenStream`.
`void` `startFragment(TextFragment newFragment)` Called when a new fragment is started for consideration.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### QueryTermScorer

    public QueryTermScorer(org.apache.lucene.search.Query query)

Parameters:
  `query` - a Lucene query (ideally rewritten using query.rewrite before being passed to this class and the searcher)

### QueryTermScorer

    public QueryTermScorer(org.apache.lucene.search.Query query,
                           java.lang.String fieldName)

Parameters:
  `query` - a Lucene query (ideally rewritten using query.rewrite before being passed to this class and the searcher)
  `fieldName` - the Field name which is used to match Query terms

### QueryTermScorer

    public QueryTermScorer(org.apache.lucene.search.Query query,
                           org.apache.lucene.index.IndexReader reader,
                           java.lang.String fieldName)

Parameters:
  `query` - a Lucene query (ideally rewritten using query.rewrite before being passed to this class and the searcher)
  `reader` - used to compute IDF which can be used to a) score selected fragments better b) use graded highlights eg set font color intensity
  `fieldName` - the field on which Inverse Document Frequency (IDF) calculations are based

### QueryTermScorer

    public QueryTermScorer(WeightedTerm[] weightedTerms)

Method Detail

### init

    public org.apache.lucene.analysis.TokenStream init(org.apache.lucene.analysis.TokenStream tokenStream)

  Description copied from interface: `Scorer`
  Called to init the Scorer with a `TokenStream`. You can grab references to the attributes you are interested in here and access them from `Scorer.getTokenScore()`.

  Specified by:
    `init` in interface `Scorer`
  Parameters:
    `tokenStream` - the `TokenStream` that will be scored.
  Returns:
    either a `TokenStream` that the Highlighter should continue using (eg if you read the tokenSream in this method) or null to continue using the same `TokenStream` that was passed in.

### startFragment

    public void startFragment(TextFragment newFragment)

  Description copied from interface: `Scorer`
  Called when a new fragment is started for consideration.

  Specified by:
    `startFragment` in interface `Scorer`
  Parameters:
    `newFragment` - the fragment that will be scored next

### getTokenScore

    public float getTokenScore()

  Description copied from interface: `Scorer`
  Called for each token in the current fragment. The `Highlighter` will increment the `TokenStream` passed to init on every call.

  Specified by:
    `getTokenScore` in interface `Scorer`
  Returns:
    a score which is passed to the `Highlighter` class to influence the mark-up of the text (this return value is NOT used to score the fragment)

### getFragmentScore

    public float getFragmentScore()

  Description copied from interface: `Scorer`
  Called when the `Highlighter` has no more tokens for the current fragment - the Scorer returns the weighting it has derived for the most recent fragment, typically based on the results of `Scorer.getTokenScore()`.

  Specified by:
    `getFragmentScore` in interface `Scorer`

### allFragmentsProcessed

    public void allFragmentsProcessed()

### getMaxTermWeight

    public float getMaxTermWeight()

  Returns:
    The highest weighted term (useful for passing to GradientFormatter to set top end of coloring scale.

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