Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LUCENE-9427: Ensure unified highlighter considers all terms in fuzzy query. #1671

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ Bug fixes
* LUCENE-9365: FuzzyQuery was missing matches when prefix length was equal to the term length
(Mark Harwood, Mike Drob)

* LUCENE-9427: Fix a regression where the unified highlighter didn't produce
highlights on fuzzy queries that correspond to exact matches. (Julie Tibshirani)

Other

* LUCENE-9391: Upgrade HPPC to 0.8.2. (Haoyu Zhai)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,7 @@ public CompiledAutomaton getAutomata() {
@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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void testOneRegexp() throws Exception {
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);
Expand Down Expand Up @@ -274,6 +274,15 @@ public void testOneFuzzy() throws Exception {
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()
Expand Down