Random r = random();
RandomIndexWriter writer = new RandomIndexWriter(r, dir,
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(r, MockTokenizer.KEYWORD, false)));
taxoDir = newDirectory();
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
for (int i = 0; i < 100; i++) {
ArrayList<CategoryPath> paths = new ArrayList<CategoryPath>();
Document doc = new Document();
if (i % 2 == 0) { // 50
doc.add(new TextField("content", "foo", Field.Store.NO));
}
if (i % 3 == 0) { // 33
doc.add(new TextField("content", "bar", Field.Store.NO));
}
if (i % 4 == 0) { // 25
if (r.nextBoolean()) {
paths.add(new CategoryPath("a/1", '/'));
} else {
paths.add(new CategoryPath("a/2", '/'));
}
}
if (i % 5 == 0) { // 20
paths.add(new CategoryPath("b"));
}
FacetFields facetFields = new FacetFields(taxoWriter);
if (paths.size() > 0) {
facetFields.addFields(doc, paths);
}
writer.addDocument(doc);
}
taxoWriter.close();
reader = writer.getReader();
writer.close();
taxo = new DirectoryTaxonomyReader(taxoDir);
}