Lucene.Net.Index.TestBinaryDocValuesUpdates.TestDocumentWithNoValue C# (CSharp) Method

TestDocumentWithNoValue() private method

private TestDocumentWithNoValue ( ) : void
return void
        public virtual void TestDocumentWithNoValue()
        {
            Directory dir = NewDirectory();
            IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
            IndexWriter writer = new IndexWriter(dir, conf);

            for (int i = 0; i < 2; i++)
            {
                Document doc = new Document();
                doc.Add(new StringField("dvUpdateKey", "dv", Store.NO));
                if (i == 0) // index only one document with value
                {
                    doc.Add(new BinaryDocValuesField("bdv", ToBytes(5L)));
                }
                writer.AddDocument(doc);
            }
            writer.Commit();

            // update all docs' bdv field
            writer.UpdateBinaryDocValue(new Term("dvUpdateKey", "dv"), "bdv", ToBytes(17L));
            writer.Dispose();

            DirectoryReader reader = DirectoryReader.Open(dir);
            AtomicReader r = (AtomicReader)reader.Leaves[0].Reader;
            BinaryDocValues bdv = r.GetBinaryDocValues("bdv");
            BytesRef scratch = new BytesRef();
            for (int i = 0; i < r.MaxDoc; i++)
            {
                Assert.AreEqual(17, GetValue(bdv, i, scratch));
            }

            reader.Dispose();
            dir.Dispose();
        }