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:
Mark Robert Miller 2009-08-28 18:31:07 +00:00
parent 92191ada45
commit 886e887b3d
2 changed files with 31 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}