Class QueryTermScorer
java.lang.Object
org.apache.lucene.search.highlight.QueryTermScorer
- All Implemented Interfaces:
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
ConstructorDescriptionQueryTermScorer
(WeightedTerm[] weightedTerms) QueryTermScorer
(Query query) QueryTermScorer
(Query query, String fieldName) QueryTermScorer
(Query query, IndexReader reader, String fieldName) -
Method Summary
Modifier and TypeMethodDescriptionvoid
float
Called when theHighlighter
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 ofScorer.getTokenScore()
.float
float
Called for each token in the current fragment.init
(TokenStream tokenStream) Called to init the Scorer with aTokenStream
.void
startFragment
(TextFragment newFragment) Called when a new fragment is started for consideration.
-
Constructor Details
-
QueryTermScorer
- Parameters:
query
- a Lucene query (ideally rewritten using query.rewrite before being passed to this class and the searcher)
-
QueryTermScorer
- 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
- 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 intensityfieldName
- the field on which Inverse Document Frequency (IDF) calculations are based
-
QueryTermScorer
-
-
Method Details
-
init
Description copied from interface:Scorer
Called to init the Scorer with aTokenStream
. You can grab references to the attributes you are interested in here and access them fromScorer.getTokenScore()
.- Specified by:
init
in interfaceScorer
- Parameters:
tokenStream
- theTokenStream
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 sameTokenStream
that was passed in.
-
startFragment
Description copied from interface:Scorer
Called when a new fragment is started for consideration.- Specified by:
startFragment
in interfaceScorer
- 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. TheHighlighter
will increment theTokenStream
passed to init on every call.- Specified by:
getTokenScore
in interfaceScorer
- 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 theHighlighter
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 ofScorer.getTokenScore()
.- Specified by:
getFragmentScore
in interfaceScorer
-
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.
-