- java.lang.Object
-
- org.apache.lucene.search.highlight.QueryScorer
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
defaultField
private boolean
expandMultiTermQuery
private java.lang.String
field
private java.util.Map<java.lang.String,WeightedSpanTerm>
fieldWeightedSpanTerms
private java.util.Set<java.lang.String>
foundTerms
private int
maxCharsToAnalyze
private float
maxTermWeight
private PositionIncrementAttribute
posIncAtt
private int
position
private Query
query
private IndexReader
reader
private boolean
skipInitExtractor
private CharTermAttribute
termAtt
private float
totalScore
private boolean
usePayloads
private boolean
wrapToCaching
-
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 float
getFragmentScore()
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
getMaxTermWeight()
float
getTokenScore()
Called for each token in the current fragment.WeightedSpanTerm
getWeightedSpanTerm(java.lang.String token)
Retrieve theWeightedSpanTerm
for the specified token.TokenStream
init(TokenStream tokenStream)
Called to init the Scorer with aTokenStream
.private void
init(Query query, java.lang.String field, IndexReader reader, boolean expandMultiTermQuery)
private TokenStream
initExtractor(TokenStream tokenStream)
boolean
isExpandMultiTermQuery()
boolean
isUsePayloads()
Whether or not we should capture payloads inMemoryIndex
at each position so that queries can access them.protected WeightedSpanTermExtractor
newTermExtractor(java.lang.String defaultField)
void
setExpandMultiTermQuery(boolean expandMultiTermQuery)
Controls whether or not multi-term queries are expanded against aMemoryIndex
IndexReader
.void
setMaxDocCharsToAnalyze(int maxDocCharsToAnalyze)
void
setUsePayloads(boolean usePayloads)
void
setWrapIfNotCachingTokenFilter(boolean wrap)
By default,TokenStream
s that are not of the typeCachingTokenFilter
are wrapped in aCachingTokenFilter
to ensure an efficient reset - if you are already using a different cachingTokenStream
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.
-
-
-
Field Detail
-
totalScore
private float totalScore
-
foundTerms
private java.util.Set<java.lang.String> foundTerms
-
fieldWeightedSpanTerms
private java.util.Map<java.lang.String,WeightedSpanTerm> fieldWeightedSpanTerms
-
maxTermWeight
private float maxTermWeight
-
position
private int position
-
defaultField
private java.lang.String defaultField
-
termAtt
private CharTermAttribute termAtt
-
posIncAtt
private PositionIncrementAttribute posIncAtt
-
expandMultiTermQuery
private boolean expandMultiTermQuery
-
query
private Query query
-
field
private java.lang.String field
-
reader
private IndexReader reader
-
skipInitExtractor
private boolean skipInitExtractor
-
wrapToCaching
private boolean wrapToCaching
-
maxCharsToAnalyze
private int maxCharsToAnalyze
-
usePayloads
private boolean usePayloads
-
-
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
-IndexReader
to 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
-IndexReader
to 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-createdWeightedSpanTerm
s
-
-
Method Detail
-
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
-
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. 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)
-
init
public TokenStream init(TokenStream tokenStream) throws java.io.IOException
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. - Throws:
java.io.IOException
- If there is a low-level I/O error
-
getWeightedSpanTerm
public WeightedSpanTerm getWeightedSpanTerm(java.lang.String token)
Retrieve theWeightedSpanTerm
for the specified token. Useful for passing Span information to aFragmenter
.- Parameters:
token
- to getWeightedSpanTerm
for- Returns:
- WeightedSpanTerm for token
-
init
private void init(Query query, java.lang.String field, IndexReader reader, boolean expandMultiTermQuery)
-
initExtractor
private TokenStream initExtractor(TokenStream tokenStream) throws java.io.IOException
- Throws:
java.io.IOException
-
newTermExtractor
protected WeightedSpanTermExtractor newTermExtractor(java.lang.String defaultField)
-
startFragment
public void startFragment(TextFragment newFragment)
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
-
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 aMemoryIndex
IndexReader
.- Parameters:
expandMultiTermQuery
- true if multi-term queries should be expanded
-
isUsePayloads
public boolean isUsePayloads()
Whether or not we should capture payloads inMemoryIndex
at each position so that queries can access them. This does not apply to term vector based TokenStreams, which support payloads only when the term vector has them.
-
setUsePayloads
public void setUsePayloads(boolean usePayloads)
-
setWrapIfNotCachingTokenFilter
public void setWrapIfNotCachingTokenFilter(boolean wrap)
By default,TokenStream
s that are not of the typeCachingTokenFilter
are wrapped in aCachingTokenFilter
to ensure an efficient reset - if you are already using a different cachingTokenStream
impl and you don't want it to be wrapped, set this to false. Note that term-vector based tokenstreams are detected and won't be wrapped either.
-
setMaxDocCharsToAnalyze
public void setMaxDocCharsToAnalyze(int maxDocCharsToAnalyze)
-
-