Skip to content

Commit

Permalink
Search/TestD-TestE code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin committed Jan 23, 2024
1 parent bd1b355 commit a6da17e
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 102 deletions.
2 changes: 2 additions & 0 deletions Lucene.Net.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Coord/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
7 changes: 1 addition & 6 deletions src/Lucene.Net.Tests/Search/TestDateFilter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Lucene.Net.Attributes;
using Lucene.Net.Documents;
using NUnit.Framework;
using System;
using Assert = Lucene.Net.TestFramework.Assert;

namespace Lucene.Net.Search
Expand Down Expand Up @@ -34,13 +33,10 @@ namespace Lucene.Net.Search

/// <summary>
/// DateFilter JUnit tests.
///
///
/// </summary>
[TestFixture]
public class TestDateFilter : LuceneTestCase
{
///
[OneTimeSetUp]
public override void BeforeClass() // LUCENENET specific - renamed from TestBefore() to ensure calling order vs base class
{
Expand Down Expand Up @@ -106,7 +102,6 @@ public void Test()
// noop, required for the before and after tests to run
}

///
[OneTimeTearDown]
public override void AfterClass() // LUCENENET specific - renamed from TestAfter() to ensure calling order vs base class
{
Expand Down Expand Up @@ -166,4 +161,4 @@ public override void AfterClass() // LUCENENET specific - renamed from TestAfter
base.AfterClass();
}
}
}
}
8 changes: 4 additions & 4 deletions src/Lucene.Net.Tests/Search/TestDisjunctionMaxQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class TestDisjunctionMaxQuery : LuceneTestCase
{
/// <summary>
/// threshold for comparing floats </summary>
public static readonly float SCORE_COMP_THRESH = 0.0000f;
public const float SCORE_COMP_THRESH = 0.0000f;

/// <summary>
/// Similarity to eliminate tf, idf and lengthNorm effects to isolate test
Expand Down Expand Up @@ -190,7 +190,7 @@ public virtual void TestSkipToFirsttimeMiss()
Assert.IsTrue(s.TopReaderContext is AtomicReaderContext);
Weight dw = s.CreateNormalizedWeight(dq);
AtomicReaderContext context = (AtomicReaderContext)s.TopReaderContext;
Scorer ds = dw.GetScorer(context, (context.AtomicReader).LiveDocs);
Scorer ds = dw.GetScorer(context, context.AtomicReader.LiveDocs);
bool skipOk = ds.Advance(3) != DocIdSetIterator.NO_MORE_DOCS;
if (skipOk)
{
Expand All @@ -208,7 +208,7 @@ public virtual void TestSkipToFirsttimeHit()
QueryUtils.Check(Random, dq, s);
Weight dw = s.CreateNormalizedWeight(dq);
AtomicReaderContext context = (AtomicReaderContext)s.TopReaderContext;
Scorer ds = dw.GetScorer(context, (context.AtomicReader).LiveDocs);
Scorer ds = dw.GetScorer(context, context.AtomicReader.LiveDocs);
Assert.IsTrue(ds.Advance(3) != DocIdSetIterator.NO_MORE_DOCS, "firsttime skipTo found no match");
Assert.AreEqual("d4", r.Document(ds.DocID).Get("id"), "found wrong docid");
}
Expand Down Expand Up @@ -568,4 +568,4 @@ protected internal virtual void PrintHits(string test, ScoreDoc[] h, IndexSearch
}
}
}
}
}
17 changes: 7 additions & 10 deletions src/Lucene.Net.Tests/Search/TestDocBoost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ namespace Lucene.Net.Search

/// <summary>
/// Document boost unit test.
///
///
/// </summary>
[TestFixture]
public class TestDocBoost : LuceneTestCase
Expand All @@ -49,8 +47,8 @@ public virtual void TestDocBoost_Mem()
Field f2 = NewTextField("field", "word", Field.Store.YES);
f2.Boost = 2.0f;

