Class WeightedSpanTermExtractor
- java.lang.Object
-
- org.apache.lucene.search.highlight.WeightedSpanTermExtractor
-
public class WeightedSpanTermExtractor extends Object
Class used to extractWeightedSpanTerm
s from aQuery
based on whetherTerm
s from theQuery
are contained in a suppliedTokenStream
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
WeightedSpanTermExtractor.PositionCheckingMap<K>
This class makes sure that if both position sensitive and insensitive versions of the same term are added, the position insensitive one wins.
-
Constructor Summary
Constructors Constructor Description WeightedSpanTermExtractor()
WeightedSpanTermExtractor(String defaultField)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
collectSpanQueryFields(SpanQuery spanQuery, Set<String> fieldNames)
protected void
extract(Query query, Map<String,WeightedSpanTerm> terms)
Fills aMap
with <@link WeightedSpanTerm>s using the terms from the suppliedQuery
.protected void
extractUnknownQuery(Query query, Map<String,WeightedSpanTerm> terms)
protected void
extractWeightedSpanTerms(Map<String,WeightedSpanTerm> terms, SpanQuery spanQuery)
Fills aMap
with <@link WeightedSpanTerm>s using the terms from the suppliedSpanQuery
.protected void
extractWeightedTerms(Map<String,WeightedSpanTerm> terms, Query query)
Fills aMap
with <@link WeightedSpanTerm>s using the terms from the suppliedQuery
.protected boolean
fieldNameComparator(String fieldNameToCheck)
Necessary to implement matches for queries againstdefaultField
boolean
getExpandMultiTermQuery()
protected IndexReader
getReaderForField(String field)
TokenStream
getTokenStream()
Map<String,WeightedSpanTerm>
getWeightedSpanTerms(Query query, TokenStream tokenStream)
Creates a Map ofWeightedSpanTerms
from the givenQuery
andTokenStream
.Map<String,WeightedSpanTerm>
getWeightedSpanTerms(Query query, TokenStream tokenStream, String fieldName)
Creates a Map ofWeightedSpanTerms
from the givenQuery
andTokenStream
.Map<String,WeightedSpanTerm>
getWeightedSpanTermsWithScores(Query query, TokenStream tokenStream, String fieldName, IndexReader reader)
Creates a Map ofWeightedSpanTerms
from the givenQuery
andTokenStream
.boolean
isCachedTokenStream()
protected boolean
mustRewriteQuery(SpanQuery spanQuery)
void
setExpandMultiTermQuery(boolean expandMultiTermQuery)
protected void
setMaxDocCharsToAnalyze(int maxDocCharsToAnalyze)
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.
-
-
-
Constructor Detail
-
WeightedSpanTermExtractor
public WeightedSpanTermExtractor()
-
WeightedSpanTermExtractor
public WeightedSpanTermExtractor(String defaultField)
-
-
Method Detail
-
extract
protected void extract(Query query, Map<String,WeightedSpanTerm> terms) throws IOException
Fills aMap
with <@link WeightedSpanTerm>s using the terms from the suppliedQuery
.- Parameters:
query
- Query to extract Terms fromterms
- Map to place created WeightedSpanTerms in- Throws:
IOException
-
extractUnknownQuery
protected void extractUnknownQuery(Query query, Map<String,WeightedSpanTerm> terms) throws IOException
- Throws:
IOException
-
extractWeightedSpanTerms
protected void extractWeightedSpanTerms(Map<String,WeightedSpanTerm> terms, SpanQuery spanQuery) throws IOException
Fills aMap
with <@link WeightedSpanTerm>s using the terms from the suppliedSpanQuery
.- Parameters:
terms
- Map to place created WeightedSpanTerms inspanQuery
- SpanQuery to extract Terms from- Throws:
IOException
-
extractWeightedTerms
protected void extractWeightedTerms(Map<String,WeightedSpanTerm> terms, Query query) throws IOException
Fills aMap
with <@link WeightedSpanTerm>s using the terms from the suppliedQuery
.- Parameters:
terms
- Map to place created WeightedSpanTerms inquery
- Query to extract Terms from- Throws:
IOException
-
fieldNameComparator
protected boolean fieldNameComparator(String fieldNameToCheck)
Necessary to implement matches for queries againstdefaultField
-
getReaderForField
protected IndexReader getReaderForField(String field) throws IOException
- Throws:
IOException
-
getWeightedSpanTerms
public Map<String,WeightedSpanTerm> getWeightedSpanTerms(Query query, TokenStream tokenStream) throws IOException
Creates a Map ofWeightedSpanTerms
from the givenQuery
andTokenStream
.- Parameters:
query
- that caused hittokenStream
- of text to be highlighted- Returns:
- Map containing WeightedSpanTerms
- Throws:
IOException
-
getWeightedSpanTerms
public Map<String,WeightedSpanTerm> getWeightedSpanTerms(Query query, TokenStream tokenStream, String fieldName) throws IOException
Creates a Map ofWeightedSpanTerms
from the givenQuery
andTokenStream
.- Parameters:
query
- that caused hittokenStream
- of text to be highlightedfieldName
- restricts Term's used based on field name- Returns:
- Map containing WeightedSpanTerms
- Throws:
IOException
-
getWeightedSpanTermsWithScores
public Map<String,WeightedSpanTerm> getWeightedSpanTermsWithScores(Query query, TokenStream tokenStream, String fieldName, IndexReader reader) throws IOException
Creates a Map ofWeightedSpanTerms
from the givenQuery
andTokenStream
. Uses a suppliedIndexReader
to properly weight terms (for gradient highlighting).- Parameters:
query
- that caused hittokenStream
- of text to be highlightedfieldName
- restricts Term's used based on field namereader
- to use for scoring- Returns:
- Map of WeightedSpanTerms with quasi tf/idf scores
- Throws:
IOException
-
collectSpanQueryFields
protected void collectSpanQueryFields(SpanQuery spanQuery, Set<String> fieldNames)
-
mustRewriteQuery
protected boolean mustRewriteQuery(SpanQuery spanQuery)
-
getExpandMultiTermQuery
public boolean getExpandMultiTermQuery()
-
setExpandMultiTermQuery
public void setExpandMultiTermQuery(boolean expandMultiTermQuery)
-
isCachedTokenStream
public boolean isCachedTokenStream()
-
getTokenStream
public TokenStream getTokenStream()
-
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.- Parameters:
wrap
-
-
setMaxDocCharsToAnalyze
protected final void setMaxDocCharsToAnalyze(int maxDocCharsToAnalyze)
-
-