Skip to content

Commit

Permalink
Add LUCENENET-specific backport comment, fix test code style
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin committed Oct 29, 2024
1 parent 75f9974 commit 8ca1322
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/Lucene.Net.Tests/Search/TestFuzzyQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ public virtual void TestFuzziness()
reader.Dispose();
directory.Dispose();
}

// LUCENENET-specific: backported fix from Lucene 9.0.0 (lucene@45611d0, LUCENE-9365)
[Test]
public void TestPrefixLengthEqualStringLength()
{
Expand All @@ -204,7 +206,7 @@ public void TestPrefixLengthEqualStringLength()
AddDoc("b*ab", writer);
AddDoc("b*abc", writer);
AddDoc("b*abcd", writer);
String multibyte = "아프리카코끼리속";
const string multibyte = "아프리카코끼리속"; // LUCENENET-specific: made const
AddDoc(multibyte, writer);
IndexReader reader = writer.GetReader();
IndexSearcher searcher = NewSearcher(reader);
Expand All @@ -226,17 +228,17 @@ public void TestPrefixLengthEqualStringLength()
hits = searcher.Search(query, 1000).ScoreDocs;
assertEquals(3, hits.Length);

maxEdits = 1;
prefixLength = multibyte.Length - 1;
query = new FuzzyQuery(new Term("field", multibyte.Substring(0, prefixLength)), maxEdits, prefixLength);
hits = searcher.Search(query, 1000).ScoreDocs;
assertEquals(1, hits.Length);
maxEdits = 1;
prefixLength = multibyte.Length - 1;
query = new FuzzyQuery(new Term("field", multibyte.Substring(0, prefixLength)), maxEdits, prefixLength);
hits = searcher.Search(query, 1000).ScoreDocs;
assertEquals(1, hits.Length);

reader.DoClose();
directory.Dispose();
}
reader.Dispose();
directory.Dispose();
}

[Test]
[Test]
public virtual void Test2()
{
Directory directory = NewDirectory();
Expand Down
3 changes: 2 additions & 1 deletion src/Lucene.Net/Search/FuzzyQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public FuzzyQuery(Term term)

protected override TermsEnum GetTermsEnum(Terms terms, AttributeSource atts)
{
if (maxEdits == 0 ) // can only match if it's exact
// LUCENENET-specific: backported fix from Lucene 9.0.0 (lucene@45611d0, LUCENE-9365)
if (maxEdits == 0) // can only match if it's exact
{
return new SingleTermsEnum(terms.GetEnumerator(), term.Bytes);
}
Expand Down

0 comments on commit 8ca1322

Please sign in to comment.