Skip to content

Commit

Permalink
BUG: Lucene.Net.Search.FuzzyTermsEnum: Compare using Lucene.Net.Util.…
Browse files Browse the repository at this point in the history
…NumericUtils.SingleToSortableInt32() to prevent test failures on x86 .NET Framework. This fixes Lucene.Net.Search.TestBooleanQuery.TestBS2DisjunctionNextVsAdvance(), Lucene.Net.Search.TestFuzzyQuery.TestTieBreaker(), and Lucene.Net.Sandbox.Queries.TestSlowFuzzyQuery.TestTieBreaker(). See #269.
  • Loading branch information
NightOwl888 committed Oct 23, 2021
1 parent b02fb28 commit 8e5ecaf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
3 changes: 0 additions & 3 deletions src/Lucene.Net.Tests.Sandbox/Queries/TestSlowFuzzyQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,6 @@ public void TestFuzzinessLong()
* is not implemented correctly, there will be problems!
*/
[Test]
#if NETFRAMEWORK
[AwaitsFix(BugUrl = "https://github.com/apache/lucenenet/issues/269")] // LUCENENET TODO: this test fails on x86 on .NET Framework in Release mode only
#endif
public void TestTieBreaker()
{
Directory directory = NewDirectory();
Expand Down
3 changes: 0 additions & 3 deletions src/Lucene.Net.Tests/Search/TestFuzzyQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,6 @@ public virtual void Test2()
/// is not implemented correctly, there will be problems!
/// </summary>
[Test]
#if NETFRAMEWORK
[AwaitsFix(BugUrl = "https://github.com/apache/lucenenet/issues/269")] // LUCENENET TODO: this test fails on x86 on .NET Framework in Release mode only
#endif
public virtual void TestTieBreaker()
{
Directory directory = NewDirectory();
Expand Down
14 changes: 9 additions & 5 deletions src/Lucene.Net/Search/FuzzyTermsEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ protected virtual void SetEnum(TermsEnum actualEnum)
/// Fired when the max non-competitive boost has changed. This is the hook to
/// swap in a smarter actualEnum
/// </summary>

private void BottomChanged(BytesRef lastTerm, bool init)
{
int oldMaxEdits = m_maxEdits;
Expand All @@ -229,7 +230,11 @@ private void BottomChanged(BytesRef lastTerm, bool init)

// as long as the max non-competitive boost is >= the max boost
// for some edit distance, keep dropping the max edit distance.
while (m_maxEdits > 0 && (termAfter ? bottom >= CalculateMaxBoost(m_maxEdits) : bottom > CalculateMaxBoost(m_maxEdits)))

// LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled
while (m_maxEdits > 0 && (termAfter ?
NumericUtils.SingleToSortableInt32(bottom) >= NumericUtils.SingleToSortableInt32(CalculateMaxBoost(m_maxEdits)) :
NumericUtils.SingleToSortableInt32(bottom) > NumericUtils.SingleToSortableInt32(CalculateMaxBoost(m_maxEdits))))
{
m_maxEdits--;
}
Expand Down Expand Up @@ -380,9 +385,6 @@ public AutomatonFuzzyTermsEnum(FuzzyTermsEnum outerInstance, TermsEnum tenum, Co

/// <summary>
/// Finds the smallest Lev(n) DFA that accepts the term. </summary>
#if NETFRAMEWORK
[MethodImpl(MethodImplOptions.NoOptimization)] // LUCENENET specific: comparing float equality fails in x86 on .NET Framework with optimizations enabled, and is causing the TestTokenLengthOpt test to fail
#endif
protected override AcceptStatus Accept(BytesRef term)
{
//System.out.println("AFTE.accept term=" + term);
Expand Down Expand Up @@ -415,7 +417,9 @@ protected override AcceptStatus Accept(BytesRef term)
{
int codePointCount = UnicodeUtil.CodePointCount(term);
float similarity = 1.0f - ((float)ed / (float)(Math.Min(codePointCount, outerInstance.m_termLength)));
if (similarity > outerInstance.m_minSimilarity)

// LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled
if (NumericUtils.SingleToSortableInt32(similarity) > NumericUtils.SingleToSortableInt32(outerInstance.m_minSimilarity))
{
boostAtt.Boost = (similarity - outerInstance.m_minSimilarity) * outerInstance.m_scaleFactor;
//System.out.println(" yes");
Expand Down

0 comments on commit 8e5ecaf

Please sign in to comment.