No need to rewrite queries in unified highlighter (#11807)

Since QueryVisitor added the ability to signal multi-term queries, the query rewrite
call in UnifiedHighlighter has been essentially useless, and with more aggressive
rewriting this is now causing bugs like #11490. We can safely remove this call.

Fixes #11490
This commit is contained in:
Alan Woodward 2022-10-03 10:15:40 +01:00 committed by GitHub
parent df94e6c005
commit 6bd8733fdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 16 deletions

View File

@ -118,6 +118,8 @@ Bug Fixes
* GITHUB#11768: Taxonomy and SSDV faceting now correctly breaks ties by preferring smaller ordinal
values. (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 all

View File

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