public virtual void TestAddIndexes() { Directory d1 = NewDirectory(); RandomIndexWriter w = new RandomIndexWriter( #if FEATURE_INSTANCE_TESTDATA_INITIALIZATION this, #endif Random, d1); Document doc = new Document(); doc.Add(NewStringField("id", "1", Field.Store.YES)); doc.Add(new NumericDocValuesField("dv", 1)); w.AddDocument(doc); IndexReader r1 = w.GetReader(); w.Dispose(); Directory d2 = NewDirectory(); w = new RandomIndexWriter( #if FEATURE_INSTANCE_TESTDATA_INITIALIZATION this, #endif Random, d2); doc = new Document(); doc.Add(NewStringField("id", "2", Field.Store.YES)); doc.Add(new NumericDocValuesField("dv", 2)); w.AddDocument(doc); IndexReader r2 = w.GetReader(); w.Dispose(); Directory d3 = NewDirectory(); w = new RandomIndexWriter( #if FEATURE_INSTANCE_TESTDATA_INITIALIZATION this, #endif Random, d3); w.AddIndexes(SlowCompositeReaderWrapper.Wrap(r1), SlowCompositeReaderWrapper.Wrap(r2)); r1.Dispose(); d1.Dispose(); r2.Dispose(); d2.Dispose(); w.ForceMerge(1); DirectoryReader r3 = w.GetReader(); w.Dispose(); AtomicReader sr = GetOnlySegmentReader(r3); Assert.AreEqual(2, sr.NumDocs); NumericDocValues docValues = sr.GetNumericDocValues("dv"); Assert.IsNotNull(docValues); r3.Dispose(); d3.Dispose(); }
public virtual void TestAddIndexes() { Directory d1 = NewDirectory(); RandomIndexWriter w = new RandomIndexWriter(Random(), d1, Similarity, TimeZone); Document doc = new Document(); doc.Add(NewStringField("id", "1", Field.Store.YES)); doc.Add(new NumericDocValuesField("dv", 1)); w.AddDocument(doc); IndexReader r1 = w.Reader; w.Dispose(); Directory d2 = NewDirectory(); w = new RandomIndexWriter(Random(), d2, Similarity, TimeZone); doc = new Document(); doc.Add(NewStringField("id", "2", Field.Store.YES)); doc.Add(new NumericDocValuesField("dv", 2)); w.AddDocument(doc); IndexReader r2 = w.Reader; w.Dispose(); Directory d3 = NewDirectory(); w = new RandomIndexWriter(Random(), d3, Similarity, TimeZone); w.AddIndexes(SlowCompositeReaderWrapper.Wrap(r1), SlowCompositeReaderWrapper.Wrap(r2)); r1.Dispose(); d1.Dispose(); r2.Dispose(); d2.Dispose(); w.ForceMerge(1); DirectoryReader r3 = w.Reader; w.Dispose(); AtomicReader sr = GetOnlySegmentReader(r3); Assert.AreEqual(2, sr.NumDocs); NumericDocValues docValues = sr.GetNumericDocValues("dv"); Assert.IsNotNull(docValues); r3.Dispose(); d3.Dispose(); }
public virtual void TestMergeStability() { Directory dir = NewDirectory(); // do not use newMergePolicy that might return a MockMergePolicy that ignores the no-CFS ratio MergePolicy mp = NewTieredMergePolicy(); mp.NoCFSRatio = 0; var cfg = (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetUseCompoundFile(false).SetMergePolicy(mp); using (var w = new RandomIndexWriter(Random(), dir, cfg)) { var numDocs = AtLeast(500); for (var i = 0; i < numDocs; ++i) { var d = new Document(); AddRandomFields(d); w.AddDocument(d); } w.ForceMerge(1); w.Commit(); } IndexReader reader = DirectoryReader.Open(dir); Directory dir2 = NewDirectory(); mp = NewTieredMergePolicy(); mp.NoCFSRatio = 0; cfg = (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetUseCompoundFile(false).SetMergePolicy(mp); using (var w = new RandomIndexWriter(Random(), dir2, cfg)) { w.AddIndexes(reader); w.Commit(); } assertEquals(BytesUsedByExtension(dir), BytesUsedByExtension(dir2)); reader.Dispose(); dir.Dispose(); dir2.Dispose(); }
public virtual void TestMergeStability() { using Directory dir = NewDirectory(); // do not use newMergePolicy that might return a MockMergePolicy that ignores the no-CFS ratio MergePolicy mp = NewTieredMergePolicy(); mp.NoCFSRatio = 0; var cfg = (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))).SetUseCompoundFile(false).SetMergePolicy(mp); using (var w = new RandomIndexWriter(Random, dir, cfg)) { var numDocs = AtLeast(500); for (var i = 0; i < numDocs; ++i) { var d = new Document(); AddRandomFields(d); w.AddDocument(d); } w.ForceMerge(1); w.Commit(); } using IndexReader reader = DirectoryReader.Open(dir); using Directory dir2 = NewDirectory(); mp = NewTieredMergePolicy(); mp.NoCFSRatio = 0; cfg = (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))).SetUseCompoundFile(false).SetMergePolicy(mp); using (var w = new RandomIndexWriter(Random, dir2, cfg)) { w.AddIndexes(reader); w.Commit(); } // LUCENENET: We need to explicitly call Equals() and use HashMap in order to ensure our // equality check is done correctly. Calling Assert.AreEqual doesn't guarantee this is done. Assert.True(BytesUsedByExtension(dir).Equals(BytesUsedByExtension(dir2))); }