Apache Lucene open-source search software
LUCENE-10368: Make IntTaxonomyFacets pkg-private (#600)
Greg Miller4323848469ae
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 2f4dbfcbe2e..5b0b3521d1a 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -12,6 +12,9 @@ API Changesclasses no longer determinize NFAs. Instead it is the responsibilityof the caller to determinize. (Robert Muir)+* LUCENE-10368: IntTaxonomyFacets has been make pkg-private and serves only as an internal+ implementation detail of taxonomy-faceting. (Greg Miller)+New Features---------------------@@ -69,6 +72,9 @@ API Changes* LUCENE-10381: Require users to provide FacetsConfig for SSDV faceting. (Greg Miller)+* LUCENE-10368: IntTaxonomyFacets has been deprecated and is no longer a supported extension point+ for user-created faceting implementations. (Greg Miller)+New Features---------------------diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/IntTaxonomyFacets.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/IntTaxonomyFacets.javaindex cdec3f1153f..1bde0eb798e 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/IntTaxonomyFacets.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/IntTaxonomyFacets.java@@ -29,26 +29,16 @@ import org.apache.lucene.facet.LabelAndValue;import org.apache.lucene.facet.TopOrdAndIntQueue;/** Base class for all taxonomy-based facets that aggregate to a per-ords int[]. */-public abstract class IntTaxonomyFacets extends TaxonomyFacets {+abstract class IntTaxonomyFacets extends TaxonomyFacets {- /**- * Dense ordinal values.- *- * <p>We are making this and {@link #sparseValues} protected for some expert usage. e.g. It can be- * checked which is being used before a loop instead of calling {@link #increment} for each- * iteration.- */- protected final int[] values;+ /** Dense ordinal values. */+ final int[] values;- /**- * Sparse ordinal values.- *- * @see #values for why protected.- */- protected final IntIntHashMap sparseValues;+ /** Sparse ordinal values. */+ final IntIntHashMap sparseValues;/** Sole constructor. */- protected IntTaxonomyFacets(+ IntTaxonomyFacets(String indexFieldName, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc)throws IOException {super(indexFieldName, taxoReader, config);@@ -62,36 +52,8 @@ public abstract class IntTaxonomyFacets extends TaxonomyFacets {}}- /** Return true if a sparse hash table should be used for counting, instead of a dense int[]. */- protected boolean useHashTable(FacetsCollector fc, TaxonomyReader taxoReader) {- if (taxoReader.getSize() < 1024) {- // small number of unique values: use an array- return false;- }-- if (fc == null) {- // counting all docs: use an array- return false;- }-- int maxDoc = 0;- int sumTotalHits = 0;- for (MatchingDocs docs : fc.getMatchingDocs()) {- sumTotalHits += docs.totalHits;- maxDoc += docs.context.reader().maxDoc();- }-- // if our result set is < 10% of the index, we collect sparsely (use hash map):- return sumTotalHits < maxDoc / 10;- }-- /** Increment the count for this ordinal by 1. */- protected void increment(int ordinal) {- increment(ordinal, 1);- }-/** Increment the count for this ordinal by {@code amount}.. */- protected void increment(int ordinal, int amount) {+ void increment(int ordinal, int amount) {if (sparseValues != null) {sparseValues.addTo(ordinal, amount);} else {@@ -100,7 +62,7 @@ public abstract class IntTaxonomyFacets extends TaxonomyFacets {}/** Get the count for this ordinal. */- protected int getValue(int ordinal) {+ int getValue(int ordinal) {if (sparseValues != null) {return sparseValues.get(ordinal);} else {@@ -109,7 +71,7 @@ public abstract class IntTaxonomyFacets extends TaxonomyFacets {}/** Rolls up any single-valued hierarchical dimensions. */- protected void rollup() throws IOException {+ void rollup() throws IOException {// Rollup any necessary dims:int[] children = null;for (Map.Entry<String, DimConfig> ent : config.getDimConfigs().entrySet()) {@@ -142,6 +104,29 @@ public abstract class IntTaxonomyFacets extends TaxonomyFacets {return sum;}+ /** Return true if a sparse hash table should be used for counting, instead of a dense int[]. */+ private boolean useHashTable(FacetsCollector fc, TaxonomyReader taxoReader) {+ if (taxoReader.getSize() < 1024) {+ // small number of unique values: use an array+ return false;+ }++ if (fc == null) {+ // counting all docs: use an array+ return false;+ }++ int maxDoc = 0;+ int sumTotalHits = 0;+ for (MatchingDocs docs : fc.getMatchingDocs()) {+ sumTotalHits += docs.totalHits;+ maxDoc += docs.context.reader().maxDoc();+ }++ // if our result set is < 10% of the index, we collect sparsely (use hash map):+ return sumTotalHits < maxDoc / 10;+ }+@Overridepublic Number getSpecificValue(String dim, String... path) throws IOException {DimConfig dimConfig = verifyDim(dim);diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumIntAssociations.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumIntAssociations.javaindex 4827779375c..9c22cf6cc82 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumIntAssociations.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumIntAssociations.java@@ -73,6 +73,7 @@ public class TaxonomyFacetSumIntAssociations extends IntTaxonomyFacets {offset += 4;int value = (int) BitUtil.VH_BE_INT.get(bytes, offset);offset += 4;+ // TODO: Can we optimize the null check in increment? See LUCENE-10373.increment(ord, value);}}