RandomIndexWriter writer = new RandomIndexWriter(random, dir, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random, MockTokenizer.KEYWORD, false)));
TaxonomyWriter taxoWriter = new LuceneTaxonomyWriter(taxoDir);
EnhancementsDocumentBuilder builder = new EnhancementsDocumentBuilder(
taxoWriter, new DefaultEnhancementsIndexingParams(
new AssociationEnhancement()));
// index documents, 50% have only 'b' and all have 'a'
for (int i = 0; i < 100; i++) {
Document doc = new Document();
CategoryContainer container = new CategoryContainer();
container.addCategory(aint, new AssociationIntProperty(2));
container.addCategory(afloat, new AssociationFloatProperty(0.5f));
if (i % 2 == 0) { // 50
container.addCategory(bint, new AssociationIntProperty(3));
container.addCategory(bfloat, new AssociationFloatProperty(0.2f));
}
builder.setCategories(container).build(doc);
writer.addDocument(doc);
}
taxoWriter.close();
reader = writer.getReader();