facetRequests.add(doctor);
facetRequests.add(cfrb20);
FacetSearchParams facetSearchParams = new FacetSearchParams(iParams, facetRequests);
FacetArrays facetArrays = new FacetArrays(PartitionsUtils.partitionSize(facetSearchParams.indexingParams, tr));
OldFacetsAccumulator sfa = new OldFacetsAccumulator(facetSearchParams, is.getIndexReader(), tr, facetArrays);
sfa.setComplementThreshold(OldFacetsAccumulator.DISABLE_COMPLEMENT);
FacetsCollector fc = FacetsCollector.create(sfa);
is.search(q, fc);
List<FacetResult> facetResults = fc.getFacetResults();
FacetResult fr = facetResults.get(0); // a, depth=3, K=2
boolean hasDoctor = "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
assertEquals(9, fr.getNumValidDescendants());
FacetResultNode parentRes = fr.getFacetResultNode();
assertEquals(2, parentRes.subResults.size());
// two nodes sorted by descending values: a/b with 8 and a/c with 6
// a/b has two children a/b/2 with value 3, and a/b/1 with value 2.
// a/c has one child a/c/1 with value 1.
double [] expectedValues0 = { 8.0, 3.0, 2.0, 6.0, 1.0 };
int i = 0;
for (FacetResultNode node : parentRes.subResults) {
assertEquals(expectedValues0[i++], node.value, Double.MIN_VALUE);
for (FacetResultNode node2 : node.subResults) {
assertEquals(expectedValues0[i++], node2.value, Double.MIN_VALUE);
}
}
// now just change the value of the first child of the root to 5, and then rearrange
// expected are: first a/c of value 6, and one child a/c/1 with value 1
// then a/b with value 5, and both children: a/b/2 with value 3, and a/b/1 with value 2.
for (FacetResultNode node : parentRes.subResults) {
node.value = 5.0;
break;
}
// now rearrange
double [] expectedValues00 = { 6.0, 1.0, 5.0, 3.0, 2.0 };
fr = sfa.createFacetResultsHandler(cfra23, sfa.createOrdinalValueResolver(cfra23)).rearrangeFacetResult(fr);
i = 0;
for (FacetResultNode node : parentRes.subResults) {
assertEquals(expectedValues00[i++], node.value, Double.MIN_VALUE);
for (FacetResultNode node2 : node.subResults) {
assertEquals(expectedValues00[i++], node2.value, Double.MIN_VALUE);