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

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

All Implemented Interfaces:
  Scorer

    public class SpanScorer

extends Object
implements Scorer

`Scorer` implementation which scores text fragments by the number of unique query terms found. This class converts appropriate Querys to SpanQuerys and attempts to score only those terms that participated in generating the 'hit' on the document.

Constructor Summary
`SpanScorer(Query query, String field, CachingTokenFilter cachingTokenFilter)`
`SpanScorer(Query query, String field, CachingTokenFilter cachingTokenFilter, IndexReader reader)`
`SpanScorer(Query query, String field, CachingTokenFilter cachingTokenFilter, IndexReader reader, String defaultField)` As above, but with ability to pass in an `IndexReader`
`SpanScorer(Query query, String field, CachingTokenFilter cachingTokenFilter, String defaultField)`
`SpanScorer(WeightedSpanTerm[] weightedTerms)`

Method Summary
`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 tokens passed to getTokenScore().
`float` `getMaxTermWeight()`
`float` `getTokenScore(Token token)` Called for each token in the current fragment
`WeightedSpanTerm` `getWeightedSpanTerm(String token)` Retrieve the WeightedSpanTerm for the specified token.
`static boolean` `isHighlightCnstScrRngQuery()`
`void` `reset()` If you call Highlighter#getBestFragment() more than once you must reset the SpanScorer between each call.
`static void` `setHighlightCnstScrRngQuery(boolean highlight)` Turns highlighting of ConstantScoreRangeQuery on/off.
`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

### SpanScorer

    public SpanScorer(Query query,
                      String field,
                      CachingTokenFilter cachingTokenFilter)
               throws IOException

Parameters:
  `query` - Query to use for highlighting
  `field` - Field to highlight - pass null to ignore fields
  `tokenStream` - of source text to be highlighted
Throws:
  `IOException`

### SpanScorer

    public SpanScorer(Query query,
                      String field,
                      CachingTokenFilter cachingTokenFilter,
                      IndexReader reader)
               throws IOException

Parameters:
  `query` - Query to use for highlighting
  `field` - Field to highlight - pass null to ignore fields
  `tokenStream` - of source text to be highlighted
  `reader` -
Throws:
  `IOException`

### SpanScorer

    public SpanScorer(Query query,
                      String field,
                      CachingTokenFilter cachingTokenFilter,
                      IndexReader reader,
                      String defaultField)
               throws IOException

  As above, but with ability to pass in an `IndexReader`

  Throws:
    `IOException`

### SpanScorer

    public SpanScorer(Query query,
                      String field,
                      CachingTokenFilter cachingTokenFilter,
                      String defaultField)
               throws IOException

Parameters:
  `defaultField` - - The default field for queries with the field name unspecified
Throws:
  `IOException`

### SpanScorer

    public SpanScorer(WeightedSpanTerm[] weightedTerms)

Parameters:
  `weightedTerms` -

Method Detail

### 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 tokens passed to getTokenScore().

  Specified by:
    `getFragmentScore` in interface `Scorer`

### getMaxTermWeight

    public float getMaxTermWeight()

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

### getTokenScore

    public float getTokenScore(Token token)

  Description copied from interface: `Scorer`
  Called for each token in the current fragment

  Specified by:
    `getTokenScore` in interface `Scorer`
  Parameters:
    `token` - The token to be scored
  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)

### getWeightedSpanTerm

    public WeightedSpanTerm getWeightedSpanTerm(String token)

  Retrieve the WeightedSpanTerm for the specified token. Useful for passing Span information to a Fragmenter.

  Parameters:
    `token` -
  Returns:
    WeightedSpanTerm for token

### isHighlightCnstScrRngQuery

    public static boolean isHighlightCnstScrRngQuery()

  Returns:
    whether ConstantScoreRangeQuerys are set to be highlighted

### reset

    public void reset()

  If you call Highlighter#getBestFragment() more than once you must reset the SpanScorer between each call.

### setHighlightCnstScrRngQuery

    public static void setHighlightCnstScrRngQuery(boolean highlight)

  Turns highlighting of ConstantScoreRangeQuery on/off. ConstantScoreRangeQuerys cannot be highlighted if you rewrite the query first. Must be called before SpanScorer construction.

  Parameters:
    `highlightCnstScrRngQuery` -

### 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`

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