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 2020/08/06 11:19:01 UTC
[lucene-solr] branch branch_8x updated: LUCENE-9427: Fuzzy query
should always call consumeTermsMatching in visitor
This is an automated email from the ASF dual-hosted git repository.
romseygeek pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/branch_8x by this push:
new b680635 LUCENE-9427: Fuzzy query should always call consumeTermsMatching in visitor
b680635 is described below
commit b6806355c3cf7c866ab3b2302b78f2b478691876
Author: Julie Tibshirani <ju...@elastic.co>
AuthorDate: Thu Aug 6 11:56:47 2020 +0100
LUCENE-9427: Fuzzy query should always call consumeTermsMatching in visitor
---
lucene/CHANGES.txt | 5 ++++-
lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java | 6 +-----
.../lucene/search/uhighlight/TestUnifiedHighlighterMTQ.java | 11 ++++++++++-
3 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index c1ae899..352810c 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -42,7 +42,10 @@ Optimizations
Bug Fixes
---------------------
-(No changes)
+
+* LUCENE-9427: Fix a regression where the unified highlighter didn't produce
+ highlights on fuzzy queries that correspond to exact matches. (Julie Tibshirani)
+
Documentation
---------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java b/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java
index b706024..91bfea2 100644
--- a/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java
@@ -159,11 +159,7 @@ public class FuzzyQuery extends MultiTermQuery {
@Override
public void visit(QueryVisitor visitor) {
if (visitor.acceptField(field)) {
- if (maxEdits == 0 || prefixLength >= term.text().length()) {
- visitor.consumeTerms(this, term);
- } else {
- visitor.consumeTermsMatching(this, term.field(), () -> getAutomata().runAutomaton);
- }
+ visitor.consumeTermsMatching(this, term.field(), () -> getAutomata().runAutomaton);
}
}
diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterMTQ.java b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterMTQ.java
index 098a89b..e0b5deb 100644
--- a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterMTQ.java
+++ b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterMTQ.java
@@ -240,7 +240,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase {
ir.close();
}
- public void testOneFuzzy() throws Exception {
+ public void testFuzzy() throws Exception {
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, indexAnalyzer);
Field body = new Field("body", "", fieldType);
@@ -274,6 +274,15 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase {
assertEquals("This is a <b>test</b>.", snippets[0]);
assertEquals("<b>Test</b> a one sentence document.", snippets[1]);
+ // with zero max edits
+ query = new FuzzyQuery(new Term("body", "test"), 0, 2);
+ topDocs = searcher.search(query, 10, Sort.INDEXORDER);
+ assertEquals(2, topDocs.totalHits.value);
+ snippets = highlighter.highlight("body", query, topDocs);
+ assertEquals(2, snippets.length);
+ assertEquals("This is a <b>test</b>.", snippets[0]);
+ assertEquals("<b>Test</b> a one sentence document.", snippets[1]);
+
// wrong field
highlighter.setFieldMatcher(null);//default
BooleanQuery bq = new BooleanQuery.Builder()