org.apache.lucene.search.highlight
Class QueryScorer

java.lang.Object
  extended by org.apache.lucene.search.highlight.QueryScorer
All Implemented Interfaces:
Scorer

public class QueryScorer
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
QueryScorer(Query query)
           
QueryScorer(Query query, IndexReader reader, String field)
           
QueryScorer(Query query, IndexReader reader, String field, String defaultField)
           
QueryScorer(Query query, String field)
           
QueryScorer(Query query, String field, String defaultField)
           
QueryScorer(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 results of Scorer.getTokenScore().
 float getMaxTermWeight()
           
 float getTokenScore()
          Called for each token in the current fragment.
 WeightedSpanTerm getWeightedSpanTerm(String token)
          Retrieve the WeightedSpanTerm for the specified token.
 TokenStream init(TokenStream tokenStream)
          Called to init the Scorer with a TokenStream.
 boolean isExpandMultiTermQuery()
           
 void setExpandMultiTermQuery(boolean expandMultiTermQuery)
          Controls whether or not multi-term queries are expanded against a MemoryIndex IndexReader.
 void setMaxDocCharsToAnalyze(int maxDocCharsToAnalyze)
           
 void setWrapIfNotCachingTokenFilter(boolean wrap)
          By default, TokenStreams that are not of the type CachingTokenFilter are wrapped in a CachingTokenFilter to ensure an efficient reset - if you are already using a different caching TokenStream impl and you don't want it to be wrapped, set this to false.
 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

QueryScorer

public QueryScorer(Query query)
Parameters:
query - Query to use for highlighting

QueryScorer

public QueryScorer(Query query,
                   String field)
Parameters:
query - Query to use for highlighting
field - Field to highlight - pass null to ignore fields

QueryScorer

public QueryScorer(Query query,
                   IndexReader reader,
                   String field)
Parameters:
query - Query to use for highlighting
field - Field to highlight - pass null to ignore fields
reader - IndexReader to use for quasi tf/idf scoring

QueryScorer

public QueryScorer(Query query,
                   IndexReader reader,
                   String field,
                   String defaultField)
Parameters:
query - to use for highlighting
reader - IndexReader to use for quasi tf/idf scoring
field - to highlight - pass null to ignore fields
defaultField -

QueryScorer

public QueryScorer(Query query,
                   String field,
                   String defaultField)
Parameters:
defaultField - - The default field for queries with the field name unspecified

QueryScorer

public QueryScorer(WeightedSpanTerm[] weightedTerms)
Parameters:
weightedTerms - an array of pre-created WeightedSpanTerms
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 results of Scorer.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()
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)

init

public TokenStream init(TokenStream tokenStream)
                 throws IOException
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.
Throws:
IOException

getWeightedSpanTerm

public WeightedSpanTerm getWeightedSpanTerm(String token)
Retrieve the WeightedSpanTerm for the specified token. Useful for passing Span information to a Fragmenter.

Parameters:
token - to get WeightedSpanTerm for
Returns:
WeightedSpanTerm for token

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

isExpandMultiTermQuery

public boolean isExpandMultiTermQuery()
Returns:
true if multi-term queries should be expanded

setExpandMultiTermQuery

public void setExpandMultiTermQuery(boolean expandMultiTermQuery)
Controls whether or not multi-term queries are expanded against a MemoryIndex IndexReader.

Parameters:
expandMultiTermQuery - true if multi-term queries should be expanded

setWrapIfNotCachingTokenFilter

public void setWrapIfNotCachingTokenFilter(boolean wrap)
By default, TokenStreams that are not of the type CachingTokenFilter are wrapped in a CachingTokenFilter to ensure an efficient reset - if you are already using a different caching TokenStream impl and you don't want it to be wrapped, set this to false.

Parameters:
wrap -

setMaxDocCharsToAnalyze

public void setMaxDocCharsToAnalyze(int maxDocCharsToAnalyze)


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