CountingFacetsCollector did not sort the nodes when FacetRequest.getNumResults was > taxoReader.getSize()

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1437867 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2013-01-24 06:35:09 +00:00
parent ee97b7a489
commit 956d884778
2 changed files with 21 additions and 0 deletions

View File

@ -3,6 +3,8 @@ package org.apache.lucene.facet.search;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
@ -265,6 +267,17 @@ public class CountingFacetsCollector extends FacetsCollector {
}
child = siblings[child];
}
Collections.sort(nodes, new Comparator<FacetResultNode>() {
@Override
public int compare(FacetResultNode o1, FacetResultNode o2) {
int value = (int) (o2.value - o1.value);
if (value == 0) {
value = o2.ordinal - o1.ordinal;
}
return value;
}
});
root.subResults = nodes;
res.add(new FacetResult(fr, root, nodes.size()));
continue;

View File

@ -351,8 +351,16 @@ public class CountingFacetsCollectorTest extends LuceneTestCase {
for (FacetResult res : facetResults) {
FacetResultNode root = res.getFacetResultNode();
assertEquals("wrong count for " + root.label, allExpectedCounts.get(root.label), (int) root.value);
int prevValue = Integer.MAX_VALUE;
int prevOrdinal = Integer.MAX_VALUE;
for (FacetResultNode child : root.subResults) {
assertEquals("wrong count for " + child.label, allExpectedCounts.get(child.label), (int) child.value);
assertTrue("wrong sort order of sub results: child.value=" + child.value + " prevValue=" + prevValue, child.value <= prevValue);
if (child.value == prevValue) {
assertTrue("wrong sort order of sub results", child.ordinal < prevOrdinal);
}
prevValue = (int) child.value;
prevOrdinal = child.ordinal;
}
}