// Writes facet ords to a separate directory from the main index
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
// Reused across documents, to add the necessary facet fields
FacetFields facetFields = new AssociationsFacetFields(taxoWriter);
for (int i = 0; i < CATEGORIES.length; i++) {
Document doc = new Document();
CategoryAssociationsContainer associations = new CategoryAssociationsContainer();
for (int j = 0; j < CATEGORIES[i].length; j++) {
associations.setAssociation(CATEGORIES[i][j], ASSOCIATIONS[i][j]);
}
facetFields.addFields(doc, associations);
indexWriter.addDocument(doc);
}
indexWriter.close();
taxoWriter.close();