e the old taxonomy with the new one. OrdinalMap map = LuceneTaxonomyWriter.addTaxonomies(); int[] ordmap = map.getMap(); // re-map the ordinals on the old directory. Directory oldDir; FacetsPayloadProcessorProvider fppp = new FacetsPayloadProcessorProvider( oldDir, ordmap); IndexWriterConfig conf = new IndexWriterConfig(VER, ANALYZER); conf.setMergePolicy(new ForceOptimizeMergePolicy()); IndexWriter writer = new IndexWriter(oldDir, conf); writer.setPayloadProcessorProvider(fppp); writer.optimize(); writer.close(); // merge that directory with the new index. IndexWriter newWriter; // opened on the 'new' Directory newWriter.addIndexes(oldDir); newWriter.commit(); For re-mapping the ordinals during index merge, do the following:
// merge the old taxonomy with the new one. OrdinalMap map = LuceneTaxonomyWriter.addTaxonomies(); int[] ordmap = map.getMap(); // Add the index and re-map ordinals on the go IndexReader r = IndexReader.open(oldDir); IndexWriterConfig conf = new IndexWriterConfig(VER, ANALYZER); IndexWriter writer = new IndexWriter(newDir, conf); writer.setPayloadProcessorProvider(fppp); writer.addIndexes(r); writer.commit();
NOTE: while the second example looks simpler, IndexWriter may trigger a long merge due to addIndexes. The first example avoids this perhaps unneeded merge, as well as can be done separately (e.g. on another node) before the index is merged.
@lucene.experimental