diff --git a/src/Lucene.Net.Tests/Search/TestFieldCacheRewriteMethod.cs b/src/Lucene.Net.Tests/Search/TestFieldCacheRewriteMethod.cs
index 47e5b8443a..c5befbe452 100644
--- a/src/Lucene.Net.Tests/Search/TestFieldCacheRewriteMethod.cs
+++ b/src/Lucene.Net.Tests/Search/TestFieldCacheRewriteMethod.cs
@@ -61,22 +61,5 @@ public virtual void TestEquals()
Assert.IsFalse(a1.Equals(b));
QueryUtils.Check(a1);
}
-
-
-
- #region TestSnapshotDeletionPolicy
- // LUCENENET NOTE: Tests in a base class are not pulled into the correct
- // context in Visual Studio. This fixes that with the minimum amount of code necessary
- // to run them in the correct context without duplicating all of the tests.
-
- ///
- /// test a bunch of random regular expressions
- [Test]
- public override void TestRegexps()
- {
- base.TestRegexps();
- }
-
- #endregion
}
}
diff --git a/src/Lucene.Net.Tests/Search/TestLiveFieldValues.cs b/src/Lucene.Net.Tests/Search/TestLiveFieldValues.cs
index b7da41d786..3c085e967c 100644
--- a/src/Lucene.Net.Tests/Search/TestLiveFieldValues.cs
+++ b/src/Lucene.Net.Tests/Search/TestLiveFieldValues.cs
@@ -10,7 +10,7 @@
using Assert = Lucene.Net.TestFramework.Assert;
using Console = Lucene.Net.Util.SystemConsole;
-#if FEATURE_RANDOM_NEXTINT64_NEXTSINGLE
+#if !FEATURE_RANDOM_NEXTINT64_NEXTSINGLE
using RandomizedTesting.Generators;
#endif
diff --git a/src/Lucene.Net.Tests/Search/TestMinShouldMatch2.cs b/src/Lucene.Net.Tests/Search/TestMinShouldMatch2.cs
index 6559f79cd1..b202e9b1d5 100644
--- a/src/Lucene.Net.Tests/Search/TestMinShouldMatch2.cs
+++ b/src/Lucene.Net.Tests/Search/TestMinShouldMatch2.cs
@@ -2,11 +2,9 @@
using Lucene.Net.Diagnostics;
using Lucene.Net.Documents;
using Lucene.Net.Index;
-using Lucene.Net.Support;
using Lucene.Net.Util;
using NUnit.Framework;
using System.Collections.Generic;
-using System.Linq;
using Assert = Lucene.Net.TestFramework.Assert;
using JCG = J2N.Collections.Generic;
@@ -101,12 +99,15 @@ public override void BeforeClass()
r = DirectoryReader.Open(dir);
atomicReader = GetOnlySegmentReader(r);
searcher = new IndexSearcher(atomicReader);
- searcher.Similarity = new DefaultSimilarityAnonymousClass();
+ searcher.Similarity = DefaultSimilarityAnonymousClass.Default;
}
private sealed class DefaultSimilarityAnonymousClass : DefaultSimilarity
{
- public DefaultSimilarityAnonymousClass()
+ // LUCENENET: making a static readonly instance with private constructor for reduced allocations
+ public static readonly DefaultSimilarityAnonymousClass Default = new DefaultSimilarityAnonymousClass();
+
+ private DefaultSimilarityAnonymousClass()
{
}
@@ -371,7 +372,7 @@ internal SlowMinShouldMatchScorer(BooleanWeight weight, AtomicReader reader, Ind
if (Debugging.AssertsEnabled) Debugging.Assert(success); // no dups
TermContext context = TermContext.Build(reader.Context, term);
SimWeight w = weight.Similarity.ComputeWeight(1f, searcher.CollectionStatistics("field"), searcher.TermStatistics(term, context));
- var dummy = w.GetValueForNormalization(); // ignored
+ _ = w.GetValueForNormalization(); // ignored
w.Normalize(1F, 1F);
sims[(int)ord] = weight.Similarity.GetSimScorer(w, (AtomicReaderContext)reader.Context);
}
@@ -428,4 +429,4 @@ public override long GetCost()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestMultiPhraseQuery.cs b/src/Lucene.Net.Tests/Search/TestMultiPhraseQuery.cs
index fd502af60c..135462d8b5 100644
--- a/src/Lucene.Net.Tests/Search/TestMultiPhraseQuery.cs
+++ b/src/Lucene.Net.Tests/Search/TestMultiPhraseQuery.cs
@@ -3,7 +3,6 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
-using System.Linq;
using Assert = Lucene.Net.TestFramework.Assert;
using Console = Lucene.Net.Util.SystemConsole;
@@ -354,7 +353,7 @@ private void Add(string s, string type, RandomIndexWriter writer)
[Test]
public virtual void TestEmptyToString()
{
- (new MultiPhraseQuery()).ToString();
+ _ = new MultiPhraseQuery().ToString();
}
[Test]
@@ -367,7 +366,7 @@ public virtual void TestCustomIDF()
IndexReader reader = writer.GetReader();
IndexSearcher searcher = NewSearcher(reader);
- searcher.Similarity = new DefaultSimilarityAnonymousClass(this);
+ searcher.Similarity = new DefaultSimilarityAnonymousClass();
MultiPhraseQuery query = new MultiPhraseQuery();
query.Add(new Term[] { new Term("body", "this"), new Term("body", "that") });
@@ -382,13 +381,6 @@ public virtual void TestCustomIDF()
private sealed class DefaultSimilarityAnonymousClass : DefaultSimilarity
{
- private readonly TestMultiPhraseQuery outerInstance;
-
- public DefaultSimilarityAnonymousClass(TestMultiPhraseQuery outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
public override Explanation IdfExplain(CollectionStatistics collectionStats, TermStatistics[] termStats)
{
return new Explanation(10f, "just a test");
@@ -462,13 +454,45 @@ private static Token MakeToken(string text, int posIncr)
return t;
}
- private static readonly Token[] INCR_0_DOC_TOKENS = new Token[] { MakeToken("x", 1), MakeToken("a", 1), MakeToken("1", 0), MakeToken("m", 1), MakeToken("b", 1), MakeToken("1", 0), MakeToken("n", 1), MakeToken("c", 1), MakeToken("y", 1) };
-
- private static readonly Token[] INCR_0_QUERY_TOKENS_AND = new Token[] { MakeToken("a", 1), MakeToken("1", 0), MakeToken("b", 1), MakeToken("1", 0), MakeToken("c", 1) };
-
- private static readonly Token[][] INCR_0_QUERY_TOKENS_AND_OR_MATCH = new Token[][] { new Token[] { MakeToken("a", 1) }, new Token[] { MakeToken("x", 1), MakeToken("1", 0) }, new Token[] { MakeToken("b", 2) }, new Token[] { MakeToken("x", 2), MakeToken("1", 0) }, new Token[] { MakeToken("c", 3) } };
-
- private static readonly Token[][] INCR_0_QUERY_TOKENS_AND_OR_NO_MATCHN = new Token[][] { new Token[] { MakeToken("x", 1) }, new Token[] { MakeToken("a", 1), MakeToken("1", 0) }, new Token[] { MakeToken("x", 2) }, new Token[] { MakeToken("b", 2), MakeToken("1", 0) }, new Token[] { MakeToken("c", 3) } };
+ private static readonly Token[] INCR_0_DOC_TOKENS = new Token[]
+ {
+ MakeToken("x", 1),
+ MakeToken("a", 1),
+ MakeToken("1", 0),
+ MakeToken("m", 1), // not existing, relying on slop=2
+ MakeToken("b", 1),
+ MakeToken("1", 0),
+ MakeToken("n", 1), // not existing, relying on slop=2
+ MakeToken("c", 1),
+ MakeToken("y", 1)
+ };
+
+ private static readonly Token[] INCR_0_QUERY_TOKENS_AND = new Token[]
+ {
+ MakeToken("a", 1),
+ MakeToken("1", 0),
+ MakeToken("b", 1),
+ MakeToken("1", 0),
+ MakeToken("c", 1)
+ };
+
+ private static readonly Token[][] INCR_0_QUERY_TOKENS_AND_OR_MATCH = new Token[][]
+ {
+ new[] { MakeToken("a", 1) },
+ new[] { MakeToken("x", 1), MakeToken("1", 0) },
+ new[] { MakeToken("b", 2) },
+ new[] { MakeToken("x", 2), MakeToken("1", 0) },
+ new[] { MakeToken("c", 3) }
+ };
+
+ private static readonly Token[][] INCR_0_QUERY_TOKENS_AND_OR_NO_MATCHN = new Token[][]
+ {
+ new[] { MakeToken("x", 1) },
+ new[] { MakeToken("a", 1), MakeToken("1", 0) },
+ new[] { MakeToken("x", 2) },
+ new[] { MakeToken("b", 2), MakeToken("1", 0) },
+ new[] { MakeToken("c", 3) }
+ };
///
/// using query parser, MPQ will be created, and will not be strict about having all query terms
@@ -626,4 +650,4 @@ public virtual void TestNegativeSlop()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestMultiTermConstantScore.cs b/src/Lucene.Net.Tests/Search/TestMultiTermConstantScore.cs
index 024551c898..621313f030 100644
--- a/src/Lucene.Net.Tests/Search/TestMultiTermConstantScore.cs
+++ b/src/Lucene.Net.Tests/Search/TestMultiTermConstantScore.cs
@@ -50,10 +50,6 @@ public class TestMultiTermConstantScore : BaseTestRangeFilter
internal /*static*/ Directory small;
internal /*static*/ IndexReader reader;
- ///
- /// LUCENENET specific
- /// Is non-static because NewIndexWriterConfig is no longer static.
- ///
[OneTimeSetUp]
public override void BeforeClass()
{
@@ -95,7 +91,7 @@ public override void AfterClass()
public static Query Csrq(string f, string l, string h, bool il, bool ih)
{
TermRangeQuery query = TermRangeQuery.NewStringRange(f, l, h, il, ih);
- query.MultiTermRewriteMethod = (MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
+ query.MultiTermRewriteMethod = MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE;
if (Verbose)
{
Console.WriteLine("TEST: query=" + query);
@@ -106,7 +102,7 @@ public static Query Csrq(string f, string l, string h, bool il, bool ih)
public static Query Csrq(string f, string l, string h, bool il, bool ih, MultiTermQuery.RewriteMethod method)
{
TermRangeQuery query = TermRangeQuery.NewStringRange(f, l, h, il, ih);
- query.MultiTermRewriteMethod = (method);
+ query.MultiTermRewriteMethod = method;
if (Verbose)
{
Console.WriteLine("TEST: query=" + query + " method=" + method);
@@ -119,7 +115,7 @@ public static Query Csrq(string f, string l, string h, bool il, bool ih, MultiTe
public static Query Cspq(Term prefix)
{
PrefixQuery query = new PrefixQuery(prefix);
- query.MultiTermRewriteMethod = (MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
+ query.MultiTermRewriteMethod = MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE;
return query;
}
@@ -128,7 +124,7 @@ public static Query Cspq(Term prefix)
public static Query Cswcq(Term wild)
{
WildcardQuery query = new WildcardQuery(wild);
- query.MultiTermRewriteMethod = (MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
+ query.MultiTermRewriteMethod = MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE;
return query;
}
@@ -242,7 +238,7 @@ public virtual void TestBoost()
search.Similarity = new DefaultSimilarity();
Query q = Csrq("data", "1", "6", T, T);
q.Boost = 100;
- search.Search(q, null, new CollectorAnonymousClass(this));
+ search.Search(q, null, new CollectorAnonymousClass());
//
// Ensure that boosting works to score one clause of a query higher
@@ -287,15 +283,7 @@ public virtual void TestBoost()
private sealed class CollectorAnonymousClass : ICollector
{
- private readonly TestMultiTermConstantScore outerInstance;
-
- public CollectorAnonymousClass(TestMultiTermConstantScore outerInstance)
- {
- this.outerInstance = outerInstance;
- @base = 0;
- }
-
- private int @base;
+ private int @base = 0;
private Scorer scorer;
public void SetScorer(Scorer scorer)
@@ -544,4 +532,4 @@ public virtual void TestRangeQueryRand()
assertEquals("max,nul,T,T", 1, result.Length);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestMultiTermQueryRewrites.cs b/src/Lucene.Net.Tests/Search/TestMultiTermQueryRewrites.cs
index 78a243ec48..d9533117ea 100644
--- a/src/Lucene.Net.Tests/Search/TestMultiTermQueryRewrites.cs
+++ b/src/Lucene.Net.Tests/Search/TestMultiTermQueryRewrites.cs
@@ -137,7 +137,7 @@ private void CheckBooleanQueryOrder(Query q)
private void CheckDuplicateTerms(MultiTermQuery.RewriteMethod method)
{
MultiTermQuery mtq = TermRangeQuery.NewStringRange("data", "2", "7", true, true);
- mtq.MultiTermRewriteMethod = (method);
+ mtq.MultiTermRewriteMethod = method;
Query q1 = searcher.Rewrite(mtq);
Query q2 = multiSearcher.Rewrite(mtq);
Query q3 = multiSearcherDupls.Rewrite(mtq);
@@ -184,8 +184,8 @@ private void CheckBooleanQueryBoosts(BooleanQuery bq)
private void CheckBoosts(MultiTermQuery.RewriteMethod method)
{
- MultiTermQuery mtq = new MultiTermQueryAnonymousClass(this);
- mtq.MultiTermRewriteMethod = (method);
+ MultiTermQuery mtq = new MultiTermQueryAnonymousClass();
+ mtq.MultiTermRewriteMethod = method;
Query q1 = searcher.Rewrite(mtq);
Query q2 = multiSearcher.Rewrite(mtq);
Query q3 = multiSearcherDupls.Rewrite(mtq);
@@ -205,27 +205,21 @@ private void CheckBoosts(MultiTermQuery.RewriteMethod method)
private sealed class MultiTermQueryAnonymousClass : MultiTermQuery
{
- private readonly TestMultiTermQueryRewrites outerInstance;
-
- public MultiTermQueryAnonymousClass(TestMultiTermQueryRewrites outerInstance)
+ public MultiTermQueryAnonymousClass()
: base("data")
{
- this.outerInstance = outerInstance;
}
protected override TermsEnum GetTermsEnum(Terms terms, AttributeSource atts)
{
- return new TermRangeTermsEnumAnonymousClass(this, terms.GetEnumerator(), new BytesRef("2"), new BytesRef("7"));
+ return new TermRangeTermsEnumAnonymousClass(terms.GetEnumerator(), new BytesRef("2"), new BytesRef("7"));
}
private sealed class TermRangeTermsEnumAnonymousClass : TermRangeTermsEnum
{
- private readonly MultiTermQueryAnonymousClass outerInstance;
-
- public TermRangeTermsEnumAnonymousClass(MultiTermQueryAnonymousClass outerInstance, TermsEnum iterator, BytesRef bref1, BytesRef bref2)
+ public TermRangeTermsEnumAnonymousClass(TermsEnum iterator, BytesRef bref1, BytesRef bref2)
: base(iterator, bref1, bref2, true, true)
{
- this.outerInstance = outerInstance;
boostAtt = Attributes.AddAttribute();
}
@@ -305,4 +299,4 @@ public virtual void TestMaxClauseLimitations()
CheckNoMaxClauseLimitation(new MultiTermQuery.TopTermsBoostOnlyBooleanQueryRewrite(1024));
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestMultiThreadTermVectors.cs b/src/Lucene.Net.Tests/Search/TestMultiThreadTermVectors.cs
index 4d567936ec..0d06ec9d6a 100644
--- a/src/Lucene.Net.Tests/Search/TestMultiThreadTermVectors.cs
+++ b/src/Lucene.Net.Tests/Search/TestMultiThreadTermVectors.cs
@@ -2,10 +2,8 @@
using Lucene.Net.Diagnostics;
using Lucene.Net.Documents;
using Lucene.Net.Index.Extensions;
-using Lucene.Net.Support.Threading;
using NUnit.Framework;
using System;
-using System.IO;
using System.Text;
using System.Threading;
using Console = Lucene.Net.Util.SystemConsole;
@@ -60,7 +58,7 @@ public override void SetUp()
customType.StoreTermVectors = true;
for (int i = 0; i < numDocs; i++)
{
- Documents.Document doc = new Documents.Document();
+ Document doc = new Document();
Field fld = NewField("field", English.Int32ToEnglish(i), customType);
doc.Add(fld);
writer.AddDocument(doc);
@@ -98,8 +96,7 @@ public virtual void Test()
{
try
{
- ///
- /// close the opened reader
+ // close the opened reader
reader.Dispose();
}
catch (Exception ioe) when (ioe.IsIOException())
@@ -240,4 +237,4 @@ private void VerifyVector(TermsEnum vector, int num)
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestNot.cs b/src/Lucene.Net.Tests/Search/TestNot.cs
index 0a267ba864..0d434cd680 100644
--- a/src/Lucene.Net.Tests/Search/TestNot.cs
+++ b/src/Lucene.Net.Tests/Search/TestNot.cs
@@ -31,8 +31,6 @@ namespace Lucene.Net.Search
///
/// Similarity unit test.
- ///
- ///
///
[TestFixture]
public class TestNot : LuceneTestCase
@@ -62,4 +60,4 @@ public virtual void TestNot_Mem()
store.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestNumericRangeQuery32.cs b/src/Lucene.Net.Tests/Search/TestNumericRangeQuery32.cs
index 9560992ca4..a48c6c4e31 100644
--- a/src/Lucene.Net.Tests/Search/TestNumericRangeQuery32.cs
+++ b/src/Lucene.Net.Tests/Search/TestNumericRangeQuery32.cs
@@ -74,7 +74,10 @@ public override void BeforeClass()
noDocs = AtLeast(4096);
distance = (1 << 30) / noDocs;
directory = NewDirectory();
- RandomIndexWriter writer = new RandomIndexWriter(Random, directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(TestUtil.NextInt32(Random, 100, 1000)).SetMergePolicy(NewLogMergePolicy()));
+ RandomIndexWriter writer = new RandomIndexWriter(Random, directory,
+ NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetMaxBufferedDocs(TestUtil.NextInt32(Random, 100, 1000))
+ .SetMergePolicy(NewLogMergePolicy()));
FieldType storedInt = new FieldType(Int32Field.TYPE_NOT_STORED);
storedInt.IsStored = true;
@@ -103,7 +106,14 @@ public override void BeforeClass()
FieldType unstoredInt2 = new FieldType(unstoredInt);
unstoredInt2.NumericPrecisionStep = 2;
- Int32Field field8 = new Int32Field("field8", 0, storedInt8), field4 = new Int32Field("field4", 0, storedInt4), field2 = new Int32Field("field2", 0, storedInt2), fieldNoTrie = new Int32Field("field" + int.MaxValue, 0, storedIntNone), ascfield8 = new Int32Field("ascfield8", 0, unstoredInt8), ascfield4 = new Int32Field("ascfield4", 0, unstoredInt4), ascfield2 = new Int32Field("ascfield2", 0, unstoredInt2);
+ Int32Field
+ field8 = new Int32Field("field8", 0, storedInt8),
+ field4 = new Int32Field("field4", 0, storedInt4),
+ field2 = new Int32Field("field2", 0, storedInt2),
+ fieldNoTrie = new Int32Field("field" + int.MaxValue, 0, storedIntNone),
+ ascfield8 = new Int32Field("ascfield8", 0, unstoredInt8),
+ ascfield4 = new Int32Field("ascfield4", 0, unstoredInt4),
+ ascfield2 = new Int32Field("ascfield2", 0, unstoredInt2);
Document doc = new Document();
// add fields, that have a distance to test general functionality
@@ -225,11 +235,11 @@ public virtual void TestInverseRange()
{
AtomicReaderContext context = (AtomicReaderContext)SlowCompositeReaderWrapper.Wrap(reader).Context;
NumericRangeFilter f = NumericRangeFilter.NewInt32Range("field8", 8, 1000, -1000, true, true);
- Assert.IsNull(f.GetDocIdSet(context, (context.AtomicReader).LiveDocs), "A inverse range should return the null instance");
+ Assert.IsNull(f.GetDocIdSet(context, context.AtomicReader.LiveDocs), "A inverse range should return the null instance");
f = NumericRangeFilter.NewInt32Range("field8", 8, int.MaxValue, null, false, false);
- Assert.IsNull(f.GetDocIdSet(context, (context.AtomicReader).LiveDocs), "A exclusive range starting with Integer.MAX_VALUE should return the null instance");
+ Assert.IsNull(f.GetDocIdSet(context, context.AtomicReader.LiveDocs), "A exclusive range starting with Integer.MAX_VALUE should return the null instance");
f = NumericRangeFilter.NewInt32Range("field8", 8, null, int.MinValue, false, false);
- Assert.IsNull(f.GetDocIdSet(context, (context.AtomicReader).LiveDocs), "A exclusive range ending with Integer.MIN_VALUE should return the null instance");
+ Assert.IsNull(f.GetDocIdSet(context, context.AtomicReader.LiveDocs), "A exclusive range ending with Integer.MIN_VALUE should return the null instance");
}
[Test]
@@ -707,4 +717,4 @@ public virtual void TestEqualsAndHash()
Assert.IsFalse(q2.Equals(q1));
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestNumericRangeQuery64.cs b/src/Lucene.Net.Tests/Search/TestNumericRangeQuery64.cs
index 1bb227cb6c..71b7f7c72b 100644
--- a/src/Lucene.Net.Tests/Search/TestNumericRangeQuery64.cs
+++ b/src/Lucene.Net.Tests/Search/TestNumericRangeQuery64.cs
@@ -74,7 +74,10 @@ public override void BeforeClass()
noDocs = AtLeast(4096);
distance = (1L << 60) / noDocs;
directory = NewDirectory();
- RandomIndexWriter writer = new RandomIndexWriter(Random, directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(TestUtil.NextInt32(Random, 100, 1000)).SetMergePolicy(NewLogMergePolicy()));
+ RandomIndexWriter writer = new RandomIndexWriter(Random, directory,
+ NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetMaxBufferedDocs(TestUtil.NextInt32(Random, 100, 1000))
+ .SetMergePolicy(NewLogMergePolicy()));
FieldType storedLong = new FieldType(Int64Field.TYPE_NOT_STORED);
storedLong.IsStored = true;
@@ -109,7 +112,16 @@ public override void BeforeClass()
FieldType unstoredLong2 = new FieldType(unstoredLong);
unstoredLong2.NumericPrecisionStep = 2;
- Int64Field field8 = new Int64Field("field8", 0L, storedLong8), field6 = new Int64Field("field6", 0L, storedLong6), field4 = new Int64Field("field4", 0L, storedLong4), field2 = new Int64Field("field2", 0L, storedLong2), fieldNoTrie = new Int64Field("field" + int.MaxValue, 0L, storedLongNone), ascfield8 = new Int64Field("ascfield8", 0L, unstoredLong8), ascfield6 = new Int64Field("ascfield6", 0L, unstoredLong6), ascfield4 = new Int64Field("ascfield4", 0L, unstoredLong4), ascfield2 = new Int64Field("ascfield2", 0L, unstoredLong2);
+ Int64Field
+ field8 = new Int64Field("field8", 0L, storedLong8),
+ field6 = new Int64Field("field6", 0L, storedLong6),
+ field4 = new Int64Field("field4", 0L, storedLong4),
+ field2 = new Int64Field("field2", 0L, storedLong2),
+ fieldNoTrie = new Int64Field("field" + int.MaxValue, 0L, storedLongNone),
+ ascfield8 = new Int64Field("ascfield8", 0L, unstoredLong8),
+ ascfield6 = new Int64Field("ascfield6", 0L, unstoredLong6),
+ ascfield4 = new Int64Field("ascfield4", 0L, unstoredLong4),
+ ascfield2 = new Int64Field("ascfield2", 0L, unstoredLong2);
Document doc = new Document();
// add fields, that have a distance to test general functionality
@@ -240,11 +252,11 @@ public virtual void TestInverseRange()
{
AtomicReaderContext context = (AtomicReaderContext)SlowCompositeReaderWrapper.Wrap(searcher.IndexReader).Context;
NumericRangeFilter f = NumericRangeFilter.NewInt64Range("field8", 8, 1000L, -1000L, true, true);
- Assert.IsNull(f.GetDocIdSet(context, (context.AtomicReader).LiveDocs), "A inverse range should return the null instance");
+ Assert.IsNull(f.GetDocIdSet(context, context.AtomicReader.LiveDocs), "A inverse range should return the null instance");
f = NumericRangeFilter.NewInt64Range("field8", 8, long.MaxValue, null, false, false);
- Assert.IsNull(f.GetDocIdSet(context, (context.AtomicReader).LiveDocs), "A exclusive range starting with Long.MAX_VALUE should return the null instance");
+ Assert.IsNull(f.GetDocIdSet(context, context.AtomicReader.LiveDocs), "A exclusive range starting with Long.MAX_VALUE should return the null instance");
f = NumericRangeFilter.NewInt64Range("field8", 8, null, long.MinValue, false, false);
- Assert.IsNull(f.GetDocIdSet(context, (context.AtomicReader).LiveDocs), "A exclusive range ending with Long.MIN_VALUE should return the null instance");
+ Assert.IsNull(f.GetDocIdSet(context, context.AtomicReader.LiveDocs), "A exclusive range ending with Long.MIN_VALUE should return the null instance");
}
[Test]
@@ -754,4 +766,4 @@ public virtual void TestEqualsAndHash()
// difference to int range is tested in TestNumericRangeQuery32
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestPhraseQuery.cs b/src/Lucene.Net.Tests/Search/TestPhraseQuery.cs
index 0cb04df2b7..55bb78ec74 100644
--- a/src/Lucene.Net.Tests/Search/TestPhraseQuery.cs
+++ b/src/Lucene.Net.Tests/Search/TestPhraseQuery.cs
@@ -30,15 +30,15 @@ namespace Lucene.Net.Search
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
using DefaultSimilarity = Lucene.Net.Search.Similarities.DefaultSimilarity;
using Directory = Lucene.Net.Store.Directory;
using OpenMode = Lucene.Net.Index.OpenMode;
///
- /// Tests .
+ /// Tests .
///
- ///
+ ///
/*
* Remove ThreadLeaks and run with (Eclipse or command line):
* -ea -Drt.seed=AFD1E7E84B35D2B1
@@ -49,7 +49,8 @@ namespace Lucene.Net.Search
public class TestPhraseQuery : LuceneTestCase
{
///
- /// threshold for comparing floats
+ /// threshold for comparing floats
+ ///
public const float SCORE_COMP_THRESH = 1e-6f;
private static IndexSearcher searcher;
@@ -63,10 +64,10 @@ public override void BeforeClass()
base.BeforeClass();
directory = NewDirectory();
- Analyzer analyzer = new AnalyzerAnonymousClass();
+ Analyzer analyzer = AnalyzerAnonymousClass.Default; // LUCENENET: using static instance
RandomIndexWriter writer = new RandomIndexWriter(Random, directory, analyzer);
- Documents.Document doc = new Documents.Document();
+ Document doc = new Document();
doc.Add(NewTextField("field", "one two three four five", Field.Store.YES));
doc.Add(NewTextField("repeated", "this is a repeated field - first part", Field.Store.YES));
IIndexableField repeatedField = NewTextField("repeated", "second part of a repeated field", Field.Store.YES);
@@ -74,11 +75,11 @@ public override void BeforeClass()
doc.Add(NewTextField("palindrome", "one two three two one", Field.Store.YES));
writer.AddDocument(doc);
- doc = new Documents.Document();
+ doc = new Document();
doc.Add(NewTextField("nonexist", "phrase exist notexist exist found", Field.Store.YES));
writer.AddDocument(doc);
- doc = new Documents.Document();
+ doc = new Document();
doc.Add(NewTextField("nonexist", "phrase exist notexist exist found", Field.Store.YES));
writer.AddDocument(doc);
@@ -90,7 +91,10 @@ public override void BeforeClass()
private sealed class AnalyzerAnonymousClass : Analyzer
{
- public AnalyzerAnonymousClass()
+ // LUCENENET: making static singleton with private constructor to reduce allocations
+ public static readonly AnalyzerAnonymousClass Default = new AnalyzerAnonymousClass();
+
+ private AnalyzerAnonymousClass()
{
}
@@ -247,7 +251,7 @@ public virtual void TestPhraseQueryWithStopAnalyzer()
Directory directory = NewDirectory();
Analyzer stopAnalyzer = new MockAnalyzer(Random, MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET);
RandomIndexWriter writer = new RandomIndexWriter(Random, directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, stopAnalyzer));
- Documents.Document doc = new Documents.Document();
+ Document doc = new Document();
doc.Add(NewTextField("field", "the stop words are here", Field.Store.YES));
writer.AddDocument(doc);
IndexReader reader = writer.GetReader();
@@ -273,11 +277,11 @@ public virtual void TestPhraseQueryInConjunctionScorer()
Directory directory = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random, directory);
- Documents.Document doc = new Documents.Document();
+ Document doc = new Document();
doc.Add(NewTextField("source", "marketing info", Field.Store.YES));
writer.AddDocument(doc);
- doc = new Documents.Document();
+ doc = new Document();
doc.Add(NewTextField("contents", "foobar", Field.Store.YES));
doc.Add(NewTextField("source", "marketing info", Field.Store.YES));
writer.AddDocument(doc);
@@ -305,15 +309,15 @@ public virtual void TestPhraseQueryInConjunctionScorer()
reader.Dispose();
writer = new RandomIndexWriter(Random, directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetOpenMode(OpenMode.CREATE));
- doc = new Documents.Document();
+ doc = new Document();
doc.Add(NewTextField("contents", "map entry woo", Field.Store.YES));
writer.AddDocument(doc);
- doc = new Documents.Document();
+ doc = new Document();
doc.Add(NewTextField("contents", "woo map entry", Field.Store.YES));
writer.AddDocument(doc);
- doc = new Documents.Document();
+ doc = new Document();
doc.Add(NewTextField("contents", "map foobarword entry woo", Field.Store.YES));
writer.AddDocument(doc);
@@ -355,15 +359,15 @@ public virtual void TestSlopScoring()
Directory directory = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random, directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMergePolicy(NewLogMergePolicy()).SetSimilarity(new DefaultSimilarity()));
- Documents.Document doc = new Documents.Document();
+ Document doc = new Document();
doc.Add(NewTextField("field", "foo firstname lastname foo", Field.Store.YES));
writer.AddDocument(doc);
- Documents.Document doc2 = new Documents.Document();
+ Document doc2 = new Document();
doc2.Add(NewTextField("field", "foo firstname zzz lastname foo", Field.Store.YES));
writer.AddDocument(doc2);
- Documents.Document doc3 = new Documents.Document();
+ Document doc3 = new Document();
doc3.Add(NewTextField("field", "foo firstname zzz yyy lastname foo", Field.Store.YES));
writer.AddDocument(doc3);
@@ -632,7 +636,7 @@ public virtual void TestRandomPhrases()
RandomIndexWriter w = new RandomIndexWriter(Random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer).SetMergePolicy(NewLogMergePolicy()));
IList> docs = new JCG.List>();
- Documents.Document d = new Documents.Document();
+ Document d = new Document();
Field f = NewTextField("f", "", Field.Store.NO);
d.Add(f);
@@ -759,4 +763,4 @@ public virtual void TestNegativeSlop()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestPositionIncrement.cs b/src/Lucene.Net.Tests/Search/TestPositionIncrement.cs
index bb421b1869..446d4364c3 100644
--- a/src/Lucene.Net.Tests/Search/TestPositionIncrement.cs
+++ b/src/Lucene.Net.Tests/Search/TestPositionIncrement.cs
@@ -48,8 +48,6 @@ namespace Lucene.Net.Search
///
/// Term position unit test.
- ///
- ///
///
[TestFixture]
public class TestPositionIncrement : LuceneTestCase
@@ -60,7 +58,7 @@ public class TestPositionIncrement : LuceneTestCase
[Test]
public virtual void TestSetPosition()
{
- Analyzer analyzer = new AnalyzerAnonymousClass(this);
+ Analyzer analyzer = new AnalyzerAnonymousClass();
Directory store = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random, store, analyzer);
Document d = new Document();
@@ -168,13 +166,6 @@ public virtual void TestSetPosition()
private sealed class AnalyzerAnonymousClass : Analyzer
{
- private readonly TestPositionIncrement outerInstance;
-
- public AnalyzerAnonymousClass(TestPositionIncrement outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
protected internal override TokenStreamComponents CreateComponents(string fieldName, TextReader reader)
{
return new TokenStreamComponents(new TokenizerAnonymousClass(reader));
@@ -318,4 +309,4 @@ public virtual void TestPayloadsPos0()
dir.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestPositiveScoresOnlyCollector.cs b/src/Lucene.Net.Tests/Search/TestPositiveScoresOnlyCollector.cs
index 33cb9b72db..69d2f11b21 100644
--- a/src/Lucene.Net.Tests/Search/TestPositiveScoresOnlyCollector.cs
+++ b/src/Lucene.Net.Tests/Search/TestPositiveScoresOnlyCollector.cs
@@ -65,7 +65,9 @@ public override long GetCost()
}
// The scores must have positive as well as negative values
- private static readonly float[] scores = new float[] { 0.7767749f, -1.7839992f, 8.9925785f, 7.9608946f, -0.07948637f, 2.6356435f, 7.4950366f, 7.1490803f, -8.108544f, 4.961808f, 2.2423935f, -7.285586f, 4.6699767f };
+ private static readonly float[] scores = new float[] { 0.7767749f, -1.7839992f,
+ 8.9925785f, 7.9608946f, -0.07948637f, 2.6356435f, 7.4950366f, 7.1490803f,
+ -8.108544f, 4.961808f, 2.2423935f, -7.285586f, 4.6699767f };
[Test]
public virtual void TestNegativeScores()
@@ -90,7 +92,7 @@ public virtual void TestNegativeScores()
IndexReader ir = writer.GetReader();
writer.Dispose();
IndexSearcher searcher = NewSearcher(ir);
- Weight fake = (new TermQuery(new Term("fake", "weight"))).CreateWeight(searcher);
+ Weight fake = new TermQuery(new Term("fake", "weight")).CreateWeight(searcher);
Scorer s = new SimpleScorer(fake);
TopDocsCollector tdc = TopScoreDocCollector.Create(scores.Length, true);
ICollector c = new PositiveScoresOnlyCollector(tdc);
@@ -110,4 +112,4 @@ public virtual void TestNegativeScores()
directory.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestPrefixFilter.cs b/src/Lucene.Net.Tests/Search/TestPrefixFilter.cs
index e9c70e4a54..2d3a7d93fd 100644
--- a/src/Lucene.Net.Tests/Search/TestPrefixFilter.cs
+++ b/src/Lucene.Net.Tests/Search/TestPrefixFilter.cs
@@ -30,8 +30,7 @@ namespace Lucene.Net.Search
using Term = Lucene.Net.Index.Term;
///
- /// Tests class.
- ///
+ /// Tests class.
///
[TestFixture]
public class TestPrefixFilter : LuceneTestCase
@@ -111,4 +110,4 @@ public virtual void TestPrefixFilter_Mem()
directory.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestPrefixQuery.cs b/src/Lucene.Net.Tests/Search/TestPrefixQuery.cs
index 30ca4300ab..f69622f2c2 100644
--- a/src/Lucene.Net.Tests/Search/TestPrefixQuery.cs
+++ b/src/Lucene.Net.Tests/Search/TestPrefixQuery.cs
@@ -32,8 +32,7 @@ namespace Lucene.Net.Search
using Terms = Lucene.Net.Index.Terms;
///
- /// Tests class.
- ///
+ /// Tests class.
///
[TestFixture]
public class TestPrefixQuery : LuceneTestCase
@@ -72,4 +71,4 @@ public virtual void TestPrefixQuery_Mem()
directory.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestPrefixRandom.cs b/src/Lucene.Net.Tests/Search/TestPrefixRandom.cs
index b094f1345d..7e664801ca 100644
--- a/src/Lucene.Net.Tests/Search/TestPrefixRandom.cs
+++ b/src/Lucene.Net.Tests/Search/TestPrefixRandom.cs
@@ -56,7 +56,9 @@ public override void SetUp()
{
base.SetUp();
dir = NewDirectory();
- RandomIndexWriter writer = new RandomIndexWriter(Random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.KEYWORD, false)).SetMaxBufferedDocs(TestUtil.NextInt32(Random, 50, 1000)));
+ RandomIndexWriter writer = new RandomIndexWriter(Random, dir,
+ NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.KEYWORD, false))
+ .SetMaxBufferedDocs(TestUtil.NextInt32(Random, 50, 1000)));
var doc = new Document();
Field field = NewStringField("field", "", Field.Store.NO);
@@ -88,32 +90,26 @@ public override void TearDown()
/// a stupid prefix query that just blasts thru the terms
private class DumbPrefixQuery : MultiTermQuery
{
- private readonly TestPrefixRandom outerInstance;
-
private readonly BytesRef prefix;
- internal DumbPrefixQuery(TestPrefixRandom outerInstance, Term term)
+ internal DumbPrefixQuery(Term term)
: base(term.Field)
{
- this.outerInstance = outerInstance;
prefix = term.Bytes;
}
protected override TermsEnum GetTermsEnum(Terms terms, AttributeSource atts)
{
- return new SimplePrefixTermsEnum(this, terms.GetEnumerator(), prefix);
+ return new SimplePrefixTermsEnum(terms.GetEnumerator(), prefix);
}
private class SimplePrefixTermsEnum : FilteredTermsEnum
{
- private readonly TestPrefixRandom.DumbPrefixQuery outerInstance;
-
private readonly BytesRef prefix;
- internal SimplePrefixTermsEnum(TestPrefixRandom.DumbPrefixQuery outerInstance, TermsEnum tenum, BytesRef prefix)
+ internal SimplePrefixTermsEnum(TermsEnum tenum, BytesRef prefix)
: base(tenum)
{
- this.outerInstance = outerInstance;
this.prefix = prefix;
SetInitialSeekTerm(new BytesRef(""));
}
@@ -149,11 +145,11 @@ public virtual void TestPrefixes()
private void AssertSame(string prefix)
{
PrefixQuery smart = new PrefixQuery(new Term("field", prefix));
- DumbPrefixQuery dumb = new DumbPrefixQuery(this, new Term("field", prefix));
+ DumbPrefixQuery dumb = new DumbPrefixQuery(new Term("field", prefix));
TopDocs smartDocs = searcher.Search(smart, 25);
TopDocs dumbDocs = searcher.Search(dumb, 25);
CheckHits.CheckEqual(smart, smartDocs.ScoreDocs, dumbDocs.ScoreDocs);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestQueryRescorer.cs b/src/Lucene.Net.Tests/Search/TestQueryRescorer.cs
index b567d6af8f..295bcf36db 100644
--- a/src/Lucene.Net.Tests/Search/TestQueryRescorer.cs
+++ b/src/Lucene.Net.Tests/Search/TestQueryRescorer.cs
@@ -151,7 +151,7 @@ public virtual void TestCustomCombine()
pq.Add(new Term("field", "wizard"));
pq.Add(new Term("field", "oz"));
- TopDocs hits2 = new QueryRescorerAnonymousClass(this, pq)
+ TopDocs hits2 = new QueryRescorerAnonymousClass(pq)
.Rescore(searcher, hits, 10);
// Resorting didn't change the order:
@@ -165,12 +165,9 @@ public virtual void TestCustomCombine()
private sealed class QueryRescorerAnonymousClass : QueryRescorer
{
- private readonly TestQueryRescorer outerInstance;
-
- public QueryRescorerAnonymousClass(TestQueryRescorer outerInstance, PhraseQuery pq)
+ public QueryRescorerAnonymousClass(PhraseQuery pq)
: base(pq)
{
- this.outerInstance = outerInstance;
}
protected override float Combine(float firstPassScore, bool secondPassMatches, float secondPassScore)
@@ -218,7 +215,7 @@ public virtual void TestExplain()
pq.Add(new Term("field", "wizard"));
pq.Add(new Term("field", "oz"));
- Rescorer rescorer = new QueryRescorerAnonymousClass2(this, pq);
+ Rescorer rescorer = new QueryRescorerAnonymousClass2(pq);
TopDocs hits2 = rescorer.Rescore(searcher, hits, 10);
@@ -253,12 +250,9 @@ public virtual void TestExplain()
private sealed class QueryRescorerAnonymousClass2 : QueryRescorer
{
- private readonly TestQueryRescorer outerInstance;
-
- public QueryRescorerAnonymousClass2(TestQueryRescorer outerInstance, PhraseQuery pq)
+ public QueryRescorerAnonymousClass2(PhraseQuery pq)
: base(pq)
{
- this.outerInstance = outerInstance;
}
protected override float Combine(float firstPassScore, bool secondPassMatches, float secondPassScore)
@@ -363,7 +357,7 @@ public virtual void TestRandom()
//System.out.println("numHits=" + numHits + " reverse=" + reverse);
TopDocs hits = s.Search(new TermQuery(new Term("field", "a")), numHits);
- TopDocs hits2 = new QueryRescorerAnonymousClass3(this, new FixedScoreQuery(idToNum, reverse))
+ TopDocs hits2 = new QueryRescorerAnonymousClass3(new FixedScoreQuery(idToNum, reverse))
.Rescore(s, hits, numHits);
int[] expected = new int[numHits];
@@ -406,7 +400,7 @@ public virtual void TestRandom()
for (int i = 0; i < numHits; i++)
{
//System.out.println("expected=" + expected[i] + " vs " + hits2.ScoreDocs[i].Doc + " v=" + idToNum[Integer.parseInt(r.Document(expected[i]).Get("id"))]);
- if ((int)expected[i] != hits2.ScoreDocs[i].Doc)
+ if (expected[i] != hits2.ScoreDocs[i].Doc)
{
//System.out.println(" diff!");
fail = true;
@@ -420,12 +414,9 @@ public virtual void TestRandom()
private sealed class QueryRescorerAnonymousClass3 : QueryRescorer
{
- private readonly TestQueryRescorer outerInstance;
-
- public QueryRescorerAnonymousClass3(TestQueryRescorer outerInstance, FixedScoreQuery fixedScoreQuery)
+ public QueryRescorerAnonymousClass3(FixedScoreQuery fixedScoreQuery)
: base(fixedScoreQuery)
{
- this.outerInstance = outerInstance;
}
protected override float Combine(float firstPassScore, bool secondPassMatches, float secondPassScore)
@@ -433,7 +424,7 @@ protected override float Combine(float firstPassScore, bool secondPassMatches, f
return secondPassScore;
}
}
-
+
///
/// Just assigns score == idToNum[doc("id")] for each doc.
private class FixedScoreQuery : Query
@@ -566,7 +557,7 @@ public override object Clone()
public override int GetHashCode()
{
- int PRIME = 31;
+ const int PRIME = 31; // LUCENENET: made const
int hash = base.GetHashCode();
if (reverse)
{
@@ -577,4 +568,4 @@ public override int GetHashCode()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestRegexpQuery.cs b/src/Lucene.Net.Tests/Search/TestRegexpQuery.cs
index ff49a59e66..cc54e3cf12 100644
--- a/src/Lucene.Net.Tests/Search/TestRegexpQuery.cs
+++ b/src/Lucene.Net.Tests/Search/TestRegexpQuery.cs
@@ -115,23 +115,20 @@ public virtual void TestRegexComplement()
[Test]
public virtual void TestCustomProvider()
{
- IAutomatonProvider myProvider = new AutomatonProviderAnonymousClass(this);
+ IAutomatonProvider myProvider = new AutomatonProviderAnonymousClass();
RegexpQuery query = new RegexpQuery(NewTerm(""), RegExpSyntax.ALL, myProvider);
Assert.AreEqual(1, searcher.Search(query, 5).TotalHits);
}
private sealed class AutomatonProviderAnonymousClass : IAutomatonProvider
{
- private readonly TestRegexpQuery outerInstance;
-
- public AutomatonProviderAnonymousClass(TestRegexpQuery outerInstance)
- {
- this.outerInstance = outerInstance;
- quickBrownAutomaton = BasicOperations.Union(new Automaton[] { BasicAutomata.MakeString("quick"), BasicAutomata.MakeString("brown"), BasicAutomata.MakeString("bob") });
- }
-
// automaton that matches quick or brown
- private Automaton quickBrownAutomaton;
+ private Automaton quickBrownAutomaton = BasicOperations.Union(new Automaton[]
+ {
+ BasicAutomata.MakeString("quick"),
+ BasicAutomata.MakeString("brown"),
+ BasicAutomata.MakeString("bob")
+ });
public Automaton GetAutomaton(string name)
{
@@ -158,4 +155,4 @@ public virtual void TestBacktracking()
Assert.AreEqual(1, RegexQueryNrHits("4934[314]"));
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestRegexpRandom.cs b/src/Lucene.Net.Tests/Search/TestRegexpRandom.cs
index bc512c1d55..060ba58eee 100644
--- a/src/Lucene.Net.Tests/Search/TestRegexpRandom.cs
+++ b/src/Lucene.Net.Tests/Search/TestRegexpRandom.cs
@@ -52,7 +52,9 @@ public override void SetUp()
{
base.SetUp();
dir = NewDirectory();
- RandomIndexWriter writer = new RandomIndexWriter(Random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(TestUtil.NextInt32(Random, 50, 1000)));
+ RandomIndexWriter writer = new RandomIndexWriter(Random, dir,
+ NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetMaxBufferedDocs(TestUtil.NextInt32(Random, 50, 1000)));
Document doc = new Document();
FieldType customType = new FieldType(TextField.TYPE_STORED);
@@ -154,4 +156,4 @@ public virtual void TestRegexps()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestRegexpRandom2.cs b/src/Lucene.Net.Tests/Search/TestRegexpRandom2.cs
index 4104056f31..7730df0664 100644
--- a/src/Lucene.Net.Tests/Search/TestRegexpRandom2.cs
+++ b/src/Lucene.Net.Tests/Search/TestRegexpRandom2.cs
@@ -68,7 +68,9 @@ public override void SetUp()
base.SetUp();
dir = NewDirectory();
fieldName = Random.NextBoolean() ? "field" : ""; // sometimes use an empty string as field name
- RandomIndexWriter writer = new RandomIndexWriter(Random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.KEYWORD, false)).SetMaxBufferedDocs(TestUtil.NextInt32(Random, 50, 1000)));
+ RandomIndexWriter writer = new RandomIndexWriter(Random, dir,
+ NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.KEYWORD, false))
+ .SetMaxBufferedDocs(TestUtil.NextInt32(Random, 50, 1000)));
Document doc = new Document();
Field field = NewStringField(fieldName, "", Field.Store.NO);
doc.Add(field);
@@ -127,16 +129,12 @@ protected override TermsEnum GetTermsEnum(Terms terms, AttributeSource atts)
private sealed class SimpleAutomatonTermsEnum : FilteredTermsEnum
{
- private readonly TestRegexpRandom2.DumbRegexpQuery outerInstance;
-
private CharacterRunAutomaton runAutomaton;
private readonly CharsRef utf16 = new CharsRef(10);
internal SimpleAutomatonTermsEnum(TestRegexpRandom2.DumbRegexpQuery outerInstance, TermsEnum tenum)
: base(tenum)
{
- this.outerInstance = outerInstance;
-
runAutomaton = new CharacterRunAutomaton(outerInstance.automaton);
SetInitialSeekTerm(new BytesRef(""));
}
@@ -188,4 +186,4 @@ protected internal virtual void AssertSame(string regexp)
CheckHits.CheckEqual(smart, smartDocs.ScoreDocs, dumbDocs.ScoreDocs);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestSameScoresWithThreads.cs b/src/Lucene.Net.Tests/Search/TestSameScoresWithThreads.cs
index 39b152182f..13ce75c65f 100644
--- a/src/Lucene.Net.Tests/Search/TestSameScoresWithThreads.cs
+++ b/src/Lucene.Net.Tests/Search/TestSameScoresWithThreads.cs
@@ -96,7 +96,7 @@ public virtual void Test()
ThreadJob[] threads = new ThreadJob[numThreads];
for (int threadID = 0; threadID < numThreads; threadID++)
{
- ThreadJob thread = new ThreadAnonymousClass(this, s, answers, startingGun);
+ ThreadJob thread = new ThreadAnonymousClass(s, answers, startingGun);
threads[threadID] = thread;
thread.Start();
}
@@ -112,15 +112,12 @@ public virtual void Test()
private sealed class ThreadAnonymousClass : ThreadJob
{
- private readonly TestSameScoresWithThreads outerInstance;
-
private readonly IndexSearcher s;
private readonly IDictionary answers;
private readonly CountdownEvent startingGun;
- public ThreadAnonymousClass(TestSameScoresWithThreads outerInstance, IndexSearcher s, IDictionary answers, CountdownEvent startingGun)
+ public ThreadAnonymousClass(IndexSearcher s, IDictionary answers, CountdownEvent startingGun)
{
- this.outerInstance = outerInstance;
this.s = s;
this.answers = answers;
this.startingGun = startingGun;
@@ -157,4 +154,4 @@ public override void Run()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestScoreCachingWrappingScorer.cs b/src/Lucene.Net.Tests/Search/TestScoreCachingWrappingScorer.cs
index 5bf8287a10..2c8fd50ebe 100644
--- a/src/Lucene.Net.Tests/Search/TestScoreCachingWrappingScorer.cs
+++ b/src/Lucene.Net.Tests/Search/TestScoreCachingWrappingScorer.cs
@@ -108,7 +108,9 @@ public void SetScorer(Scorer scorer)
public bool AcceptsDocsOutOfOrder => true;
}
- private static readonly float[] scores = new float[] { 0.7767749f, 1.7839992f, 8.9925785f, 7.9608946f, 0.07948637f, 2.6356435f, 7.4950366f, 7.1490803f, 8.108544f, 4.961808f, 2.2423935f, 7.285586f, 4.6699767f };
+ private static readonly float[] scores = new float[] { 0.7767749f, 1.7839992f,
+ 8.9925785f, 7.9608946f, 0.07948637f, 2.6356435f, 7.4950366f, 7.1490803f,
+ 8.108544f, 4.961808f, 2.2423935f, 7.285586f, 4.6699767f };
[Test]
public virtual void TestGetScores()
@@ -119,7 +121,7 @@ public virtual void TestGetScores()
IndexReader ir = writer.GetReader();
writer.Dispose();
IndexSearcher searcher = NewSearcher(ir);
- Weight fake = (new TermQuery(new Term("fake", "weight"))).CreateWeight(searcher);
+ Weight fake = new TermQuery(new Term("fake", "weight")).CreateWeight(searcher);
Scorer s = new SimpleScorer(fake);
ScoreCachingCollector scc = new ScoreCachingCollector(scores.Length);
scc.SetScorer(s);
@@ -139,4 +141,4 @@ public virtual void TestGetScores()
directory.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestScorerPerf.cs b/src/Lucene.Net.Tests/Search/TestScorerPerf.cs
index 8396c01b23..be57b8e926 100644
--- a/src/Lucene.Net.Tests/Search/TestScorerPerf.cs
+++ b/src/Lucene.Net.Tests/Search/TestScorerPerf.cs
@@ -63,34 +63,35 @@ public virtual void CreateDummySearcher()
s = NewSearcher(r);
}
- public virtual void CreateRandomTerms(int nDocs, int nTerms, double power, Directory dir)
- {
- int[] freq = new int[nTerms];
- terms = new Term[nTerms];
- for (int i = 0; i < nTerms; i++)
- {
- int f = (nTerms + 1) - i; // make first terms less frequent
- freq[i] = (int)Math.Ceiling(Math.Pow(f, power));
- terms[i] = new Term("f", char.ToString((char)('A' + i)));
- }
-
- IndexWriter iw = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetOpenMode(OpenMode.CREATE));
- for (int i = 0; i < nDocs; i++)
- {
- Document d = new Document();
- for (int j = 0; j < nTerms; j++)
- {
- if (Random.Next(freq[j]) == 0)
- {
- d.Add(NewStringField("f", terms[j].Text, Field.Store.NO));
- //System.out.println(d);
- }
- }
- iw.AddDocument(d);
- }
- iw.ForceMerge(1);
- iw.Dispose();
- }
+ // LUCENENET: unused so commented out here, only used by commented-out code below
+ // public virtual void CreateRandomTerms(int nDocs, int nTerms, double power, Directory dir)
+ // {
+ // int[] freq = new int[nTerms];
+ // terms = new Term[nTerms];
+ // for (int i = 0; i < nTerms; i++)
+ // {
+ // int f = (nTerms + 1) - i; // make first terms less frequent
+ // freq[i] = (int)Math.Ceiling(Math.Pow(f, power));
+ // terms[i] = new Term("f", char.ToString((char)('A' + i)));
+ // }
+ //
+ // IndexWriter iw = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetOpenMode(OpenMode.CREATE));
+ // for (int i = 0; i < nDocs; i++)
+ // {
+ // Document d = new Document();
+ // for (int j = 0; j < nTerms; j++)
+ // {
+ // if (Random.Next(freq[j]) == 0)
+ // {
+ // d.Add(NewStringField("f", terms[j].Text, Field.Store.NO));
+ // //System.out.println(d);
+ // }
+ // }
+ // iw.AddDocument(d);
+ // }
+ // iw.ForceMerge(1);
+ // iw.Dispose();
+ // }
public virtual BitSet RandBitSet(int sz, int numBitsToSet)
{
@@ -264,115 +265,116 @@ public virtual int DoNestedConjunctions(int iter, int maxOuterClauses, int maxCl
return ret;
}
- public virtual int DoTermConjunctions(IndexSearcher s, int termsInIndex, int maxClauses, int iter)
- {
- int ret = 0;
-
- long nMatches = 0;
- for (int i = 0; i < iter; i++)
- {
- int nClauses = Random.Next(maxClauses - 1) + 2; // min 2 clauses
- BooleanQuery bq = new BooleanQuery();
- BitSet termflag = new BitSet(termsInIndex);
- for (int j = 0; j < nClauses; j++)
- {
- int tnum;
- // don't pick same clause twice
- tnum = Random.Next(termsInIndex);
- if (termflag.Get(tnum))
- {
- tnum = termflag.NextClearBit(tnum);
- }
- if (tnum < 0 || tnum >= termsInIndex)
- {
- tnum = termflag.NextClearBit(0);
- }
- termflag.Set(tnum);
- Query tq = new TermQuery(terms[tnum]);
- bq.Add(tq, Occur.MUST);
- }
-
- CountingHitCollector hc = new CountingHitCollector();
- s.Search(bq, hc);
- nMatches += hc.Count;
- ret += hc.Sum;
- }
- if (Verbose)
- {
- Console.WriteLine("Average number of matches=" + (nMatches / iter));
- }
-
- return ret;
- }
-
- public virtual int DoNestedTermConjunctions(IndexSearcher s, int termsInIndex, int maxOuterClauses, int maxClauses, int iter)
- {
- int ret = 0;
- long nMatches = 0;
- for (int i = 0; i < iter; i++)
- {
- int oClauses = Random.Next(maxOuterClauses - 1) + 2;
- BooleanQuery oq = new BooleanQuery();
- for (int o = 0; o < oClauses; o++)
- {
- int nClauses = Random.Next(maxClauses - 1) + 2; // min 2 clauses
- BooleanQuery bq = new BooleanQuery();
- BitSet termflag = new BitSet(termsInIndex);
- for (int j = 0; j < nClauses; j++)
- {
- int tnum;
- // don't pick same clause twice
- tnum = Random.Next(termsInIndex);
- if (termflag.Get(tnum))
- {
- tnum = termflag.NextClearBit(tnum);
- }
- if (tnum < 0 || tnum >= 25)
- {
- tnum = termflag.NextClearBit(0);
- }
- termflag.Set(tnum);
- Query tq = new TermQuery(terms[tnum]);
- bq.Add(tq, Occur.MUST);
- } // inner
-
- oq.Add(bq, Occur.MUST);
- } // outer
-
- CountingHitCollector hc = new CountingHitCollector();
- s.Search(oq, hc);
- nMatches += hc.Count;
- ret += hc.Sum;
- }
- if (Verbose)
- {
- Console.WriteLine("Average number of matches=" + (nMatches / iter));
- }
- return ret;
- }
-
- public virtual int DoSloppyPhrase(IndexSearcher s, int termsInIndex, int maxClauses, int iter)
- {
- int ret = 0;
-
- for (int i = 0; i < iter; i++)
- {
- int nClauses = Random.Next(maxClauses - 1) + 2; // min 2 clauses
- PhraseQuery q = new PhraseQuery();
- for (int j = 0; j < nClauses; j++)
- {
- int tnum = Random.Next(termsInIndex);
- q.Add(new Term("f", char.ToString((char)(tnum + 'A'))), j);
- }
- q.Slop = termsInIndex; // this could be random too
-
- CountingHitCollector hc = new CountingHitCollector();
- s.Search(q, hc);
- ret += hc.Sum;
- }
-
- return ret;
- }
+ // LUCENENET: unused so commented out here, only used by commented-out code below
+ // public virtual int DoTermConjunctions(IndexSearcher s, int termsInIndex, int maxClauses, int iter)
+ // {
+ // int ret = 0;
+ //
+ // long nMatches = 0;
+ // for (int i = 0; i < iter; i++)
+ // {
+ // int nClauses = Random.Next(maxClauses - 1) + 2; // min 2 clauses
+ // BooleanQuery bq = new BooleanQuery();
+ // BitSet termflag = new BitSet(termsInIndex);
+ // for (int j = 0; j < nClauses; j++)
+ // {
+ // int tnum;
+ // // don't pick same clause twice
+ // tnum = Random.Next(termsInIndex);
+ // if (termflag.Get(tnum))
+ // {
+ // tnum = termflag.NextClearBit(tnum);
+ // }
+ // if (tnum < 0 || tnum >= termsInIndex)
+ // {
+ // tnum = termflag.NextClearBit(0);
+ // }
+ // termflag.Set(tnum);
+ // Query tq = new TermQuery(terms[tnum]);
+ // bq.Add(tq, Occur.MUST);
+ // }
+ //
+ // CountingHitCollector hc = new CountingHitCollector();
+ // s.Search(bq, hc);
+ // nMatches += hc.Count;
+ // ret += hc.Sum;
+ // }
+ // if (Verbose)
+ // {
+ // Console.WriteLine("Average number of matches=" + (nMatches / iter));
+ // }
+ //
+ // return ret;
+ // }
+ //
+ // public virtual int DoNestedTermConjunctions(IndexSearcher s, int termsInIndex, int maxOuterClauses, int maxClauses, int iter)
+ // {
+ // int ret = 0;
+ // long nMatches = 0;
+ // for (int i = 0; i < iter; i++)
+ // {
+ // int oClauses = Random.Next(maxOuterClauses - 1) + 2;
+ // BooleanQuery oq = new BooleanQuery();
+ // for (int o = 0; o < oClauses; o++)
+ // {
+ // int nClauses = Random.Next(maxClauses - 1) + 2; // min 2 clauses
+ // BooleanQuery bq = new BooleanQuery();
+ // BitSet termflag = new BitSet(termsInIndex);
+ // for (int j = 0; j < nClauses; j++)
+ // {
+ // int tnum;
+ // // don't pick same clause twice
+ // tnum = Random.Next(termsInIndex);
+ // if (termflag.Get(tnum))
+ // {
+ // tnum = termflag.NextClearBit(tnum);
+ // }
+ // if (tnum < 0 || tnum >= 25)
+ // {
+ // tnum = termflag.NextClearBit(0);
+ // }
+ // termflag.Set(tnum);
+ // Query tq = new TermQuery(terms[tnum]);
+ // bq.Add(tq, Occur.MUST);
+ // } // inner
+ //
+ // oq.Add(bq, Occur.MUST);
+ // } // outer
+ //
+ // CountingHitCollector hc = new CountingHitCollector();
+ // s.Search(oq, hc);
+ // nMatches += hc.Count;
+ // ret += hc.Sum;
+ // }
+ // if (Verbose)
+ // {
+ // Console.WriteLine("Average number of matches=" + (nMatches / iter));
+ // }
+ // return ret;
+ // }
+ //
+ // public virtual int DoSloppyPhrase(IndexSearcher s, int termsInIndex, int maxClauses, int iter)
+ // {
+ // int ret = 0;
+ //
+ // for (int i = 0; i < iter; i++)
+ // {
+ // int nClauses = Random.Next(maxClauses - 1) + 2; // min 2 clauses
+ // PhraseQuery q = new PhraseQuery();
+ // for (int j = 0; j < nClauses; j++)
+ // {
+ // int tnum = Random.Next(termsInIndex);
+ // q.Add(new Term("f", char.ToString((char)(tnum + 'A'))), j);
+ // }
+ // q.Slop = termsInIndex; // this could be random too
+ //
+ // CountingHitCollector hc = new CountingHitCollector();
+ // s.Search(q, hc);
+ // ret += hc.Sum;
+ // }
+ //
+ // return ret;
+ // }
[Test]
public virtual void TestConjunctions()
@@ -474,4 +476,4 @@ public virtual void TestConjunctions()
/// **
*/
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestSearchWithThreads.cs b/src/Lucene.Net.Tests/Search/TestSearchWithThreads.cs
index 072ae6924b..1060663104 100644
--- a/src/Lucene.Net.Tests/Search/TestSearchWithThreads.cs
+++ b/src/Lucene.Net.Tests/Search/TestSearchWithThreads.cs
@@ -95,7 +95,7 @@ public virtual void Test()
for (int threadID = 0; threadID < NUM_SEARCH_THREADS; threadID++)
{
threads[threadID] = new ThreadAnonymousClass(this, s, failed, netSearch);
- threads[threadID].IsBackground = (true);
+ threads[threadID].IsBackground = true;
}
foreach (ThreadJob t in threads)
@@ -156,10 +156,10 @@ public override void Run()
}
catch (Exception exc) when (exc.IsException())
{
- failed.Value = (true);
+ failed.Value = true;
throw RuntimeException.Create(exc);
}
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestSearcherManager.cs b/src/Lucene.Net.Tests/Search/TestSearcherManager.cs
index a3f7ce4de8..2f1449d242 100644
--- a/src/Lucene.Net.Tests/Search/TestSearcherManager.cs
+++ b/src/Lucene.Net.Tests/Search/TestSearcherManager.cs
@@ -122,7 +122,7 @@ public override IndexSearcher NewSearcher(IndexReader r)
protected override void DoSearching(TaskScheduler es, long stopTime)
{
ThreadJob reopenThread = new ThreadAnonymousClass(this, stopTime);
- reopenThread.IsBackground = (true);
+ reopenThread.IsBackground = true;
reopenThread.Start();
RunSearchThreads(stopTime);
@@ -277,7 +277,7 @@ public virtual void TestIntermediateClose()
AtomicBoolean triedReopen = new AtomicBoolean(false);
//TaskScheduler es = Random().NextBoolean() ? null : Executors.newCachedThreadPool(new NamedThreadFactory("testIntermediateClose"));
TaskScheduler es = Random.NextBoolean() ? null : TaskScheduler.Default;
- SearcherFactory factory = new SearcherFactoryAnonymousClass2(this, awaitEnterWarm, awaitClose, triedReopen, es);
+ SearcherFactory factory = new SearcherFactoryAnonymousClass2(awaitEnterWarm, awaitClose, triedReopen, es);
SearcherManager searcherManager = Random.NextBoolean() ? new SearcherManager(dir, factory) : new SearcherManager(writer, Random.NextBoolean(), factory);
if (Verbose)
{
@@ -296,7 +296,7 @@ public virtual void TestIntermediateClose()
writer.Commit();
AtomicBoolean success = new AtomicBoolean(false);
Exception[] exc = new Exception[1];
- ThreadJob thread = new ThreadJob(() => new RunnableAnonymousClass(this, triedReopen, searcherManager, success, exc).Run());
+ ThreadJob thread = new ThreadJob(() => new RunnableAnonymousClass(triedReopen, searcherManager, success, exc).Run());
thread.Start();
if (Verbose)
{
@@ -333,16 +333,13 @@ public virtual void TestIntermediateClose()
private sealed class SearcherFactoryAnonymousClass2 : SearcherFactory
{
- private readonly TestSearcherManager outerInstance;
-
private CountdownEvent awaitEnterWarm;
private CountdownEvent awaitClose;
private AtomicBoolean triedReopen;
private TaskScheduler es;
- public SearcherFactoryAnonymousClass2(TestSearcherManager outerInstance, CountdownEvent awaitEnterWarm, CountdownEvent awaitClose, AtomicBoolean triedReopen, TaskScheduler es)
+ public SearcherFactoryAnonymousClass2(CountdownEvent awaitEnterWarm, CountdownEvent awaitClose, AtomicBoolean triedReopen, TaskScheduler es)
{
- this.outerInstance = outerInstance;
this.awaitEnterWarm = awaitEnterWarm;
this.awaitClose = awaitClose;
this.triedReopen = triedReopen;
@@ -369,16 +366,13 @@ public override IndexSearcher NewSearcher(IndexReader r)
private sealed class RunnableAnonymousClass //: IThreadRunnable
{
- private readonly TestSearcherManager outerInstance;
-
private AtomicBoolean triedReopen;
private SearcherManager searcherManager;
private AtomicBoolean success;
private Exception[] exc;
- public RunnableAnonymousClass(TestSearcherManager outerInstance, AtomicBoolean triedReopen, SearcherManager searcherManager, AtomicBoolean success, Exception[] exc)
+ public RunnableAnonymousClass(AtomicBoolean triedReopen, SearcherManager searcherManager, AtomicBoolean success, Exception[] exc)
{
- this.outerInstance = outerInstance;
this.triedReopen = triedReopen;
this.searcherManager = searcherManager;
this.success = success;
@@ -389,13 +383,13 @@ public void Run()
{
try
{
- triedReopen.Value = (true);
+ triedReopen.Value = true;
if (Verbose)
{
Console.WriteLine("NOW call maybeReopen");
}
searcherManager.MaybeRefresh();
- success.Value = (true);
+ success.Value = true;
}
catch (Exception e) when (e.IsAlreadyClosedException())
{
@@ -410,7 +404,7 @@ public void Run()
}
exc[0] = e;
// use success as the barrier here to make sure we see the write
- success.Value = (false);
+ success.Value = false;
}
}
}
@@ -504,7 +498,7 @@ public virtual void TestListenerCalled()
IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null));
AtomicBoolean afterRefreshCalled = new AtomicBoolean(false);
SearcherManager sm = new SearcherManager(iw, false, new SearcherFactory());
- sm.AddListener(new RefreshListenerAnonymousClass(this, afterRefreshCalled));
+ sm.AddListener(new RefreshListenerAnonymousClass(afterRefreshCalled));
iw.AddDocument(new Document());
iw.Commit();
assertFalse(afterRefreshCalled);
@@ -517,13 +511,10 @@ public virtual void TestListenerCalled()
private sealed class RefreshListenerAnonymousClass : ReferenceManager.IRefreshListener
{
- private readonly TestSearcherManager outerInstance;
-
private AtomicBoolean afterRefreshCalled;
- public RefreshListenerAnonymousClass(TestSearcherManager outerInstance, AtomicBoolean afterRefreshCalled)
+ public RefreshListenerAnonymousClass(AtomicBoolean afterRefreshCalled)
{
- this.outerInstance = outerInstance;
this.afterRefreshCalled = afterRefreshCalled;
}
@@ -535,7 +526,7 @@ public void AfterRefresh(bool didRefresh)
{
if (didRefresh)
{
- afterRefreshCalled.Value = (true);
+ afterRefreshCalled.Value = true;
}
}
}
@@ -550,7 +541,7 @@ public virtual void TestEvilSearcherFactory()
IndexReader other = DirectoryReader.Open(dir);
- SearcherFactory theEvilOne = new SearcherFactoryAnonymousClass3(this, other);
+ SearcherFactory theEvilOne = new SearcherFactoryAnonymousClass3(other);
try
{
@@ -575,13 +566,10 @@ public virtual void TestEvilSearcherFactory()
private sealed class SearcherFactoryAnonymousClass3 : SearcherFactory
{
- private readonly TestSearcherManager outerInstance;
-
private IndexReader other;
- public SearcherFactoryAnonymousClass3(TestSearcherManager outerInstance, IndexReader other)
+ public SearcherFactoryAnonymousClass3(IndexReader other)
{
- this.outerInstance = outerInstance;
this.other = other;
}
@@ -602,7 +590,7 @@ public virtual void TestMaybeRefreshBlockingLock()
SearcherManager sm = new SearcherManager(dir, null);
- ThreadJob t = new ThreadAnonymousClass2(this, sm);
+ ThreadJob t = new ThreadAnonymousClass2(sm);
t.Start();
t.Join();
@@ -615,13 +603,10 @@ public virtual void TestMaybeRefreshBlockingLock()
private sealed class ThreadAnonymousClass2 : ThreadJob
{
- private readonly TestSearcherManager outerInstance;
-
private SearcherManager sm;
- public ThreadAnonymousClass2(TestSearcherManager outerInstance, SearcherManager sm)
+ public ThreadAnonymousClass2(SearcherManager sm)
{
- this.outerInstance = outerInstance;
this.sm = sm;
}
@@ -639,4 +624,4 @@ public override void Run()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestShardSearching.cs b/src/Lucene.Net.Tests/Search/TestShardSearching.cs
index 0cefa1b93f..219aba5efd 100644
--- a/src/Lucene.Net.Tests/Search/TestShardSearching.cs
+++ b/src/Lucene.Net.Tests/Search/TestShardSearching.cs
@@ -1,7 +1,6 @@
using J2N.Collections.Generic.Extensions;
using NUnit.Framework;
using RandomizedTesting.Generators;
-using System;
using System.Collections.Generic;
using Assert = Lucene.Net.TestFramework.Assert;
using Console = Lucene.Net.Util.SystemConsole;
@@ -488,4 +487,4 @@ private PreviousSearchState AssertSame(IndexSearcher mockSearcher, NodeState.Sha
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestSimilarity.cs b/src/Lucene.Net.Tests/Search/TestSimilarity.cs
index f148c354b4..2eaa86ea09 100644
--- a/src/Lucene.Net.Tests/Search/TestSimilarity.cs
+++ b/src/Lucene.Net.Tests/Search/TestSimilarity.cs
@@ -36,8 +36,6 @@ namespace Lucene.Net.Search
///
/// Similarity unit test.
- ///
- ///
///
[TestFixture]
public class TestSimilarity : LuceneTestCase
@@ -104,23 +102,23 @@ public virtual void TestSimilarity_Mem()
Term b = new Term("field", "b");
Term c = new Term("field", "c");
- searcher.Search(new TermQuery(b), new CollectorAnonymousClass(this));
+ searcher.Search(new TermQuery(b), new CollectorAnonymousClass());
BooleanQuery bq = new BooleanQuery();
bq.Add(new TermQuery(a), Occur.SHOULD);
bq.Add(new TermQuery(b), Occur.SHOULD);
//System.out.println(bq.toString("field"));
- searcher.Search(bq, new CollectorAnonymousClass2(this));
+ searcher.Search(bq, new CollectorAnonymousClass2());
PhraseQuery pq = new PhraseQuery();
pq.Add(a);
pq.Add(c);
//System.out.println(pq.toString("field"));
- searcher.Search(pq, new CollectorAnonymousClass3(this));
+ searcher.Search(pq, new CollectorAnonymousClass3());
pq.Slop = 2;
//System.out.println(pq.toString("field"));
- searcher.Search(pq, new CollectorAnonymousClass4(this));
+ searcher.Search(pq, new CollectorAnonymousClass4());
reader.Dispose();
store.Dispose();
@@ -128,13 +126,6 @@ public virtual void TestSimilarity_Mem()
private sealed class CollectorAnonymousClass : ICollector
{
- private readonly TestSimilarity outerInstance;
-
- public CollectorAnonymousClass(TestSimilarity outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
private Scorer scorer;
public void SetScorer(Scorer scorer)
@@ -156,15 +147,7 @@ public void SetNextReader(AtomicReaderContext context)
private sealed class CollectorAnonymousClass2 : ICollector
{
- private readonly TestSimilarity outerInstance;
-
- public CollectorAnonymousClass2(TestSimilarity outerInstance)
- {
- this.outerInstance = outerInstance;
- @base = 0;
- }
-
- private int @base;
+ private int @base = 0;
private Scorer scorer;
public void SetScorer(Scorer scorer)
@@ -188,13 +171,6 @@ public void SetNextReader(AtomicReaderContext context)
private sealed class CollectorAnonymousClass3 : ICollector
{
- private readonly TestSimilarity outerInstance;
-
- public CollectorAnonymousClass3(TestSimilarity outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
private Scorer scorer;
public void SetScorer(Scorer scorer)
@@ -217,13 +193,6 @@ public void SetNextReader(AtomicReaderContext context)
private sealed class CollectorAnonymousClass4 : ICollector
{
- private readonly TestSimilarity outerInstance;
-
- public CollectorAnonymousClass4(TestSimilarity outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
private Scorer scorer;
public void SetScorer(Scorer scorer)
@@ -244,4 +213,4 @@ public void SetNextReader(AtomicReaderContext context)
public bool AcceptsDocsOutOfOrder => true;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestSimilarityProvider.cs b/src/Lucene.Net.Tests/Search/TestSimilarityProvider.cs
index 5df7c9f39c..42211ca509 100644
--- a/src/Lucene.Net.Tests/Search/TestSimilarityProvider.cs
+++ b/src/Lucene.Net.Tests/Search/TestSimilarityProvider.cs
@@ -53,7 +53,7 @@ public override void SetUp()
{
base.SetUp();
directory = NewDirectory();
- PerFieldSimilarityWrapper sim = new ExampleSimilarityProvider(this);
+ PerFieldSimilarityWrapper sim = new ExampleSimilarityProvider();
IndexWriterConfig iwc = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetSimilarity(sim);
RandomIndexWriter iw = new RandomIndexWriter(Random, directory, iwc);
Document doc = new Document();
@@ -105,17 +105,8 @@ public virtual void TestBasics()
private class ExampleSimilarityProvider : PerFieldSimilarityWrapper
{
- private readonly TestSimilarityProvider outerInstance;
-
- public ExampleSimilarityProvider(TestSimilarityProvider outerInstance)
- {
- this.outerInstance = outerInstance;
- sim1 = new Sim1(outerInstance);
- sim2 = new Sim2(outerInstance);
- }
-
- private readonly Similarity sim1;
- private readonly Similarity sim2;
+ private readonly Similarity sim1 = new Sim1();
+ private readonly Similarity sim2 = new Sim2();
public override Similarity Get(string field)
{
@@ -132,13 +123,6 @@ public override Similarity Get(string field)
private class Sim1 : TFIDFSimilarity
{
- private readonly TestSimilarityProvider outerInstance;
-
- public Sim1(TestSimilarityProvider outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
public override long EncodeNormValue(float f)
{
return (long)f;
@@ -187,13 +171,6 @@ public override float ScorePayload(int doc, int start, int end, BytesRef payload
private class Sim2 : TFIDFSimilarity
{
- private readonly TestSimilarityProvider outerInstance;
-
- public Sim2(TestSimilarityProvider outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
public override long EncodeNormValue(float f)
{
return (long)f;
@@ -240,4 +217,4 @@ public override float ScorePayload(int doc, int start, int end, BytesRef payload
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestSimpleExplanationsOfNonMatches.cs b/src/Lucene.Net.Tests/Search/TestSimpleExplanationsOfNonMatches.cs
index 486178f2a3..6ed12b0118 100644
--- a/src/Lucene.Net.Tests/Search/TestSimpleExplanationsOfNonMatches.cs
+++ b/src/Lucene.Net.Tests/Search/TestSimpleExplanationsOfNonMatches.cs
@@ -1,5 +1,3 @@
-using NUnit.Framework;
-
namespace Lucene.Net.Search
{
/*
@@ -28,10 +26,10 @@ public class TestSimpleExplanationsOfNonMatches : TestSimpleExplanations
///
/// Overrides superclass to ignore matches and focus on non-matches
///
- ///
+ ///
public override void Qtest(Query q, int[] expDocNrs)
{
CheckHits.CheckNoMatchExplanations(q, FIELD, searcher, expDocNrs);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestSloppyPhraseQuery.cs b/src/Lucene.Net.Tests/Search/TestSloppyPhraseQuery.cs
index d26721dab2..17ef5195fa 100644
--- a/src/Lucene.Net.Tests/Search/TestSloppyPhraseQuery.cs
+++ b/src/Lucene.Net.Tests/Search/TestSloppyPhraseQuery.cs
@@ -198,7 +198,7 @@ private static Document MakeDocument(string docText)
return doc;
}
-
+
private static PhraseQuery MakePhraseQuery(string terms)
{
@@ -339,7 +339,36 @@ public virtual void TestInfiniteFreq1()
[Test]
public virtual void TestInfiniteFreq2()
{
- string document = "So much fun to be had in my head " + "No more sunshine " + "So much fun just lying in my bed " + "No more sunshine " + "I can't face the sunlight and the dirt outside " + "Wanna stay in 666 where this darkness don't lie " + "Drug drug druggy " + "Got a feeling sweet like honey " + "Drug drug druggy " + "Need sensation like my baby " + "Show me your scars you're so aware " + "I'm not barbaric I just care " + "Drug drug drug " + "I need a reflection to prove I exist " + "No more sunshine " + "I am a victim of designer blitz " + "No more sunshine " + "Dance like a robot when you're chained at the knee " + "The C.I.A say you're all they'll ever need " + "Drug drug druggy " + "Got a feeling sweet like honey " + "Drug drug druggy " + "Need sensation like my baby " + "Snort your lines you're so aware " + "I'm not barbaric I just care " + "Drug drug druggy " + "Got a feeling sweet like honey " + "Drug drug druggy " + "Need sensation like my baby";
+ string document =
+ "So much fun to be had in my head " +
+ "No more sunshine " +
+ "So much fun just lying in my bed " +
+ "No more sunshine " +
+ "I can't face the sunlight and the dirt outside " +
+ "Wanna stay in 666 where this darkness don't lie " +
+ "Drug drug druggy " +
+ "Got a feeling sweet like honey " +
+ "Drug drug druggy " +
+ "Need sensation like my baby " +
+ "Show me your scars you're so aware " +
+ "I'm not barbaric I just care " +
+ "Drug drug drug " +
+ "I need a reflection to prove I exist " +
+ "No more sunshine " +
+ "I am a victim of designer blitz " +
+ "No more sunshine " +
+ "Dance like a robot when you're chained at the knee " +
+ "The C.I.A say you're all they'll ever need " +
+ "Drug drug druggy " +
+ "Got a feeling sweet like honey " +
+ "Drug drug druggy " +
+ "Need sensation like my baby " +
+ "Snort your lines you're so aware " +
+ "I'm not barbaric I just care " +
+ "Drug drug druggy " +
+ "Got a feeling sweet like honey " +
+ "Drug drug druggy " +
+ "Need sensation like my baby";
Directory dir = NewDirectory();
@@ -362,4 +391,4 @@ public virtual void TestInfiniteFreq2()
dir.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestSloppyPhraseQuery2.cs b/src/Lucene.Net.Tests/Search/TestSloppyPhraseQuery2.cs
index 02529ac3a7..59227adb88 100644
--- a/src/Lucene.Net.Tests/Search/TestSloppyPhraseQuery2.cs
+++ b/src/Lucene.Net.Tests/Search/TestSloppyPhraseQuery2.cs
@@ -1,7 +1,10 @@
using NUnit.Framework;
-using RandomizedTesting.Generators;
using System;
+#if !FEATURE_RANDOM_NEXTINT64_NEXTSINGLE
+using RandomizedTesting.Generators;
+#endif
+
namespace Lucene.Net.Search
{
/*
@@ -244,4 +247,4 @@ private MultiPhraseQuery RandomPhraseQuery(long seed)
return pq;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestSort.cs b/src/Lucene.Net.Tests/Search/TestSort.cs
index 847012bc52..434b96e205 100644
--- a/src/Lucene.Net.Tests/Search/TestSort.cs
+++ b/src/Lucene.Net.Tests/Search/TestSort.cs
@@ -68,8 +68,8 @@ public class TestSort : LuceneTestCase
{
///
/// LUCENENET specific. Ensure we have an infostream attached to the default FieldCache
- /// when running the tests. In Java, this was done in the Core.Search.TestFieldCache.TestInfoStream()
- /// method (which polluted the state of these tests), but we need to make the tests self-contained
+ /// when running the tests. In Java, this was done in the Core.Search.TestFieldCache.TestInfoStream()
+ /// method (which polluted the state of these tests), but we need to make the tests self-contained
/// so they can be run correctly regardless of order. Not setting the InfoStream skips an execution
/// path within these tests, so we should do it to make sure we test all of the code.
///
@@ -1565,7 +1565,7 @@ public virtual void TestCustomIntParser()
iw.Dispose();
IndexSearcher searcher = NewSearcher(ir);
- Sort sort = new Sort(new SortField("parser", new IntParserAnonymousClass(this)), SortField.FIELD_DOC);
+ Sort sort = new Sort(new SortField("parser", new IntParserAnonymousClass()), SortField.FIELD_DOC);
TopDocs td = searcher.Search(new MatchAllDocsQuery(), 10, sort);
@@ -1583,13 +1583,6 @@ public virtual void TestCustomIntParser()
private sealed class IntParserAnonymousClass : FieldCache.IInt32Parser
{
- private readonly TestSort outerInstance;
-
- public IntParserAnonymousClass(TestSort outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
///
/// NOTE: This was parseInt() in Lucene
///
@@ -1626,7 +1619,7 @@ public virtual void TestCustomByteParser()
iw.Dispose();
IndexSearcher searcher = NewSearcher(ir);
- Sort sort = new Sort(new SortField("parser", new ByteParserAnonymousClass(this)), SortField.FIELD_DOC);
+ Sort sort = new Sort(new SortField("parser", new ByteParserAnonymousClass()), SortField.FIELD_DOC);
TopDocs td = searcher.Search(new MatchAllDocsQuery(), 10, sort);
@@ -1646,13 +1639,6 @@ public virtual void TestCustomByteParser()
private sealed class ByteParserAnonymousClass : FieldCache.IByteParser
#pragma warning restore 612, 618
{
- private readonly TestSort outerInstance;
-
- public ByteParserAnonymousClass(TestSort outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
public byte ParseByte(BytesRef term)
{
return (byte)(term.Bytes[term.Offset] - 'A');
@@ -1686,7 +1672,7 @@ public virtual void TestCustomShortParser()
iw.Dispose();
IndexSearcher searcher = NewSearcher(ir);
- Sort sort = new Sort(new SortField("parser", new ShortParserAnonymousClass(this)), SortField.FIELD_DOC);
+ Sort sort = new Sort(new SortField("parser", new ShortParserAnonymousClass()), SortField.FIELD_DOC);
TopDocs td = searcher.Search(new MatchAllDocsQuery(), 10, sort);
@@ -1706,13 +1692,6 @@ public virtual void TestCustomShortParser()
private sealed class ShortParserAnonymousClass : FieldCache.IInt16Parser
#pragma warning restore 612, 618
{
- private readonly TestSort outerInstance;
-
- public ShortParserAnonymousClass(TestSort outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
///
/// NOTE: This was parseShort() in Lucene
///
@@ -1749,7 +1728,7 @@ public virtual void TestCustomLongParser()
iw.Dispose();
IndexSearcher searcher = NewSearcher(ir);
- Sort sort = new Sort(new SortField("parser", new LongParserAnonymousClass(this)), SortField.FIELD_DOC);
+ Sort sort = new Sort(new SortField("parser", new LongParserAnonymousClass()), SortField.FIELD_DOC);
TopDocs td = searcher.Search(new MatchAllDocsQuery(), 10, sort);
@@ -1767,13 +1746,6 @@ public virtual void TestCustomLongParser()
private sealed class LongParserAnonymousClass : FieldCache.IInt64Parser
{
- private readonly TestSort outerInstance;
-
- public LongParserAnonymousClass(TestSort outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
///
/// NOTE: This was parseLong() in Lucene
///
@@ -1810,7 +1782,7 @@ public virtual void TestCustomFloatParser()
iw.Dispose();
IndexSearcher searcher = NewSearcher(ir);
- Sort sort = new Sort(new SortField("parser", new FloatParserAnonymousClass(this)), SortField.FIELD_DOC);
+ Sort sort = new Sort(new SortField("parser", new FloatParserAnonymousClass()), SortField.FIELD_DOC);
TopDocs td = searcher.Search(new MatchAllDocsQuery(), 10, sort);
@@ -1828,13 +1800,6 @@ public virtual void TestCustomFloatParser()
private sealed class FloatParserAnonymousClass : FieldCache.ISingleParser
{
- private readonly TestSort outerInstance;
-
- public FloatParserAnonymousClass(TestSort outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
///
/// NOTE: This was parseFloat() in Lucene
///
@@ -1871,7 +1836,7 @@ public virtual void TestCustomDoubleParser()
iw.Dispose();
IndexSearcher searcher = NewSearcher(ir);
- Sort sort = new Sort(new SortField("parser", new DoubleParserAnonymousClass(this)), SortField.FIELD_DOC);
+ Sort sort = new Sort(new SortField("parser", new DoubleParserAnonymousClass()), SortField.FIELD_DOC);
TopDocs td = searcher.Search(new MatchAllDocsQuery(), 10, sort);
@@ -1889,13 +1854,6 @@ public virtual void TestCustomDoubleParser()
private sealed class DoubleParserAnonymousClass : FieldCache.IDoubleParser
{
- private readonly TestSort outerInstance;
-
- public DoubleParserAnonymousClass(TestSort outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
public double ParseDouble(BytesRef term)
{
return Math.Pow(term.Bytes[term.Offset], (term.Bytes[term.Offset] - 'A'));
@@ -2019,4 +1977,4 @@ public virtual void TestScore()
dir.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestSortRandom.cs b/src/Lucene.Net.Tests/Search/TestSortRandom.cs
index f69526518e..973d7e85e6 100644
--- a/src/Lucene.Net.Tests/Search/TestSortRandom.cs
+++ b/src/Lucene.Net.Tests/Search/TestSortRandom.cs
@@ -73,7 +73,7 @@ public virtual void TestRandomStringSort()
// 10% of the time, the document is missing the value:
BytesRef br;
- if (LuceneTestCase.Random.Next(10) != 7)
+ if (Random.Next(10) != 7)
{
string s;
if (random.NextBoolean())
@@ -217,7 +217,7 @@ public virtual void TestRandomStringSort()
// Compute expected results:
var expected = f.matchValues.ToList();
-
+
expected.Sort(Comparer.Create((a,b) =>
{
if (a is null)
@@ -350,4 +350,4 @@ public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDo
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestSortRescorer.cs b/src/Lucene.Net.Tests/Search/TestSortRescorer.cs
index d409fd5b61..babbd7746a 100644
--- a/src/Lucene.Net.Tests/Search/TestSortRescorer.cs
+++ b/src/Lucene.Net.Tests/Search/TestSortRescorer.cs
@@ -189,12 +189,12 @@ public virtual void TestRandom()
bool fail = false;
for (int i = 0; i < numHits; i++)
{
- fail |= (int)expected[i] != hits2.ScoreDocs[i].Doc;
+ fail |= expected[i] != hits2.ScoreDocs[i].Doc;
}
Assert.IsFalse(fail);
r.Dispose();
dir.Dispose();
- }
+ }
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestSubScorerFreqs.cs b/src/Lucene.Net.Tests/Search/TestSubScorerFreqs.cs
index dfc981d373..13f45234cd 100644
--- a/src/Lucene.Net.Tests/Search/TestSubScorerFreqs.cs
+++ b/src/Lucene.Net.Tests/Search/TestSubScorerFreqs.cs
@@ -47,11 +47,11 @@ public override void BeforeClass() // LUCENENET specific - renamed from MakeInde
int num = AtLeast(31);
for (int i = 0; i < num; i++)
{
- Documents.Document doc = new Documents.Document();
+ Document doc = new Document();
doc.Add(NewTextField("f", "a b c d b c d c d d", Field.Store.NO));
w.AddDocument(doc);
- doc = new Documents.Document();
+ doc = new Document();
doc.Add(NewTextField("f", "a b c d", Field.Store.NO));
w.AddDocument(doc);
}
@@ -228,4 +228,4 @@ public virtual void TestPhraseQuery()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestTermScorer.cs b/src/Lucene.Net.Tests/Search/TestTermScorer.cs
index cca779b45f..34491b4642 100644
--- a/src/Lucene.Net.Tests/Search/TestTermScorer.cs
+++ b/src/Lucene.Net.Tests/Search/TestTermScorer.cs
@@ -52,7 +52,10 @@ public override void SetUp()
base.SetUp();
directory = NewDirectory();
- RandomIndexWriter writer = new RandomIndexWriter(Random, directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMergePolicy(NewLogMergePolicy()).SetSimilarity(new DefaultSimilarity()));
+ RandomIndexWriter writer = new RandomIndexWriter(Random, directory,
+ NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetMergePolicy(NewLogMergePolicy())
+ .SetSimilarity(new DefaultSimilarity()));
for (int i = 0; i < values.Length; i++)
{
Document doc = new Document();
@@ -82,13 +85,13 @@ public virtual void Test()
Weight weight = indexSearcher.CreateNormalizedWeight(termQuery);
Assert.IsTrue(indexSearcher.TopReaderContext is AtomicReaderContext);
AtomicReaderContext context = (AtomicReaderContext)indexSearcher.TopReaderContext;
- BulkScorer ts = weight.GetBulkScorer(context, true, (context.AtomicReader).LiveDocs);
+ BulkScorer ts = weight.GetBulkScorer(context, true, context.AtomicReader.LiveDocs);
// we have 2 documents with the term all in them, one document for all the
// other values
IList docs = new JCG.List();
// must call next first
- ts.Score(new CollectorAnonymousClass(this, context, docs));
+ ts.Score(new CollectorAnonymousClass(this, docs));
Assert.IsTrue(docs.Count == 2, "docs Size: " + docs.Count + " is not: " + 2);
TestHit doc0 = docs[0];
TestHit doc5 = docs[1];
@@ -110,13 +113,11 @@ private sealed class CollectorAnonymousClass : ICollector
{
private readonly TestTermScorer outerInstance;
- private AtomicReaderContext context;
private readonly IList docs;
- public CollectorAnonymousClass(TestTermScorer outerInstance, AtomicReaderContext context, IList docs)
+ public CollectorAnonymousClass(TestTermScorer outerInstance, IList docs)
{
this.outerInstance = outerInstance;
- this.context = context;
this.docs = docs;
@base = 0;
}
@@ -133,7 +134,7 @@ public void Collect(int doc)
{
float score = scorer.GetScore();
doc = doc + @base;
- docs.Add(new TestHit(outerInstance, doc, score));
+ docs.Add(new TestHit(doc, score));
Assert.IsTrue(score > 0, "score " + score + " is not greater than 0");
Assert.IsTrue(doc == 0 || doc == 5, "Doc: " + doc + " does not equal 0 or doc does not equal 5");
}
@@ -180,14 +181,11 @@ public virtual void TestAdvance()
private class TestHit
{
- private readonly TestTermScorer outerInstance;
-
public int Doc { get; }
public float Score { get; }
- public TestHit(TestTermScorer outerInstance, int doc, float score)
+ public TestHit(int doc, float score)
{
- this.outerInstance = outerInstance;
this.Doc = doc;
this.Score = score;
}
@@ -198,4 +196,4 @@ public override string ToString()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestTimeLimitingCollector.cs b/src/Lucene.Net.Tests/Search/TestTimeLimitingCollector.cs
index 2abe196abb..20fa9066ac 100644
--- a/src/Lucene.Net.Tests/Search/TestTimeLimitingCollector.cs
+++ b/src/Lucene.Net.Tests/Search/TestTimeLimitingCollector.cs
@@ -39,22 +39,22 @@ namespace Lucene.Net.Search
///
public class TestTimeLimitingCollector : LuceneTestCase
{
- private static readonly int SLOW_DOWN = 3;
- private static readonly long TIME_ALLOWED = 17 * SLOW_DOWN; // so searches can find about 17 docs.
+ private const int SLOW_DOWN = 3;
+ private const long TIME_ALLOWED = 17 * SLOW_DOWN; // so searches can find about 17 docs.
- // max time allowed is relaxed for multithreading tests.
- // the multithread case fails when setting this to 1 (no slack) and launching many threads (>2000).
+ // max time allowed is relaxed for multithreading tests.
+ // the multithread case fails when setting this to 1 (no slack) and launching many threads (>2000).
// but this is not a real failure, just noise.
- private static readonly double MULTI_THREAD_SLACK = 7;
+ private const double MULTI_THREAD_SLACK = 7;
- private static readonly int N_DOCS = 3000;
- private static readonly int N_THREADS = 50;
+ private const int N_DOCS = 3000;
+ private const int N_THREADS = 50;
private IndexSearcher searcher;
private Directory directory;
private IndexReader reader;
- private readonly string FIELD_NAME = "body";
+ private const string FIELD_NAME = "body";
private Query query;
private Counter counter;
private TimeLimitingCollector.TimerThread counterThread;
@@ -67,7 +67,7 @@ public class TestTimeLimitingCollector : LuceneTestCase
public override void SetUp()
{
base.SetUp();
- counter = Lucene.Net.Util.Counter.NewCounter(true);
+ counter = Counter.NewCounter(true);
counterThread = new TimeLimitingCollector.TimerThread(counter);
counterThread.Start();
string[] docText = {
@@ -167,7 +167,7 @@ private void DoTestSearch()
private ICollector CreateTimedCollector(MyHitCollector hc, long timeAllowed, bool greedy)
{
TimeLimitingCollector res = new TimeLimitingCollector(hc, counter, timeAllowed);
- res.IsGreedy = (greedy); // set to true to make sure at least one doc is collected.
+ res.IsGreedy = greedy; // set to true to make sure at least one doc is collected.
return res;
}
@@ -252,7 +252,7 @@ private long MaxTime(bool multiThreaded)
long res = 2 * counterThread.Resolution + TIME_ALLOWED + SLOW_DOWN; // some slack for less noise in this test
if (multiThreaded)
{
- res = (long)(res * MULTI_THREAD_SLACK); // larger slack
+ res = (long)(res * MULTI_THREAD_SLACK); // larger slack
}
return res;
}
@@ -272,7 +272,7 @@ private string MaxTimeStr(bool multiThreaded)
}
/**
- * Test timeout behavior when resolution is modified.
+ * Test timeout behavior when resolution is modified.
*/
[Test]
public void TestModifyResolution()
@@ -301,7 +301,7 @@ public void TestModifyResolution()
}
}
- /**
+ /**
* Test correctness with multiple searching threads.
*/
[Test]
@@ -310,7 +310,7 @@ public void TestSearchMultiThreaded()
DoTestMultiThreads(false);
}
- /**
+ /**
* Test correctness with multiple searching threads.
*/
[Test]
@@ -345,6 +345,7 @@ private sealed class ThreadAnonymousClass : ThreadJob
private readonly OpenBitSet success;
private readonly bool withTimeout;
private readonly int num;
+
public ThreadAnonymousClass(TestTimeLimitingCollector outerInstance, OpenBitSet success, bool withTimeout, int num)
{
this.outerInstance = outerInstance;
@@ -352,6 +353,7 @@ public ThreadAnonymousClass(TestTimeLimitingCollector outerInstance, OpenBitSet
this.withTimeout = withTimeout;
this.num = num;
}
+
public override void Run()
{
if (withTimeout)
@@ -362,6 +364,8 @@ public override void Run()
{
outerInstance.DoTestSearch();
}
+
+ // LUCENENET: using UninterruptableMonitor instead of lock, see UninterruptableMonitor docs
UninterruptableMonitor.Enter(success);
try
{
diff --git a/src/Lucene.Net.Tests/Search/TestTopDocsCollector.cs b/src/Lucene.Net.Tests/Search/TestTopDocsCollector.cs
index d420f07bc2..48dc289c65 100644
--- a/src/Lucene.Net.Tests/Search/TestTopDocsCollector.cs
+++ b/src/Lucene.Net.Tests/Search/TestTopDocsCollector.cs
@@ -85,7 +85,14 @@ public override void SetScorer(Scorer scorer)
// Scores array to be used by MyTopDocsCollector. If it is changed, MAX_SCORE
// must also change.
- private static readonly float[] scores = new float[] { 0.7767749f, 1.7839992f, 8.9925785f, 7.9608946f, 0.07948637f, 2.6356435f, 7.4950366f, 7.1490803f, 8.108544f, 4.961808f, 2.2423935f, 7.285586f, 4.6699767f, 2.9655676f, 6.953706f, 5.383931f, 6.9916306f, 8.365894f, 7.888485f, 8.723962f, 3.1796896f, 0.39971232f, 1.3077754f, 6.8489285f, 9.17561f, 5.060466f, 7.9793315f, 8.601509f, 4.1858315f, 0.28146625f };
+ private static readonly float[] scores = new float[]
+ {
+ 0.7767749f, 1.7839992f, 8.9925785f, 7.9608946f, 0.07948637f, 2.6356435f,
+ 7.4950366f, 7.1490803f, 8.108544f, 4.961808f, 2.2423935f, 7.285586f, 4.6699767f,
+ 2.9655676f, 6.953706f, 5.383931f, 6.9916306f, 8.365894f, 7.888485f, 8.723962f,
+ 3.1796896f, 0.39971232f, 1.3077754f, 6.8489285f, 9.17561f, 5.060466f, 7.9793315f,
+ 8.601509f, 4.1858315f, 0.28146625f
+ };
private const float MAX_SCORE = 9.17561f;
@@ -227,4 +234,4 @@ public virtual void TestResultsOrder()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestTopFieldCollector.cs b/src/Lucene.Net.Tests/Search/TestTopFieldCollector.cs
index 82b89eed96..c8c4969257 100644
--- a/src/Lucene.Net.Tests/Search/TestTopFieldCollector.cs
+++ b/src/Lucene.Net.Tests/Search/TestTopFieldCollector.cs
@@ -178,8 +178,28 @@ public virtual void TestOutOfOrderDocsScoringSort()
{
// Two Sort criteria to instantiate the multi/single comparers.
Sort[] sort = new Sort[] { new Sort(SortField.FIELD_DOC), new Sort() };
- bool[][] tfcOptions = new bool[][] { new bool[] { false, false, false }, new bool[] { false, false, true }, new bool[] { false, true, false }, new bool[] { false, true, true }, new bool[] { true, false, false }, new bool[] { true, false, true }, new bool[] { true, true, false }, new bool[] { true, true, true } };
- string[] actualTFCClasses = new string[] { "OutOfOrderOneComparerNonScoringCollector", "OutOfOrderOneComparerScoringMaxScoreCollector", "OutOfOrderOneComparerScoringNoMaxScoreCollector", "OutOfOrderOneComparerScoringMaxScoreCollector", "OutOfOrderOneComparerNonScoringCollector", "OutOfOrderOneComparerScoringMaxScoreCollector", "OutOfOrderOneComparerScoringNoMaxScoreCollector", "OutOfOrderOneComparerScoringMaxScoreCollector" };
+ bool[][] tfcOptions = new bool[][]
+ {
+ new bool[] { false, false, false },
+ new bool[] { false, false, true },
+ new bool[] { false, true, false },
+ new bool[] { false, true, true },
+ new bool[] { true, false, false },
+ new bool[] { true, false, true },
+ new bool[] { true, true, false },
+ new bool[] { true, true, true }
+ };
+ string[] actualTFCClasses = new string[]
+ {
+ "OutOfOrderOneComparerNonScoringCollector",
+ "OutOfOrderOneComparerScoringMaxScoreCollector",
+ "OutOfOrderOneComparerScoringNoMaxScoreCollector",
+ "OutOfOrderOneComparerScoringMaxScoreCollector",
+ "OutOfOrderOneComparerNonScoringCollector",
+ "OutOfOrderOneComparerScoringMaxScoreCollector",
+ "OutOfOrderOneComparerScoringNoMaxScoreCollector",
+ "OutOfOrderOneComparerScoringMaxScoreCollector"
+ };
BooleanQuery bq = new BooleanQuery();
// Add a Query with SHOULD, since bw.Scorer() returns BooleanScorer2
@@ -211,8 +231,28 @@ public virtual void TestOutOfOrderDocsScoringSortMulti()
{
// Two Sort criteria to instantiate the multi/single comparers.
Sort[] sort = new Sort[] { new Sort(SortField.FIELD_DOC, SortField.FIELD_SCORE) };
- bool[][] tfcOptions = new bool[][] { new bool[] { false, false, false }, new bool[] { false, false, true }, new bool[] { false, true, false }, new bool[] { false, true, true }, new bool[] { true, false, false }, new bool[] { true, false, true }, new bool[] { true, true, false }, new bool[] { true, true, true } };
- string[] actualTFCClasses = new string[] { "OutOfOrderMultiComparerNonScoringCollector", "OutOfOrderMultiComparerScoringMaxScoreCollector", "OutOfOrderMultiComparerScoringNoMaxScoreCollector", "OutOfOrderMultiComparerScoringMaxScoreCollector", "OutOfOrderMultiComparerNonScoringCollector", "OutOfOrderMultiComparerScoringMaxScoreCollector", "OutOfOrderMultiComparerScoringNoMaxScoreCollector", "OutOfOrderMultiComparerScoringMaxScoreCollector" };
+ bool[][] tfcOptions = new bool[][]
+ {
+ new bool[] { false, false, false },
+ new bool[] { false, false, true },
+ new bool[] { false, true, false },
+ new bool[] { false, true, true },
+ new bool[] { true, false, false },
+ new bool[] { true, false, true },
+ new bool[] { true, true, false },
+ new bool[] { true, true, true }
+ };
+ string[] actualTFCClasses = new string[]
+ {
+ "OutOfOrderMultiComparerNonScoringCollector",
+ "OutOfOrderMultiComparerScoringMaxScoreCollector",
+ "OutOfOrderMultiComparerScoringNoMaxScoreCollector",
+ "OutOfOrderMultiComparerScoringMaxScoreCollector",
+ "OutOfOrderMultiComparerNonScoringCollector",
+ "OutOfOrderMultiComparerScoringMaxScoreCollector",
+ "OutOfOrderMultiComparerScoringNoMaxScoreCollector",
+ "OutOfOrderMultiComparerScoringMaxScoreCollector"
+ };
BooleanQuery bq = new BooleanQuery();
// Add a Query with SHOULD, since bw.Scorer() returns BooleanScorer2
@@ -252,4 +292,4 @@ public virtual void TestSortWithScoreAndMaxScoreTrackingNoResults()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestWildcard.cs b/src/Lucene.Net.Tests/Search/TestWildcard.cs
index 4c9e5cc4be..b0d9762d9e 100644
--- a/src/Lucene.Net.Tests/Search/TestWildcard.cs
+++ b/src/Lucene.Net.Tests/Search/TestWildcard.cs
@@ -292,18 +292,91 @@ public virtual void TestParsingAndSearching()
string[] docs = new string[] { "\\ abcdefg1", "\\x00079 hijklmn1", "\\\\ opqrstu1" };
// queries that should find all docs
- Query[] matchAll = new Query[] { new WildcardQuery(new Term(field, "*")), new WildcardQuery(new Term(field, "*1")), new WildcardQuery(new Term(field, "**1")), new WildcardQuery(new Term(field, "*?")), new WildcardQuery(new Term(field, "*?1")), new WildcardQuery(new Term(field, "?*1")), new WildcardQuery(new Term(field, "**")), new WildcardQuery(new Term(field, "***")), new WildcardQuery(new Term(field, "\\\\*")) };
+ Query[] matchAll = new Query[]
+ {
+ new WildcardQuery(new Term(field, "*")),
+ new WildcardQuery(new Term(field, "*1")),
+ new WildcardQuery(new Term(field, "**1")),
+ new WildcardQuery(new Term(field, "*?")),
+ new WildcardQuery(new Term(field, "*?1")),
+ new WildcardQuery(new Term(field, "?*1")),
+ new WildcardQuery(new Term(field, "**")),
+ new WildcardQuery(new Term(field, "***")),
+ new WildcardQuery(new Term(field, "\\\\*"))
+ };
// queries that should find no docs
- Query[] matchNone = new Query[] { new WildcardQuery(new Term(field, "a*h")), new WildcardQuery(new Term(field, "a?h")), new WildcardQuery(new Term(field, "*a*h")), new WildcardQuery(new Term(field, "?a")), new WildcardQuery(new Term(field, "a?")) };
-
- PrefixQuery[][] matchOneDocPrefix = new PrefixQuery[][] { new PrefixQuery[] { new PrefixQuery(new Term(field, "a")), new PrefixQuery(new Term(field, "ab")), new PrefixQuery(new Term(field, "abc")) }, new PrefixQuery[] { new PrefixQuery(new Term(field, "h")), new PrefixQuery(new Term(field, "hi")), new PrefixQuery(new Term(field, "hij")), new PrefixQuery(new Term(field, "\\x0007")) }, new PrefixQuery[] { new PrefixQuery(new Term(field, "o")), new PrefixQuery(new Term(field, "op")), new PrefixQuery(new Term(field, "opq")), new PrefixQuery(new Term(field, "\\\\")) } };
+ Query[] matchNone = new Query[]
+ {
+ new WildcardQuery(new Term(field, "a*h")),
+ new WildcardQuery(new Term(field, "a?h")),
+ new WildcardQuery(new Term(field, "*a*h")),
+ new WildcardQuery(new Term(field, "?a")),
+ new WildcardQuery(new Term(field, "a?"))
+ };
+
+ PrefixQuery[][] matchOneDocPrefix = new PrefixQuery[][]
+ {
+ new[]
+ {
+ new PrefixQuery(new Term(field, "a")),
+ new PrefixQuery(new Term(field, "ab")),
+ new PrefixQuery(new Term(field, "abc")) // these should find only doc 0
+ },
+ new[]
+ {
+ new PrefixQuery(new Term(field, "h")),
+ new PrefixQuery(new Term(field, "hi")),
+ new PrefixQuery(new Term(field, "hij")),
+ new PrefixQuery(new Term(field, "\\x0007")) // these should find only doc 1
+ },
+ new[]
+ {
+ new PrefixQuery(new Term(field, "o")),
+ new PrefixQuery(new Term(field, "op")),
+ new PrefixQuery(new Term(field, "opq")),
+ new PrefixQuery(new Term(field, "\\\\")) // these should find only doc 2
+ }
+ };
- WildcardQuery[][] matchOneDocWild = new WildcardQuery[][] { new WildcardQuery[] { new WildcardQuery(new Term(field, "*a*")), new WildcardQuery(new Term(field, "*ab*")), new WildcardQuery(new Term(field, "*abc**")), new WildcardQuery(new Term(field, "ab*e*")), new WildcardQuery(new Term(field, "*g?")), new WildcardQuery(new Term(field, "*f?1")) }, new WildcardQuery[] { new WildcardQuery(new Term(field, "*h*")), new WildcardQuery(new Term(field, "*hi*")), new WildcardQuery(new Term(field, "*hij**")), new WildcardQuery(new Term(field, "hi*k*")), new WildcardQuery(new Term(field, "*n?")), new WildcardQuery(new Term(field, "*m?1")), new WildcardQuery(new Term(field, "hij**")) }, new WildcardQuery[] { new WildcardQuery(new Term(field, "*o*")), new WildcardQuery(new Term(field, "*op*")), new WildcardQuery(new Term(field, "*opq**")), new WildcardQuery(new Term(field, "op*q*")), new WildcardQuery(new Term(field, "*u?")), new WildcardQuery(new Term(field, "*t?1")), new WildcardQuery(new Term(field, "opq**")) } };
+ WildcardQuery[][] matchOneDocWild = new WildcardQuery[][]
+ {
+ new[]
+ {
+ new WildcardQuery(new Term(field, "*a*")), // these should find only doc 0
+ new WildcardQuery(new Term(field, "*ab*")),
+ new WildcardQuery(new Term(field, "*abc**")),
+ new WildcardQuery(new Term(field, "ab*e*")),
+ new WildcardQuery(new Term(field, "*g?")),
+ new WildcardQuery(new Term(field, "*f?1"))
+ },
+ new[]
+ {
+ new WildcardQuery(new Term(field, "*h*")), // these should find only doc 1
+ new WildcardQuery(new Term(field, "*hi*")),
+ new WildcardQuery(new Term(field, "*hij**")),
+ new WildcardQuery(new Term(field, "hi*k*")),
+ new WildcardQuery(new Term(field, "*n?")),
+ new WildcardQuery(new Term(field, "*m?1")),
+ new WildcardQuery(new Term(field, "hij**"))
+ },
+ new[]
+ {
+ new WildcardQuery(new Term(field, "*o*")), // these should find only doc 2
+ new WildcardQuery(new Term(field, "*op*")),
+ new WildcardQuery(new Term(field, "*opq**")),
+ new WildcardQuery(new Term(field, "op*q*")),
+ new WildcardQuery(new Term(field, "*u?")),
+ new WildcardQuery(new Term(field, "*t?1")),
+ new WildcardQuery(new Term(field, "opq**"))
+ }
+ };
// prepare the index
Directory dir = NewDirectory();
- RandomIndexWriter iw = new RandomIndexWriter(Random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMergePolicy(NewLogMergePolicy()));
+ RandomIndexWriter iw = new RandomIndexWriter(Random, dir,
+ NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetMergePolicy(NewLogMergePolicy()));
for (int i = 0; i < docs.Length; i++)
{
Document doc = new Document();
@@ -373,4 +446,4 @@ public virtual void TestParsingAndSearching()
dir.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Search/TestWildcardRandom.cs b/src/Lucene.Net.Tests/Search/TestWildcardRandom.cs
index bd23d1cb2e..61d7b552df 100644
--- a/src/Lucene.Net.Tests/Search/TestWildcardRandom.cs
+++ b/src/Lucene.Net.Tests/Search/TestWildcardRandom.cs
@@ -1,7 +1,6 @@
using Lucene.Net.Documents;
using Lucene.Net.Index.Extensions;
using NUnit.Framework;
-using System;
using System.Text;
using Assert = Lucene.Net.TestFramework.Assert;
using Console = Lucene.Net.Util.SystemConsole;
@@ -53,7 +52,9 @@ public override void SetUp()
{
base.SetUp();
dir = NewDirectory();
- RandomIndexWriter writer = new RandomIndexWriter(Random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(TestUtil.NextInt32(Random, 50, 1000)));
+ RandomIndexWriter writer = new RandomIndexWriter(Random, dir,
+ NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetMaxBufferedDocs(TestUtil.NextInt32(Random, 50, 1000)));
Document doc = new Document();
Field field = NewStringField("field", "", Field.Store.NO);
@@ -157,4 +158,4 @@ public virtual void TestWildcards()
}
}
}
-}
\ No newline at end of file
+}