Class QueryScorer
- java.lang.Object
-
- org.apache.lucene.search.highlight.QueryScorer
-
-
Constructor Summary
Constructors Constructor Description QueryScorer(WeightedSpanTerm[] weightedTerms)QueryScorer(Query query)QueryScorer(Query query, java.lang.String field)QueryScorer(Query query, java.lang.String field, java.lang.String defaultField)QueryScorer(Query query, IndexReader reader, java.lang.String field)QueryScorer(Query query, IndexReader reader, java.lang.String field, java.lang.String defaultField)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description floatgetFragmentScore()Called when theHighlighterhas 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().floatgetMaxTermWeight()floatgetTokenScore()Called for each token in the current fragment.WeightedSpanTermgetWeightedSpanTerm(java.lang.String token)Retrieve theWeightedSpanTermfor the specified token.TokenStreaminit(TokenStream tokenStream)Called to init the Scorer with aTokenStream.booleanisExpandMultiTermQuery()voidsetExpandMultiTermQuery(boolean expandMultiTermQuery)Controls whether or not multi-term queries are expanded against aMemoryIndexIndexReader.voidsetMaxDocCharsToAnalyze(int maxDocCharsToAnalyze)voidsetWrapIfNotCachingTokenFilter(boolean wrap)By default,TokenStreams that are not of the typeCachingTokenFilterare wrapped in aCachingTokenFilterto ensure an efficient reset - if you are already using a different cachingTokenStreamimpl and you don't want it to be wrapped, set this to false.voidstartFragment(TextFragment newFragment)Called when a new fragment is started for consideration.
-
-
-
Constructor Detail
-
QueryScorer
public QueryScorer(Query query)
- Parameters:
query- Query to use for highlighting
-
QueryScorer
public QueryScorer(Query query, java.lang.String field)
- Parameters:
query- Query to use for highlightingfield- Field to highlight - pass null to ignore fields
-
QueryScorer
public QueryScorer(Query query, IndexReader reader, java.lang.String field)
- Parameters:
query- Query to use for highlightingfield- Field to highlight - pass null to ignore fieldsreader-IndexReaderto use for quasi tf/idf scoring
-
QueryScorer
public QueryScorer(Query query, IndexReader reader, java.lang.String field, java.lang.String defaultField)
- Parameters:
query- to use for highlightingreader-IndexReaderto use for quasi tf/idf scoringfield- to highlight - pass null to ignore fields
-
QueryScorer
public QueryScorer(Query query, java.lang.String field, java.lang.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-createdWeightedSpanTerms
-
-
Method Detail
-
getFragmentScore
public float getFragmentScore()
Description copied from interface:ScorerCalled when theHighlighterhas 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:
getFragmentScorein interfaceScorer
-
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:ScorerCalled for each token in the current fragment. TheHighlighterwill increment theTokenStreampassed to init on every call.- Specified by:
getTokenScorein interfaceScorer- Returns:
- a score which is passed to the
Highlighterclass 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 java.io.IOException
Description copied from interface:ScorerCalled 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:
initin interfaceScorer- Parameters:
tokenStream- theTokenStreamthat will be scored.- Returns:
- either a
TokenStreamthat the Highlighter should continue using (eg if you read the tokenSream in this method) or null to continue using the sameTokenStreamthat was passed in. - Throws:
java.io.IOException- If there is a low-level I/O error
-
getWeightedSpanTerm
public WeightedSpanTerm getWeightedSpanTerm(java.lang.String token)
Retrieve theWeightedSpanTermfor the specified token. Useful for passing Span information to aFragmenter.- Parameters:
token- to getWeightedSpanTermfor- Returns:
- WeightedSpanTerm for token
-
startFragment
public void startFragment(TextFragment newFragment)
Description copied from interface:ScorerCalled when a new fragment is started for consideration.- Specified by:
startFragmentin interfaceScorer- 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 aMemoryIndexIndexReader.- Parameters:
expandMultiTermQuery- true if multi-term queries should be expanded
-
setWrapIfNotCachingTokenFilter
public void setWrapIfNotCachingTokenFilter(boolean wrap)
By default,TokenStreams that are not of the typeCachingTokenFilterare wrapped in aCachingTokenFilterto ensure an efficient reset - if you are already using a different cachingTokenStreamimpl and you don't want it to be wrapped, set this to false.
-
setMaxDocCharsToAnalyze
public void setMaxDocCharsToAnalyze(int maxDocCharsToAnalyze)
-
-