mirror of https://github.com/apache/lucene.git
LUCENE-9427: Fuzzy query should always call consumeTermsMatching in visitor
This commit is contained in:
parent
321c4bbe1f
commit
688583fc2d
|
@ -191,7 +191,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
|
||||
---------------------
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue