diff --git a/src/Lucene.Net.Sandbox/Queries/FuzzyLikeThisQuery.cs b/src/Lucene.Net.Sandbox/Queries/FuzzyLikeThisQuery.cs
index e8fb2d7d27..02980b3e00 100644
--- a/src/Lucene.Net.Sandbox/Queries/FuzzyLikeThisQuery.cs
+++ b/src/Lucene.Net.Sandbox/Queries/FuzzyLikeThisQuery.cs
@@ -6,6 +6,7 @@
using Lucene.Net.Util;
using System;
using System.Collections.Generic;
+using System.Runtime.CompilerServices;
using JCG = J2N.Collections.Generic;
namespace Lucene.Net.Sandbox.Queries
@@ -363,6 +364,9 @@ public ScoreTermQueue(int size)
/// (non-Javadoc)
///
///
+#if NETFRAMEWORK
+ [MethodImpl(MethodImplOptions.NoOptimization)] // LUCENENET specific: comparing score equality fails in x86 on .NET Framework with optimizations enabled
+#endif
protected internal override bool LessThan(ScoreTerm termA, ScoreTerm termB)
{
if (termA.Score == termB.Score)
diff --git a/src/Lucene.Net.Sandbox/Queries/SlowFuzzyTermsEnum.cs b/src/Lucene.Net.Sandbox/Queries/SlowFuzzyTermsEnum.cs
index b7e8ba3c0c..6acb46f709 100644
--- a/src/Lucene.Net.Sandbox/Queries/SlowFuzzyTermsEnum.cs
+++ b/src/Lucene.Net.Sandbox/Queries/SlowFuzzyTermsEnum.cs
@@ -3,6 +3,7 @@
using Lucene.Net.Util;
using System;
using System.IO;
+using System.Runtime.CompilerServices;
namespace Lucene.Net.Sandbox.Queries
{
@@ -120,6 +121,9 @@ public LinearFuzzyTermsEnum(SlowFuzzyTermsEnum outerInstance)
/// where distance is the Levenshtein distance for the two words.
///
///
+#if NETFRAMEWORK
+ [MethodImpl(MethodImplOptions.NoOptimization)] // LUCENENET specific: comparing float equality fails in x86 on .NET Framework with optimizations enabled. Fixes TestTokenLengthOpt.
+#endif
protected override sealed AcceptStatus Accept(BytesRef term)
{
if (StringHelper.StartsWith(term, prefixBytesRef))
diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
index 06e03c5ecd..d64b23518a 100644
--- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
@@ -1269,8 +1269,7 @@ public static Type GetTestClass()
return testClass;
// 2nd attempt - try scanning the referenced assemblies to see if we can find the class by fullname
- var referencedAssemblies = AssemblyUtils.GetReferencedAssemblies();
- testClass = referencedAssemblies.SelectMany(a => a.GetTypes().Where(t => t.FullName == testClassName)).FirstOrDefault();
+ testClass = AssemblyUtils.GetReferencedAssemblies().SelectMany(a => a.GetTypes().Where(t => t.FullName == testClassName)).FirstOrDefault();
if (testClass != null)
return testClass;
#endif
diff --git a/src/Lucene.Net/Search/FuzzyTermsEnum.cs b/src/Lucene.Net/Search/FuzzyTermsEnum.cs
index e07dbd5b78..14039c3eee 100644
--- a/src/Lucene.Net/Search/FuzzyTermsEnum.cs
+++ b/src/Lucene.Net/Search/FuzzyTermsEnum.cs
@@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Runtime.CompilerServices;
using JCG = J2N.Collections.Generic;
namespace Lucene.Net.Search
@@ -381,6 +382,9 @@ public AutomatonFuzzyTermsEnum(FuzzyTermsEnum outerInstance, TermsEnum tenum, Co
///
/// Finds the smallest Lev(n) DFA that accepts the term.
+#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);
diff --git a/src/Lucene.Net/Search/TopScoreDocCollector.cs b/src/Lucene.Net/Search/TopScoreDocCollector.cs
index 73dfbb2623..4839499547 100644
--- a/src/Lucene.Net/Search/TopScoreDocCollector.cs
+++ b/src/Lucene.Net/Search/TopScoreDocCollector.cs
@@ -1,6 +1,7 @@
using Lucene.Net.Diagnostics;
using Lucene.Net.Support;
using System;
+using System.Runtime.CompilerServices;
namespace Lucene.Net.Search
{
@@ -46,6 +47,9 @@ internal InOrderTopScoreDocCollector(int numHits)
{
}
+#if NETFRAMEWORK
+ [MethodImpl(MethodImplOptions.NoOptimization)] // LUCENENET specific: comparing float equality fails in x86 on .NET Framework with optimizations enabled
+#endif
public override void Collect(int doc)
{
float score = scorer.GetScore();
@@ -89,6 +93,9 @@ internal InOrderPagingScoreDocCollector(ScoreDoc after, int numHits)
this.after = after;
}
+#if NETFRAMEWORK
+ [MethodImpl(MethodImplOptions.NoOptimization)] // LUCENENET specific: comparing float equality fails in x86 on .NET Framework with optimizations enabled
+#endif
public override void Collect(int doc)
{
float score = scorer.GetScore();
@@ -146,6 +153,9 @@ internal OutOfOrderTopScoreDocCollector(int numHits)
{
}
+#if NETFRAMEWORK
+ [MethodImpl(MethodImplOptions.NoOptimization)] // LUCENENET specific: comparing float equality fails in x86 on .NET Framework with optimizations enabled
+#endif
public override void Collect(int doc)
{
float score = scorer.GetScore();
@@ -189,6 +199,9 @@ internal OutOfOrderPagingScoreDocCollector(ScoreDoc after, int numHits)
this.after = after;
}
+#if NETFRAMEWORK
+ [MethodImpl(MethodImplOptions.NoOptimization)] // LUCENENET specific: comparing float equality fails in x86 on .NET Framework with optimizations enabled
+#endif
public override void Collect(int doc)
{
float score = scorer.GetScore();
@@ -302,7 +315,7 @@ protected override TopDocs NewTopDocs(ScoreDoc[] results, int start)
// it means the largest element is already in results, use its score as
// maxScore. Otherwise pop everything else, until the largest element is
// extracted and use its score as maxScore.
- float maxScore = float.NaN;
+ float maxScore/* = float.NaN*/; // LUCENENET: Removed unnecessary assignment
if (start == 0)
{
maxScore = results[0].Score;
diff --git a/src/Lucene.Net/Support/AssemblyUtils.cs b/src/Lucene.Net/Support/AssemblyUtils.cs
index e77b616879..5beaab2059 100644
--- a/src/Lucene.Net/Support/AssemblyUtils.cs
+++ b/src/Lucene.Net/Support/AssemblyUtils.cs
@@ -39,7 +39,7 @@ internal class AssemblyUtils
/// Microsoft assemblies here.
///
///
- public static IList GetReferencedAssemblies()
+ public static IEnumerable GetReferencedAssemblies()
{
// .NET Port Hack: We do a 2-level deep check here because if the assembly you're
// hoping would be loaded hasn't been loaded yet into the app domain,
@@ -55,9 +55,9 @@ public static IList GetReferencedAssemblies()
.Distinct();
var assembliesLoaded = LoadAssemblyFromName(assemblyNames);
#endif
- assembliesLoaded = assembliesLoaded.Where(x => !DotNetFrameworkFilter.IsFrameworkAssembly(x)).ToArray();
+ var nonFrameworkAssembliesLoaded = assembliesLoaded.Where(x => !DotNetFrameworkFilter.IsFrameworkAssembly(x));
- var referencedAssemblies = assembliesLoaded
+ var referencedAssemblies = nonFrameworkAssembliesLoaded
.SelectMany(assembly =>
{
return assembly
@@ -68,7 +68,7 @@ public static IList GetReferencedAssemblies()
.Where(x => x != null)
.Distinct();
- return assembliesLoaded.Concat(referencedAssemblies).Distinct().ToList();
+ return nonFrameworkAssembliesLoaded.Concat(referencedAssemblies).Distinct();
}
#if !FEATURE_APPDOMAIN_GETASSEMBLIES
diff --git a/src/Lucene.Net/Util/SPIClassIterator.cs b/src/Lucene.Net/Util/SPIClassIterator.cs
index f6c7e52171..5439a51ab7 100644
--- a/src/Lucene.Net/Util/SPIClassIterator.cs
+++ b/src/Lucene.Net/Util/SPIClassIterator.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Reflection;
using JCG = J2N.Collections.Generic;
namespace Lucene.Net.Util
@@ -32,29 +33,33 @@ namespace Lucene.Net.Util
///
public class SPIClassIterator : IEnumerable
{
- private static JCG.HashSet types = LoadTypes();
+ private static readonly JCG.HashSet types = LoadTypes();
private static JCG.HashSet LoadTypes() // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006)
{
- types = new JCG.HashSet();
+ var types = new JCG.HashSet();
var assembliesToExamine = Support.AssemblyUtils.GetReferencedAssemblies();
- // LUCENENET HACK:
- // Tests such as TestImpersonation.cs expect that the assemblies
- // are probed in a certain order. NamedSPILoader, lines 68 - 75 adds
- // the first item it sees with that name. So if you have multiple
- // codecs, it may not add the right one, depending on the order of
- // the assemblies that were examined.
- // This results in many test failures if Types from Lucene.Net.Codecs
- // are examined and added to NamedSPILoader first before
- // Lucene.Net.TestFramework.
- var testFrameworkAssembly = assembliesToExamine.FirstOrDefault(x => string.Equals(x.GetName().Name, "Lucene.Net.TestFramework", StringComparison.Ordinal));
- if (testFrameworkAssembly != null)
- {
- assembliesToExamine.Remove(testFrameworkAssembly);
- assembliesToExamine.Insert(0, testFrameworkAssembly);
- }
+ // LUCENENET NOTE: The following hack is not required because we are using abstract factories
+ // and pure DI to ensure the order of the codecs are always correct during testing.
+
+ //// LUCENENET HACK:
+ //// Tests such as TestImpersonation.cs expect that the assemblies
+ //// are probed in a certain order. NamedSPILoader, lines 68 - 75 adds
+ //// the first item it sees with that name. So if you have multiple
+ //// codecs, it may not add the right one, depending on the order of
+ //// the assemblies that were examined.
+ //// This results in many test failures if Types from Lucene.Net.Codecs
+ //// are examined and added to NamedSPILoader first before
+ //// Lucene.Net.TestFramework.
+ //var testFrameworkAssembly = assembliesToExamine.FirstOrDefault(x => string.Equals(x.GetName().Name, "Lucene.Net.TestFramework", StringComparison.Ordinal));
+ //if (testFrameworkAssembly != null)
+ //{
+ // //assembliesToExamine.Remove(testFrameworkAssembly);
+ // //assembliesToExamine.Insert(0, testFrameworkAssembly);
+ // assembliesToExamine = new Assembly[] { testFrameworkAssembly }.Concat(assembliesToExamine.Where(a => !testFrameworkAssembly.Equals(a)));
+ //}
foreach (var assembly in assembliesToExamine)
{