mirror of https://github.com/apache/lucene.git
LUCENE-1871: Highlighter wraps caching token filters that are not CachingTokenFilter in CachingTokenFilter
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@808982 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
92191ada45
commit
886e887b3d
|
@ -23,6 +23,7 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.lucene.analysis.CachingTokenFilter;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
|
||||
import org.apache.lucene.analysis.tokenattributes.TermAttribute;
|
||||
|
@ -52,6 +53,7 @@ public class QueryScorer implements Scorer {
|
|||
private String field;
|
||||
private IndexReader reader;
|
||||
private boolean skipInitExtractor;
|
||||
private boolean wrapToCaching = true;
|
||||
|
||||
/**
|
||||
* @param query Query to use for highlighting
|
||||
|
@ -209,6 +211,7 @@ public class QueryScorer implements Scorer {
|
|||
: new WeightedSpanTermExtractor(defaultField);
|
||||
|
||||
qse.setExpandMultiTermQuery(expandMultiTermQuery);
|
||||
qse.setWrapIfNotCachingTokenFilter(wrapToCaching);
|
||||
if (reader == null) {
|
||||
this.fieldWeightedSpanTerms = qse.getWeightedSpanTerms(query,
|
||||
tokenStream, field);
|
||||
|
@ -249,4 +252,17 @@ public class QueryScorer implements Scorer {
|
|||
public void setExpandMultiTermQuery(boolean expandMultiTermQuery) {
|
||||
this.expandMultiTermQuery = expandMultiTermQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, {@link TokenStream}s that are not of the type
|
||||
* {@link CachingTokenFilter} are wrapped in a {@link CachingTokenFilter} to
|
||||
* ensure an efficient reset - if you are already using a different caching
|
||||
* {@link TokenStream} impl and you don't want it to be wrapped, set this to
|
||||
* false.
|
||||
*
|
||||
* @param wrap
|
||||
*/
|
||||
public void setWrapIfNotCachingTokenFilter(boolean wrap) {
|
||||
this.wrapToCaching = wrap;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ public class WeightedSpanTermExtractor {
|
|||
private String defaultField;
|
||||
private boolean expandMultiTermQuery;
|
||||
private boolean cachedTokenStream;
|
||||
private boolean wrapToCaching = true;
|
||||
|
||||
public WeightedSpanTermExtractor() {
|
||||
}
|
||||
|
@ -303,7 +304,7 @@ public class WeightedSpanTermExtractor {
|
|||
}
|
||||
|
||||
private IndexReader getReaderForField(String field) throws IOException {
|
||||
if(!cachedTokenStream && !(tokenStream instanceof CachingTokenFilter)) {
|
||||
if(wrapToCaching && !cachedTokenStream && !(tokenStream instanceof CachingTokenFilter)) {
|
||||
tokenStream = new CachingTokenFilter(tokenStream);
|
||||
cachedTokenStream = true;
|
||||
}
|
||||
|
@ -488,4 +489,17 @@ public class WeightedSpanTermExtractor {
|
|||
public TokenStream getTokenStream() {
|
||||
return tokenStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, {@link TokenStream}s that are not of the type
|
||||
* {@link CachingTokenFilter} are wrapped in a {@link CachingTokenFilter} to
|
||||
* ensure an efficient reset - if you are already using a different caching
|
||||
* {@link TokenStream} impl and you don't want it to be wrapped, set this to
|
||||
* false.
|
||||
*
|
||||
* @param wrap
|
||||
*/
|
||||
public void setWrapIfNotCachingTokenFilter(boolean wrap) {
|
||||
this.wrapToCaching = wrap;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue