Skip to content

Commit

Permalink
Test review of TestSegmentTermDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin committed Mar 10, 2024
1 parent 7498e9e commit ccbb96e
Showing 1 changed file with 50 additions and 11 deletions.
61 changes: 50 additions & 11 deletions src/Lucene.Net.Tests/Index/TestSegmentTermDocs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ namespace Lucene.Net.Index
[TestFixture]
public class TestSegmentTermDocs : LuceneTestCase
{
private Document testDoc;
private Document testDoc = new Document();
private Directory dir;
private SegmentCommitInfo info;

[SetUp]
public override void SetUp()
{
base.SetUp();
testDoc = new Document();
dir = NewDirectory();
DocHelper.SetupDoc(testDoc);
info = DocHelper.WriteDoc(Random, dir, testDoc);
Expand Down Expand Up @@ -99,7 +98,12 @@ public virtual void TestBadSeek(int indexDivisor)
//After adding the document, we should be able to read it back in
SegmentReader reader = new SegmentReader(info, indexDivisor, NewIOContext(Random));
Assert.IsTrue(reader != null);
DocsEnum termDocs = TestUtil.Docs(Random, reader, "textField2", new BytesRef("bad"), reader.LiveDocs, null, 0);
DocsEnum termDocs = TestUtil.Docs(Random, reader,
"textField2",
new BytesRef("bad"),
reader.LiveDocs,
null,
0);

Assert.IsNull(termDocs);
reader.Dispose();
Expand All @@ -108,7 +112,12 @@ public virtual void TestBadSeek(int indexDivisor)
//After adding the document, we should be able to read it back in
SegmentReader reader = new SegmentReader(info, indexDivisor, NewIOContext(Random));
Assert.IsTrue(reader != null);
DocsEnum termDocs = TestUtil.Docs(Random, reader, "junk", new BytesRef("bad"), reader.LiveDocs, null, 0);
DocsEnum termDocs = TestUtil.Docs(Random, reader,
"junk",
new BytesRef("bad"),
reader.LiveDocs,
null,
0);
Assert.IsNull(termDocs);
reader.Dispose();
}
Expand Down Expand Up @@ -149,7 +158,12 @@ public virtual void TestSkipTo(int indexDivisor)

IndexReader reader = DirectoryReader.Open(dir, indexDivisor);

DocsEnum tdocs = TestUtil.Docs(Random, reader, ta.Field, new BytesRef(ta.Text), MultiFields.GetLiveDocs(reader), null, DocsFlags.FREQS);
DocsEnum tdocs = TestUtil.Docs(Random, reader,
ta.Field,
new BytesRef(ta.Text),
MultiFields.GetLiveDocs(reader),
null,
DocsFlags.FREQS);

// without optimization (assumption skipInterval == 16)

Expand All @@ -169,7 +183,12 @@ public virtual void TestSkipTo(int indexDivisor)
Assert.IsFalse(tdocs.Advance(10) != DocIdSetIterator.NO_MORE_DOCS);

// without next
tdocs = TestUtil.Docs(Random, reader, ta.Field, new BytesRef(ta.Text), MultiFields.GetLiveDocs(reader), null, 0);
tdocs = TestUtil.Docs(Random, reader,
ta.Field,
new BytesRef(ta.Text),
MultiFields.GetLiveDocs(reader),
null,
0);

Assert.IsTrue(tdocs.Advance(0) != DocIdSetIterator.NO_MORE_DOCS);
Assert.AreEqual(0, tdocs.DocID);
Expand All @@ -182,7 +201,12 @@ public virtual void TestSkipTo(int indexDivisor)
// exactly skipInterval documents and therefore with optimization

// with next
tdocs = TestUtil.Docs(Random, reader, tb.Field, new BytesRef(tb.Text), MultiFields.GetLiveDocs(reader), null, DocsFlags.FREQS);
tdocs = TestUtil.Docs(Random, reader,
tb.Field,
new BytesRef(tb.Text),
MultiFields.GetLiveDocs(reader),
null,
DocsFlags.FREQS);

Assert.IsTrue(tdocs.NextDoc() != DocIdSetIterator.NO_MORE_DOCS);
Assert.AreEqual(10, tdocs.DocID);
Expand All @@ -201,7 +225,12 @@ public virtual void TestSkipTo(int indexDivisor)
Assert.IsFalse(tdocs.Advance(26) != DocIdSetIterator.NO_MORE_DOCS);

// without next
tdocs = TestUtil.Docs(Random, reader, tb.Field, new BytesRef(tb.Text), MultiFields.GetLiveDocs(reader), null, DocsFlags.FREQS);
tdocs = TestUtil.Docs(Random, reader,
tb.Field,
new BytesRef(tb.Text),
MultiFields.GetLiveDocs(reader),
null,
DocsFlags.FREQS);

Assert.IsTrue(tdocs.Advance(5) != DocIdSetIterator.NO_MORE_DOCS);
Assert.AreEqual(10, tdocs.DocID);
Expand All @@ -216,7 +245,12 @@ public virtual void TestSkipTo(int indexDivisor)
// much more than skipInterval documents and therefore with optimization

// with next
tdocs = TestUtil.Docs(Random, reader, tc.Field, new BytesRef(tc.Text), MultiFields.GetLiveDocs(reader), null, DocsFlags.FREQS);
tdocs = TestUtil.Docs(Random, reader,
tc.Field,
new BytesRef(tc.Text),
MultiFields.GetLiveDocs(reader),
null,
DocsFlags.FREQS);

Assert.IsTrue(tdocs.NextDoc() != DocIdSetIterator.NO_MORE_DOCS);
Assert.AreEqual(26, tdocs.DocID);
Expand All @@ -237,7 +271,12 @@ public virtual void TestSkipTo(int indexDivisor)
Assert.IsFalse(tdocs.Advance(76) != DocIdSetIterator.NO_MORE_DOCS);

//without next
tdocs = TestUtil.Docs(Random, reader, tc.Field, new BytesRef(tc.Text), MultiFields.GetLiveDocs(reader), null, 0);
tdocs = TestUtil.Docs(Random, reader,
tc.Field,
new BytesRef(tc.Text),
MultiFields.GetLiveDocs(reader),
null,
0);
Assert.IsTrue(tdocs.Advance(5) != DocIdSetIterator.NO_MORE_DOCS);
Assert.AreEqual(26, tdocs.DocID);
Assert.IsTrue(tdocs.Advance(40) != DocIdSetIterator.NO_MORE_DOCS);
Expand Down Expand Up @@ -272,4 +311,4 @@ private void AddDoc(IndexWriter writer, string value)
writer.AddDocument(doc);
}
}
}
}

0 comments on commit ccbb96e

Please sign in to comment.