You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2022/10/03 09:15:47 UTC

[lucene] branch main updated: No need to rewrite queries in unified highlighter (#11807)

This is an automated email from the ASF dual-hosted git repository.

romseygeek pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new 6bd8733fdbe No need to rewrite queries in unified highlighter (#11807)
6bd8733fdbe is described below

commit 6bd8733fdbe504d5510603723bc1ee6af31a6df3
Author: Alan Woodward <ro...@apache.org>
AuthorDate: Mon Oct 3 10:15:40 2022 +0100

    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
---
 lucene/CHANGES.txt                                    |  2 ++
 .../lucene/search/uhighlight/UnifiedHighlighter.java  | 19 +++----------------
 2 files changed, 5 insertions(+), 16 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 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 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
diff --git a/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/UnifiedHighlighter.java b/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/UnifiedHighlighter.java
index 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;
   }