RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
// Use a custom delim char to make sure the impls
// respect it:
final char delim = ':';
FacetIndexingParams fip = new FacetIndexingParams() {
@Override
public char getFacetDelimChar() {
return delim;
}
};
SortedSetDocValuesFacetFields dvFields = new SortedSetDocValuesFacetFields(fip);
Document doc = new Document();
// Mixup order we add these paths, to verify tie-break
// order is by label (unicode sort) and has nothing to
// do w/ order we added them:
List<CategoryPath> paths = new ArrayList<CategoryPath>();
paths.add(new CategoryPath("a", "foo"));
paths.add(new CategoryPath("a", "bar"));
paths.add(new CategoryPath("a", "zoo"));
Collections.shuffle(paths, random());
paths.add(new CategoryPath("b", "baz"));
paths.add(new CategoryPath("b" + FacetIndexingParams.DEFAULT_FACET_DELIM_CHAR, "bazfoo"));
dvFields.addFields(doc, paths);
writer.addDocument(doc);
if (random().nextBoolean()) {
writer.commit();
}
doc = new Document();
dvFields.addFields(doc, Collections.singletonList(new CategoryPath("a", "foo")));
writer.addDocument(doc);
// NRT open
IndexSearcher searcher = newSearcher(writer.getReader());
writer.close();
List<FacetRequest> requests = new ArrayList<FacetRequest>();
requests.add(new CountFacetRequest(new CategoryPath("a"), 10));
requests.add(new CountFacetRequest(new CategoryPath("b"), 10));
requests.add(new CountFacetRequest(new CategoryPath("b" + FacetIndexingParams.DEFAULT_FACET_DELIM_CHAR), 10));
final boolean doDimCount = random().nextBoolean();
CategoryListParams clp = new CategoryListParams() {
@Override
public OrdinalPolicy getOrdinalPolicy(String dimension) {
return doDimCount ? OrdinalPolicy.NO_PARENTS : OrdinalPolicy.ALL_BUT_DIMENSION;
}
};
FacetSearchParams fsp = new FacetSearchParams(new FacetIndexingParams(clp), requests);
// Per-top-reader state:
SortedSetDocValuesReaderState state = new SortedSetDocValuesReaderState(fip, searcher.getIndexReader());
//SortedSetDocValuesCollector c = new SortedSetDocValuesCollector(state);