Apache Lucene open-source search software
No need to rewrite queries in unified highlighter (#11807)
Alan Woodward6bd8733fdbe5
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex e9032231b9e..f1e64372168 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -118,6 +118,8 @@ Bug Fixes* GITHUB#11768: Taxonomy and SSDV faceting now correctly breaks ties by preferring smaller ordinalvalues. (Greg Miller)+* GITHUB#11807: Don't rewrite queries in unified highlighter. (Alan Woodward)+Optimizations---------------------* GITHUB#11738: Optimize MultiTermQueryConstantScoreWrapper when a term is present that matches alldiff --git a/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/UnifiedHighlighter.java b/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/UnifiedHighlighter.javaindex 2d76099ae1c..79894cf5bcb 100644--- a/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/UnifiedHighlighter.java+++ b/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/UnifiedHighlighter.java@@ -44,7 +44,6 @@ import org.apache.lucene.index.IndexOptions;import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.LeafReader;import org.apache.lucene.index.LeafReaderContext;-import org.apache.lucene.index.MultiReader;import org.apache.lucene.index.ReaderUtil;import org.apache.lucene.index.StoredFieldVisitor;import org.apache.lucene.index.Term;@@ -97,18 +96,6 @@ public class UnifiedHighlighter {public static final int DEFAULT_CACHE_CHARS_THRESHOLD = 524288; // ~ 1 MB (2 byte chars)- static final IndexSearcher EMPTY_INDEXSEARCHER;-- static {- try {- IndexReader emptyReader = new MultiReader();- EMPTY_INDEXSEARCHER = new IndexSearcher(emptyReader);- EMPTY_INDEXSEARCHER.setQueryCache(null);- } catch (IOException bogus) {- throw new RuntimeException(bogus);- }- }-protected static final LabelledCharArrayMatcher[] ZERO_LEN_AUTOMATA_ARRAY =new LabelledCharArrayMatcher[0];@@ -452,10 +439,10 @@ public class UnifiedHighlighter {this.cacheFieldValCharsThreshold = builder.cacheFieldValCharsThreshold;}- /** Extracts matching terms after rewriting against an empty index */- protected static Set<Term> extractTerms(Query query) throws IOException {+ /** Extracts matching terms */+ protected static Set<Term> extractTerms(Query query) {Set<Term> queryTerms = new HashSet<>();- EMPTY_INDEXSEARCHER.rewrite(query).visit(QueryVisitor.termCollector(queryTerms));+ query.visit(QueryVisitor.termCollector(queryTerms));return queryTerms;}