Remove LongValueFacetCounts#getTopChildrenSortByCount since it provides redundant functionality (#11744)

This commit is contained in:
Greg Miller 2023-03-06 12:12:23 -08:00 committed by GitHub
parent c514089d66
commit afd3a7efbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 17 deletions

View File

@ -117,6 +117,8 @@ API Changes
* GITHUB#12173: TermInSetQuery#getTermData has been deprecated. This exposes internal implementation details that we * GITHUB#12173: TermInSetQuery#getTermData has been deprecated. This exposes internal implementation details that we
may want to change in the future, and users shouldn't rely on the encoding directly. (Greg Miller) may want to change in the future, and users shouldn't rely on the encoding directly. (Greg Miller)
* GITHUB#11746: Deprecate LongValueFacetCounts#getTopChildrenSortByCount. (Greg Miller)
New Features New Features
--------------------- ---------------------

View File

@ -42,8 +42,9 @@ import org.apache.lucene.util.PriorityQueue;
* {@link Facets} implementation that computes counts for all unique long values, more efficiently * {@link Facets} implementation that computes counts for all unique long values, more efficiently
* counting small values (0-1023) using an int array, and switching to a <code>HashMap</code> for * counting small values (0-1023) using an int array, and switching to a <code>HashMap</code> for
* values above 1023. Retrieve all facet counts, in value order, with {@link * values above 1023. Retrieve all facet counts, in value order, with {@link
* #getAllChildrenSortByValue}, or get the topN values sorted by count with {@link * #getAllChildrenSortByValue}, or get all children with no ordering requirements with {@link
* #getTopChildrenSortByCount}. * #getAllChildren(String, String...)}, or get the topN values sorted by count with {@link
* #getTopChildren(int, String, String...)}.
* *
* @lucene.experimental * @lucene.experimental
*/ */
@ -376,17 +377,7 @@ public class LongValueFacetCounts extends Facets {
public FacetResult getTopChildren(int topN, String dim, String... path) { public FacetResult getTopChildren(int topN, String dim, String... path) {
validateTopN(topN); validateTopN(topN);
validateDimAndPathForGetChildren(dim, path); validateDimAndPathForGetChildren(dim, path);
return getTopChildrenSortByCount(topN);
}
/** Reusable hash entry to hold long facet value and int count. */
private static class Entry {
int count;
long value;
}
/** Returns the specified top number of facets, sorted by count. */
public FacetResult getTopChildrenSortByCount(int topN) {
PriorityQueue<Entry> pq = PriorityQueue<Entry> pq =
new PriorityQueue<>(Math.min(topN, counts.length + hashCounts.size())) { new PriorityQueue<>(Math.min(topN, counts.length + hashCounts.size())) {
@Override @Override
@ -434,7 +425,20 @@ public class LongValueFacetCounts extends Facets {
return new FacetResult(field, new String[0], totCount, results, childCount); 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).
*
* <p>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() { public FacetResult getAllChildrenSortByValue() {
List<LabelAndValue> labelValues = new ArrayList<>(); List<LabelAndValue> labelValues = new ArrayList<>();

View File

@ -399,7 +399,7 @@ public class TestLongValueFacetCounts extends FacetTestCase {
if (VERBOSE) { if (VERBOSE) {
System.out.println(" topN=" + topN); System.out.println(" topN=" + topN);
} }
actual = facetCounts.getTopChildrenSortByCount(topN); actual = facetCounts.getTopChildren(topN, "field");
assertSame( assertSame(
"all docs, sort facets by count", "all docs, sort facets by count",
expectedCounts, expectedCounts,
@ -488,7 +488,7 @@ public class TestLongValueFacetCounts extends FacetTestCase {
} else { } else {
topN = random().nextInt(docCount); topN = random().nextInt(docCount);
} }
actual = facetCounts.getTopChildrenSortByCount(topN); actual = facetCounts.getTopChildren(topN, "field");
assertSame( assertSame(
"id " + minId + "-" + maxId + ", sort facets by count", "id " + minId + "-" + maxId + ", sort facets by count",
expectedCounts, expectedCounts,
@ -662,7 +662,7 @@ public class TestLongValueFacetCounts extends FacetTestCase {
if (VERBOSE) { if (VERBOSE) {
System.out.println(" topN=" + topN); System.out.println(" topN=" + topN);
} }
actual = facetCounts.getTopChildrenSortByCount(topN); actual = facetCounts.getTopChildren(topN, "field");
assertSame( assertSame(
"all docs, sort facets by count", "all docs, sort facets by count",
expectedCounts, expectedCounts,
@ -729,7 +729,7 @@ public class TestLongValueFacetCounts extends FacetTestCase {
} else { } else {
topN = random().nextInt(docCount); topN = random().nextInt(docCount);
} }
actual = facetCounts.getTopChildrenSortByCount(topN); actual = facetCounts.getTopChildren(topN, "field");
assertSame( assertSame(
"id " + minId + "-" + maxId + ", sort facets by count", "id " + minId + "-" + maxId + ", sort facets by count",
expectedCounts, expectedCounts,