Documents.Document d1 = new Documents.Document();
Documents.Document d2 = new Documents.Document();
Document d1 = new Document();
Document d2 = new Document();

d1.Add(f1); // boost = 1
d2.Add(f2); // boost = 2
Expand All @@ -64,7 +62,9 @@ public virtual void TestDocBoost_Mem()
float[] scores = new float[4];

IndexSearcher searcher = NewSearcher(reader);
searcher.Search(new TermQuery(new Term("field", "word")), new CollectorAnonymousClass(this, scores));
searcher.Search(
new TermQuery(new Term("field", "word")),
new CollectorAnonymousClass(scores));

float lastScore = 0.0f;

Expand All @@ -84,13 +84,10 @@ public virtual void TestDocBoost_Mem()

private sealed class CollectorAnonymousClass : ICollector
{
private readonly TestDocBoost outerInstance;

private readonly float[] scores;

public CollectorAnonymousClass(TestDocBoost outerInstance, float[] scores)
public CollectorAnonymousClass(float[] scores)
{
this.outerInstance = outerInstance;
this.scores = scores;
@base = 0;
}
Expand All @@ -116,4 +113,4 @@ public void SetNextReader(AtomicReaderContext context)
public bool AcceptsDocsOutOfOrder => true;
}
}
}
}
50 changes: 10 additions & 40 deletions src/Lucene.Net.Tests/Search/TestDocIdSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public class TestDocIdSet : LuceneTestCase
public virtual void TestFilteredDocIdSet()
{
const int maxdoc = 10;
DocIdSet innerSet = new DocIdSetAnonymousClass(this, maxdoc);
DocIdSet innerSet = new DocIdSetAnonymousClass(maxdoc);

DocIdSet filteredSet = new FilteredDocIdSetAnonymousClass(this, innerSet);
DocIdSet filteredSet = new FilteredDocIdSetAnonymousClass(innerSet);

DocIdSetIterator iter = filteredSet.GetIterator();
IList<int> list = new JCG.List<int>();
Expand Down Expand Up @@ -77,13 +77,10 @@ public virtual void TestFilteredDocIdSet()

private sealed class DocIdSetAnonymousClass : DocIdSet
{
private readonly TestDocIdSet outerInstance;

private readonly int maxdoc;

public DocIdSetAnonymousClass(TestDocIdSet outerInstance, int maxdoc)
public DocIdSetAnonymousClass(int maxdoc)
{
this.outerInstance = outerInstance;
this.maxdoc = maxdoc;
}

Expand Down Expand Up @@ -126,12 +123,9 @@ public override long GetCost()

private sealed class FilteredDocIdSetAnonymousClass : FilteredDocIdSet
{
private readonly TestDocIdSet outerInstance;

public FilteredDocIdSetAnonymousClass(TestDocIdSet outerInstance, DocIdSet innerSet)
public FilteredDocIdSetAnonymousClass(DocIdSet innerSet)
: base(innerSet)
{
this.outerInstance = outerInstance;
}

protected override bool Match(int docid)
Expand All @@ -158,7 +152,7 @@ public virtual void TestNullDocIdSet()
Assert.AreEqual(1, searcher.Search(new MatchAllDocsQuery(), 10).TotalHits);

// Now search w/ a Filter which returns a null DocIdSet
Filter f = new FilterAnonymousClass(this);
Filter f = new FilterAnonymousClass();

Assert.AreEqual(0, searcher.Search(new MatchAllDocsQuery(), f, 10).TotalHits);
reader.Dispose();
Expand All @@ -167,13 +161,6 @@ public virtual void TestNullDocIdSet()

private sealed class FilterAnonymousClass : Filter
{
private readonly TestDocIdSet outerInstance;

public FilterAnonymousClass(TestDocIdSet outerInstance)
{
this.outerInstance = outerInstance;
}

public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDocs)
{
return null;
Expand All @@ -196,7 +183,7 @@ public virtual void TestNullIteratorFilteredDocIdSet()
Assert.AreEqual(1, searcher.Search(new MatchAllDocsQuery(), 10).TotalHits);

// Now search w/ a Filter which returns a null DocIdSet
Filter f = new FilterAnonymousClass2(this);
Filter f = new FilterAnonymousClass2();

Assert.AreEqual(0, searcher.Search(new MatchAllDocsQuery(), f, 10).TotalHits);
reader.Dispose();
Expand All @@ -205,28 +192,14 @@ public virtual void TestNullIteratorFilteredDocIdSet()

private sealed class FilterAnonymousClass2 : Filter
{
private readonly TestDocIdSet outerInstance;

public FilterAnonymousClass2(TestDocIdSet outerInstance)
{
this.outerInstance = outerInstance;
}

public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDocs)
{
DocIdSet innerNullIteratorSet = new DocIdSetAnonymousClass2(this);
return new FilteredDocIdSetAnonymousClass2(this, innerNullIteratorSet);
DocIdSet innerNullIteratorSet = new DocIdSetAnonymousClass2();
return new FilteredDocIdSetAnonymousClass2(innerNullIteratorSet);
}

private sealed class DocIdSetAnonymousClass2 : DocIdSet
{
private readonly FilterAnonymousClass2 outerInstance;

public DocIdSetAnonymousClass2(FilterAnonymousClass2 outerInstance)
{
this.outerInstance = outerInstance;
}

public override DocIdSetIterator GetIterator()
{
return null;
Expand All @@ -235,12 +208,9 @@ public override DocIdSetIterator GetIterator()

private sealed class FilteredDocIdSetAnonymousClass2 : FilteredDocIdSet
{
private readonly FilterAnonymousClass2 outerInstance;

public FilteredDocIdSetAnonymousClass2(FilterAnonymousClass2 outerInstance, DocIdSet innerNullIteratorSet)
public FilteredDocIdSetAnonymousClass2(DocIdSet innerNullIteratorSet)
: base(innerNullIteratorSet)
{
this.outerInstance = outerInstance;
}

protected override bool Match(int docid)
Expand All @@ -250,4 +220,4 @@ protected override bool Match(int docid)
}
}
}
}
}
5 changes: 2 additions & 3 deletions src/Lucene.Net.Tests/Search/TestDocTermOrdsRangeFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using NUnit.Framework;
using RandomizedTesting.Generators;
using System;
using System.Collections.Generic;
using JCG = J2N.Collections.Generic;
using Console = Lucene.Net.Util.SystemConsole;

Expand Down Expand Up @@ -140,12 +139,12 @@ protected internal virtual void AssertSame(BytesRef lowerVal, BytesRef upperVal,
{
Query docValues = new ConstantScoreQuery(DocTermOrdsRangeFilter.NewBytesRefRange(fieldName, lowerVal, upperVal, includeLower, includeUpper));
MultiTermQuery inverted = new TermRangeQuery(fieldName, lowerVal, upperVal, includeLower, includeUpper);
inverted.MultiTermRewriteMethod = (MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
inverted.MultiTermRewriteMethod = MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE;

TopDocs invertedDocs = searcher1.Search(inverted, 25);
TopDocs docValuesDocs = searcher2.Search(docValues, 25);

CheckHits.CheckEqual(inverted, invertedDocs.ScoreDocs, docValuesDocs.ScoreDocs);
}
}
}
}
11 changes: 5 additions & 6 deletions src/Lucene.Net.Tests/Search/TestDocTermOrdsRewriteMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using NUnit.Framework;
using RandomizedTesting.Generators;
using System;
using System.Collections.Generic;
using JCG = J2N.Collections.Generic;
using Assert = Lucene.Net.TestFramework.Assert;
using Console = Lucene.Net.Util.SystemConsole;
Expand Down Expand Up @@ -139,7 +138,7 @@ public virtual void TestRegexps()
protected internal virtual void AssertSame(string regexp)
{
RegexpQuery docValues = new RegexpQuery(new Term(fieldName, regexp), RegExpSyntax.NONE);
docValues.MultiTermRewriteMethod = (new DocTermOrdsRewriteMethod());
docValues.MultiTermRewriteMethod = new DocTermOrdsRewriteMethod();
RegexpQuery inverted = new RegexpQuery(new Term(fieldName, regexp), RegExpSyntax.NONE);

TopDocs invertedDocs = searcher1.Search(inverted, 25);
Expand All @@ -157,12 +156,12 @@ public virtual void TestEquals()
Assert.AreEqual(a1, a2);
Assert.IsFalse(a1.Equals(b));

a1.MultiTermRewriteMethod = (new DocTermOrdsRewriteMethod());
a2.MultiTermRewriteMethod = (new DocTermOrdsRewriteMethod());
b.MultiTermRewriteMethod = (new DocTermOrdsRewriteMethod());
a1.MultiTermRewriteMethod = new DocTermOrdsRewriteMethod();
a2.MultiTermRewriteMethod = new DocTermOrdsRewriteMethod();
b.MultiTermRewriteMethod = new DocTermOrdsRewriteMethod();
Assert.AreEqual(a1, a2);
Assert.IsFalse(a1.Equals(b));
QueryUtils.Check(a1);
}
}
}
}
11 changes: 3 additions & 8 deletions src/Lucene.Net.Tests/Search/TestDocValuesScoring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public virtual void TestSimple()
Similarity @base = searcher1.Similarity;
// boosting
IndexSearcher searcher2 = NewSearcher(ir, false);
searcher2.Similarity = new PerFieldSimilarityWrapperAnonymousClass(this, field, @base);
searcher2.Similarity = new PerFieldSimilarityWrapperAnonymousClass(@base);

