mirror of
https://github.com/apache/lucene.git
synced 2025-02-27 21:09:19 +00:00
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.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.lucene.analysis.CachingTokenFilter;
|
||||||
import org.apache.lucene.analysis.TokenStream;
|
import org.apache.lucene.analysis.TokenStream;
|
||||||
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
|
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
|
||||||
import org.apache.lucene.analysis.tokenattributes.TermAttribute;
|
import org.apache.lucene.analysis.tokenattributes.TermAttribute;
|
||||||
@ -52,6 +53,7 @@ public class QueryScorer implements Scorer {
|
|||||||
private String field;
|
private String field;
|
||||||
private IndexReader reader;
|
private IndexReader reader;
|
||||||
private boolean skipInitExtractor;
|
private boolean skipInitExtractor;
|
||||||
|
private boolean wrapToCaching = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param query Query to use for highlighting
|
* @param query Query to use for highlighting
|
||||||
@ -209,6 +211,7 @@ public class QueryScorer implements Scorer {
|
|||||||
: new WeightedSpanTermExtractor(defaultField);
|
: new WeightedSpanTermExtractor(defaultField);
|
||||||
|
|
||||||
qse.setExpandMultiTermQuery(expandMultiTermQuery);
|
qse.setExpandMultiTermQuery(expandMultiTermQuery);
|
||||||
|
qse.setWrapIfNotCachingTokenFilter(wrapToCaching);
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
this.fieldWeightedSpanTerms = qse.getWeightedSpanTerms(query,
|
this.fieldWeightedSpanTerms = qse.getWeightedSpanTerms(query,
|
||||||
tokenStream, field);
|
tokenStream, field);
|
||||||
@ -249,4 +252,17 @@ public class QueryScorer implements Scorer {
|
|||||||
public void setExpandMultiTermQuery(boolean expandMultiTermQuery) {
|
public void setExpandMultiTermQuery(boolean expandMultiTermQuery) {
|
||||||
this.expandMultiTermQuery = 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 String defaultField;
|
||||||
private boolean expandMultiTermQuery;
|
private boolean expandMultiTermQuery;
|
||||||
private boolean cachedTokenStream;
|
private boolean cachedTokenStream;
|
||||||
|
private boolean wrapToCaching = true;
|
||||||
|
|
||||||
public WeightedSpanTermExtractor() {
|
public WeightedSpanTermExtractor() {
|
||||||
}
|
}
|
||||||
@ -303,7 +304,7 @@ public class WeightedSpanTermExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private IndexReader getReaderForField(String field) throws IOException {
|
private IndexReader getReaderForField(String field) throws IOException {
|
||||||
if(!cachedTokenStream && !(tokenStream instanceof CachingTokenFilter)) {
|
if(wrapToCaching && !cachedTokenStream && !(tokenStream instanceof CachingTokenFilter)) {
|
||||||
tokenStream = new CachingTokenFilter(tokenStream);
|
tokenStream = new CachingTokenFilter(tokenStream);
|
||||||
cachedTokenStream = true;
|
cachedTokenStream = true;
|
||||||
}
|
}
|
||||||
@ -488,4 +489,17 @@ public class WeightedSpanTermExtractor {
|
|||||||
public TokenStream getTokenStream() {
|
public TokenStream getTokenStream() {
|
||||||
return tokenStream;
|
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…
x
Reference in New Issue
Block a user