use of org.apache.lucene.index.IndexWriterConfig.OpenMode in project lucene-solr by apache.
the class TestDirectoryTaxonomyReader method testOpenIfChangedManySegments.
@Test
public void testOpenIfChangedManySegments() throws Exception {
// test openIfChanged() when the taxonomy contains many segments
Directory dir = newDirectory();
DirectoryTaxonomyWriter writer = new DirectoryTaxonomyWriter(dir) {
@Override
protected IndexWriterConfig createIndexWriterConfig(OpenMode openMode) {
IndexWriterConfig conf = super.createIndexWriterConfig(openMode);
LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();
lmp.setMergeFactor(2);
return conf;
}
};
TaxonomyReader reader = new DirectoryTaxonomyReader(writer);
int numRounds = random().nextInt(10) + 10;
// one for root
int numCategories = 1;
for (int i = 0; i < numRounds; i++) {
int numCats = random().nextInt(4) + 1;
for (int j = 0; j < numCats; j++) {
writer.addCategory(new FacetLabel(Integer.toString(i), Integer.toString(j)));
}
numCategories += numCats + 1;
TaxonomyReader newtr = TaxonomyReader.openIfChanged(reader);
assertNotNull(newtr);
reader.close();
reader = newtr;
// assert categories
assertEquals(numCategories, reader.getSize());
int roundOrdinal = reader.getOrdinal(new FacetLabel(Integer.toString(i)));
int[] parents = reader.getParallelTaxonomyArrays().parents();
// round's parent is root
assertEquals(0, parents[roundOrdinal]);
for (int j = 0; j < numCats; j++) {
int ord = reader.getOrdinal(new FacetLabel(Integer.toString(i), Integer.toString(j)));
// round's parent is root
assertEquals(roundOrdinal, parents[ord]);
}
}
reader.close();
writer.close();
dir.close();
}
use of org.apache.lucene.index.IndexWriterConfig.OpenMode in project lucene-solr by apache.
the class TestIndexWriterOnOldIndex method testOpenModeAndCreatedVersion.
public void testOpenModeAndCreatedVersion() throws IOException {
InputStream resource = getClass().getResourceAsStream("index.single-empty-doc.630.zip");
assertNotNull(resource);
Path path = createTempDir();
TestUtil.unzip(resource, path);
Directory dir = newFSDirectory(path);
for (OpenMode openMode : OpenMode.values()) {
Directory tmpDir = newDirectory(dir);
assertEquals(6, /** 6.3.0 */
SegmentInfos.readLatestCommit(tmpDir).getIndexCreatedVersionMajor());
IndexWriter w = new IndexWriter(tmpDir, newIndexWriterConfig().setOpenMode(openMode));
w.commit();
w.close();
switch(openMode) {
case CREATE:
assertEquals(Version.LATEST.major, SegmentInfos.readLatestCommit(tmpDir).getIndexCreatedVersionMajor());
break;
default:
assertEquals(6, /** 6.3.0 */
SegmentInfos.readLatestCommit(tmpDir).getIndexCreatedVersionMajor());
}
tmpDir.close();
}
dir.close();
}
Aggregations