pq =
new PriorityQueue<>(Math.min(topN, counts.length + hashCounts.size())) {
@Override
@@ -434,7 +425,20 @@ public class LongValueFacetCounts extends Facets {
return new FacetResult(field, new String[0], totCount, results, childCount);
}
- /** Returns all unique values seen, sorted by value. */
+ /** Reusable hash entry to hold long facet value and int count. */
+ private static class Entry {
+ int count;
+ long value;
+ }
+
+ /**
+ * Returns all unique values seen, sorted by value. This functionality is very similar to {@link
+ * #getAllChildren(String, String...)}, but it guarantees the returned values will be sorted by
+ * value (while {@code #getAllChildren} doesn't guarantee any sort order).
+ *
+ * Note: If you don't care about the order of children returned, it may be slightly more
+ * efficient to use {@link #getAllChildren(String, String...)}.
+ */
public FacetResult getAllChildrenSortByValue() {
List labelValues = new ArrayList<>();
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
index b68c3e14c73..58c232c8c6e 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestLongValueFacetCounts.java
@@ -399,7 +399,7 @@ public class TestLongValueFacetCounts extends FacetTestCase {
if (VERBOSE) {
System.out.println(" topN=" + topN);
}
- actual = facetCounts.getTopChildrenSortByCount(topN);
+ actual = facetCounts.getTopChildren(topN, "field");
assertSame(
"all docs, sort facets by count",
expectedCounts,
@@ -488,7 +488,7 @@ public class TestLongValueFacetCounts extends FacetTestCase {
} else {
topN = random().nextInt(docCount);
}
- actual = facetCounts.getTopChildrenSortByCount(topN);
+ actual = facetCounts.getTopChildren(topN, "field");
assertSame(
"id " + minId + "-" + maxId + ", sort facets by count",
expectedCounts,
@@ -662,7 +662,7 @@ public class TestLongValueFacetCounts extends FacetTestCase {
if (VERBOSE) {
System.out.println(" topN=" + topN);
}
- actual = facetCounts.getTopChildrenSortByCount(topN);
+ actual = facetCounts.getTopChildren(topN, "field");
assertSame(
"all docs, sort facets by count",
expectedCounts,
@@ -729,7 +729,7 @@ public class TestLongValueFacetCounts extends FacetTestCase {
} else {
topN = random().nextInt(docCount);
}
- actual = facetCounts.getTopChildrenSortByCount(topN);
+ actual = facetCounts.getTopChildren(topN, "field");
assertSame(
"id " + minId + "-" + maxId + ", sort facets by count",
expectedCounts,