public void test() throws Exception {
Directory dir = newDirectory();
Directory taxoDir = newDirectory();
final IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
final DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir);
final FacetFields facetFields = new FacetFields(tw);
final AtomicBoolean stop = new AtomicBoolean();
// How many unique facets to index before stopping:
final int ordLimit = TEST_NIGHTLY ? 100000 : 6000;
Thread indexer = new Thread() {
@Override
public void run() {
try {
Set<String> seen = new HashSet<String>();
List<String> paths = new ArrayList<String>();
while (true) {
Document doc = new Document();
List<CategoryPath> docPaths = new ArrayList<CategoryPath>();
int numPaths = _TestUtil.nextInt(random(), 1, 5);
for(int i=0;i<numPaths;i++) {
String path;
if (!paths.isEmpty() && random().nextInt(5) != 4) {
// Use previous path
path = paths.get(random().nextInt(paths.size()));
} else {
// Create new path
path = null;
while (true) {
path = _TestUtil.randomRealisticUnicodeString(random());
if (path.length() != 0 && !seen.contains(path) && path.indexOf(FacetIndexingParams.DEFAULT_FACET_DELIM_CHAR) == -1) {
seen.add(path);
paths.add(path);
break;
}
}
}
docPaths.add(new CategoryPath("field", path));
}
try {
facetFields.addFields(doc, docPaths);
w.addDocument(doc);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}