@Test
public void testCreateIndex() throws IOException {
long s = System.nanoTime();
IndexWriterConfig conf = new IndexWriterConfig(LuceneVersionConstant.LUCENE_VERSION, new KeywordAnalyzer());
IndexDeletionPolicyReader indexDeletionPolicy = new IndexDeletionPolicyReader(
new KeepOnlyLastCommitDeletionPolicy());
conf.setIndexDeletionPolicy(indexDeletionPolicy);
FSDirectory control = FSDirectory.open(fileControl);
Directory dir = getControlDir(control, directory);
// The serial merge scheduler can be useful for debugging.
// conf.setMergeScheduler(new SerialMergeScheduler());
IndexWriter writer = new IndexWriter(dir, conf);
int numDocs = 10000;
DirectoryReader reader = null;
long gen = 0;
for (int i = 0; i < 100; i++) {
if (reader == null) {
reader = DirectoryReader.open(writer, true);
gen = reader.getIndexCommit().getGeneration();
indexDeletionPolicy.register(gen);
} else {
DirectoryReader old = reader;
reader = DirectoryReader.openIfChanged(old, writer, true);
if (reader == null) {
reader = old;
} else {
long newGen = reader.getIndexCommit().getGeneration();
indexDeletionPolicy.register(newGen);
indexDeletionPolicy.unregister(gen);
old.close();
gen = newGen;
}
}
assertEquals(i * numDocs, reader.numDocs());