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

TestUpdateSegmentWithPostingButNoDocValues() private method

private TestUpdateSegmentWithPostingButNoDocValues ( ) : void
return void
        public virtual void TestUpdateSegmentWithPostingButNoDocValues()
        {
            Directory dir = NewDirectory();
            IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
            // prevent merges, otherwise by the time updates are applied
            // (writer.Dispose()), the segments might have merged and that update becomes
            // legit.
            conf.SetMergePolicy(NoMergePolicy.COMPOUND_FILES);
            IndexWriter writer = new IndexWriter(dir, conf);

            // first segment with BDV
            Document doc = new Document();
            doc.Add(new StringField("id", "doc0", Store.NO));
            doc.Add(new StringField("bdv", "mock-value", Store.NO));
            doc.Add(new BinaryDocValuesField("bdv", ToBytes(5L)));
            writer.AddDocument(doc);
            writer.Commit();

            // second segment with no BDV
            doc = new Document();
            doc.Add(new StringField("id", "doc1", Store.NO));
            doc.Add(new StringField("bdv", "mock-value", Store.NO));
            writer.AddDocument(doc);
            writer.Commit();

            // update document in the second segment
            writer.UpdateBinaryDocValue(new Term("id", "doc1"), "bdv", ToBytes(5L));
            writer.Dispose();

            DirectoryReader reader = DirectoryReader.Open(dir);
            BytesRef scratch = new BytesRef();
            foreach (AtomicReaderContext context in reader.Leaves)
            {
                AtomicReader r = context.AtomicReader;
                BinaryDocValues bdv = r.GetBinaryDocValues("bdv");
                for (int i = 0; i < r.MaxDoc; i++)
                {
                    Assert.AreEqual(5L, GetValue(bdv, i, scratch));
                }
            }
            reader.Dispose();

            dir.Dispose();
        }