diff --git a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/SpanScorer.java b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/SpanScorer.java index 59bdc25c0aa..e0efebb51c5 100644 --- a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/SpanScorer.java +++ b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/SpanScorer.java @@ -25,7 +25,7 @@ public class SpanScorer implements Scorer { private float maxTermWeight; private int position = -1; private String defaultField; - private boolean highlightCnstScrRngQuery; + private static boolean highlightCnstScrRngQuery; /** * @param query @@ -184,7 +184,7 @@ public class SpanScorer implements Scorer { /** * @return whether ConstantScoreRangeQuerys are set to be highlighted */ - public boolean isHighlightCnstScrRngQuery() { + public static boolean isHighlightCnstScrRngQuery() { return highlightCnstScrRngQuery; } @@ -198,12 +198,12 @@ public class SpanScorer implements Scorer { /** * Turns highlighting of ConstantScoreRangeQuery on/off. ConstantScoreRangeQuerys cannot be - * highlighted if you rewrite the query first. + * highlighted if you rewrite the query first. Must be called before SpanScorer construction. * * @param highlightCnstScrRngQuery */ - public void setHighlightCnstScrRngQuery(boolean highlightCnstScrRngQuery) { - this.highlightCnstScrRngQuery = highlightCnstScrRngQuery; + public static void setHighlightCnstScrRngQuery(boolean highlight) { + highlightCnstScrRngQuery = highlight; } /* diff --git a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java index e8af11db145..7a4a373d0eb 100644 --- a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java +++ b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java @@ -179,7 +179,7 @@ public class WeightedSpanTermExtractor { sp.setBoost(query.getBoost()); extractWeightedSpanTerms(terms, sp); } - } else if (query instanceof ConstantScoreRangeQuery) { + } else if (highlightCnstScrRngQuery && query instanceof ConstantScoreRangeQuery) { ConstantScoreRangeQuery q = (ConstantScoreRangeQuery) query; Term lower = new Term(fieldName, q.getLowerVal()); Term upper = new Term(fieldName, q.getUpperVal()); diff --git a/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java b/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java index ff7c8f9280f..edecc937171 100644 --- a/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java +++ b/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java @@ -488,9 +488,10 @@ public class HighlighterTest extends TestCase implements Formatter { tokenStream = new CachingTokenFilter(analyzer.tokenStream(HighlighterTest.FIELD_NAME, new StringReader(text))); + + SpanScorer.setHighlightCnstScrRngQuery(true); scorer = new SpanScorer(query, HighlighterTest.FIELD_NAME, (CachingTokenFilter) tokenStream); - scorer.setHighlightCnstScrRngQuery(true); - + Highlighter highlighter = new Highlighter(this, scorer); ((CachingTokenFilter) tokenStream).reset();