Class WeightedSpanTermExtractor
- java.lang.Object
-
- org.apache.lucene.search.highlight.WeightedSpanTermExtractor
-
public class WeightedSpanTermExtractor extends Object
Class used to extractWeightedSpanTerms from aQuerybased on whetherTerms from theQueryare contained in a suppliedTokenStream.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classWeightedSpanTermExtractor.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 voidcollectSpanQueryFields(org.apache.lucene.search.spans.SpanQuery spanQuery, Set<String> fieldNames)protected voidextract(org.apache.lucene.search.Query query, Map<String,WeightedSpanTerm> terms)Fills aMapwith <@link WeightedSpanTerm>s using the terms from the suppliedQuery.protected voidextractUnknownQuery(org.apache.lucene.search.Query query, Map<String,WeightedSpanTerm> terms)protected voidextractWeightedSpanTerms(Map<String,WeightedSpanTerm> terms, org.apache.lucene.search.spans.SpanQuery spanQuery)Fills aMapwith <@link WeightedSpanTerm>s using the terms from the suppliedSpanQuery.protected voidextractWeightedTerms(Map<String,WeightedSpanTerm> terms, org.apache.lucene.search.Query query)Fills aMapwith <@link WeightedSpanTerm>s using the terms from the suppliedQuery.protected booleanfieldNameComparator(String fieldNameToCheck)Necessary to implement matches for queries againstdefaultFieldbooleangetExpandMultiTermQuery()protected org.apache.lucene.index.IndexReadergetReaderForField(String field)org.apache.lucene.analysis.TokenStreamgetTokenStream()Map<String,WeightedSpanTerm>getWeightedSpanTerms(org.apache.lucene.search.Query query, org.apache.lucene.analysis.TokenStream tokenStream)Creates a Map ofWeightedSpanTermsfrom the givenQueryandTokenStream.Map<String,WeightedSpanTerm>getWeightedSpanTerms(org.apache.lucene.search.Query query, org.apache.lucene.analysis.TokenStream tokenStream, String fieldName)Creates a Map ofWeightedSpanTermsfrom the givenQueryandTokenStream.Map<String,WeightedSpanTerm>getWeightedSpanTermsWithScores(org.apache.lucene.search.Query query, org.apache.lucene.analysis.TokenStream tokenStream, String fieldName, org.apache.lucene.index.IndexReader reader)Creates a Map ofWeightedSpanTermsfrom the givenQueryandTokenStream.booleanisCachedTokenStream()protected booleanmustRewriteQuery(org.apache.lucene.search.spans.SpanQuery spanQuery)voidsetExpandMultiTermQuery(boolean expandMultiTermQuery)protected 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.
-
-
-
Constructor Detail
-
WeightedSpanTermExtractor
public WeightedSpanTermExtractor()
-
WeightedSpanTermExtractor
public WeightedSpanTermExtractor(String defaultField)
-
-
Method Detail
-
extract
protected void extract(org.apache.lucene.search.Query query, Map<String,WeightedSpanTerm> terms) throws IOExceptionFills aMapwith <@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(org.apache.lucene.search.Query query, Map<String,WeightedSpanTerm> terms) throws IOException- Throws:
IOException
-
extractWeightedSpanTerms
protected void extractWeightedSpanTerms(Map<String,WeightedSpanTerm> terms, org.apache.lucene.search.spans.SpanQuery spanQuery) throws IOException
Fills aMapwith <@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, org.apache.lucene.search.Query query) throws IOException
Fills aMapwith <@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 org.apache.lucene.index.IndexReader getReaderForField(String field) throws IOException
- Throws:
IOException
-
getWeightedSpanTerms
public Map<String,WeightedSpanTerm> getWeightedSpanTerms(org.apache.lucene.search.Query query, org.apache.lucene.analysis.TokenStream tokenStream) throws IOException
Creates a Map ofWeightedSpanTermsfrom the givenQueryandTokenStream.- Parameters:
query- that caused hittokenStream- of text to be highlighted- Returns:
- Map containing WeightedSpanTerms
- Throws:
IOException
-
getWeightedSpanTerms
public Map<String,WeightedSpanTerm> getWeightedSpanTerms(org.apache.lucene.search.Query query, org.apache.lucene.analysis.TokenStream tokenStream, String fieldName) throws IOException
Creates a Map ofWeightedSpanTermsfrom the givenQueryandTokenStream.- 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(org.apache.lucene.search.Query query, org.apache.lucene.analysis.TokenStream tokenStream, String fieldName, org.apache.lucene.index.IndexReader reader) throws IOException
Creates a Map ofWeightedSpanTermsfrom the givenQueryandTokenStream. Uses a suppliedIndexReaderto 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(org.apache.lucene.search.spans.SpanQuery spanQuery, Set<String> fieldNames)
-
mustRewriteQuery
protected boolean mustRewriteQuery(org.apache.lucene.search.spans.SpanQuery spanQuery)
-
getExpandMultiTermQuery
public boolean getExpandMultiTermQuery()
-
setExpandMultiTermQuery
public void setExpandMultiTermQuery(boolean expandMultiTermQuery)
-
isCachedTokenStream
public boolean isCachedTokenStream()
-
getTokenStream
public org.apache.lucene.analysis.TokenStream getTokenStream()
-
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.- Parameters:
wrap-
-
setMaxDocCharsToAnalyze
protected final void setMaxDocCharsToAnalyze(int maxDocCharsToAnalyze)
-
-