// in this case, we searched on field "foo". first document should have 2x the score.
TermQuery tq = new TermQuery(new Term("foo", "quick"));
Expand Down Expand Up @@ -123,15 +123,10 @@ public virtual void TestSimple()

private sealed class PerFieldSimilarityWrapperAnonymousClass : PerFieldSimilarityWrapper
{
private readonly TestDocValuesScoring outerInstance;

private Field field;
private Similarity @base;

public PerFieldSimilarityWrapperAnonymousClass(TestDocValuesScoring outerInstance, Field field, Similarity @base)
public PerFieldSimilarityWrapperAnonymousClass(Similarity @base)
{
this.outerInstance = outerInstance;
this.field = field;
this.@base = @base;
fooSim = new BoostingSimilarity(@base, "foo_boost");
}
Expand Down Expand Up @@ -230,4 +225,4 @@ public override Explanation Explain(int doc, Explanation freq)
}
}
}
}
}
17 changes: 4 additions & 13 deletions src/Lucene.Net.Tests/Search/TestEarlyTermination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public virtual void TestEarlyTermination_Mem()
for (int i = 0; i < iters; ++i)
{
IndexSearcher searcher = NewSearcher(reader);
ICollector collector = new CollectorAnonymousClass(this);
ICollector collector = new CollectorAnonymousClass();

searcher.Search(new MatchAllDocsQuery(), collector);
}
Expand All @@ -77,17 +77,8 @@ public virtual void TestEarlyTermination_Mem()

private sealed class CollectorAnonymousClass : ICollector
{
private readonly TestEarlyTermination outerInstance;

public CollectorAnonymousClass(TestEarlyTermination outerInstance)
{
this.outerInstance = outerInstance;
outOfOrder = Random.NextBoolean();
collectionTerminated = true;
}

internal readonly bool outOfOrder;
internal bool collectionTerminated;
internal readonly bool outOfOrder = Random.NextBoolean();
internal bool collectionTerminated = true;

public void SetScorer(Scorer scorer)
{
Expand Down Expand Up @@ -119,4 +110,4 @@ public void SetNextReader(AtomicReaderContext context)
public bool AcceptsDocsOutOfOrder => outOfOrder;
}
}
}
}
Loading

0 comments on commit a6da17e

Please sign in to comment.