You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by gs...@apache.org on 2022/01/10 15:43:37 UTC
[lucene] branch main updated: LUCENE-10350: Avoid some null checking for FastTaxonomyFacetCounts#countAll() (#578)
This is an automated email from the ASF dual-hosted git repository.
gsmiller pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/main by this push:
new e750f6c LUCENE-10350: Avoid some null checking for FastTaxonomyFacetCounts#countAll() (#578)
e750f6c is described below
commit e750f6cd37f422c3c35ad1945efa4222a484d9f9
Author: gf2121 <52...@users.noreply.github.com>
AuthorDate: Mon Jan 10 23:43:09 2022 +0800
LUCENE-10350: Avoid some null checking for FastTaxonomyFacetCounts#countAll() (#578)
---
lucene/CHANGES.txt | 2 +
.../facet/taxonomy/FastTaxonomyFacetCounts.java | 59 +++++++++++++++-------
.../lucene/facet/taxonomy/IntTaxonomyFacets.java | 17 +++++--
3 files changed, 56 insertions(+), 22 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 01137e6..683fa15 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -146,6 +146,8 @@ Optimizations
* LUCENE-10346: Optimize facet counting for single-valued TaxonomyFacetCounts. (Guo Feng)
+* LUCENE-10350: Avoid some duplicate null check in facet counting for TaxonomyFacetCounts. (Guo Feng)
+
Changes in runtime behavior
---------------------
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FastTaxonomyFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FastTaxonomyFacetCounts.java
index 439fa09..9a6436b 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FastTaxonomyFacetCounts.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FastTaxonomyFacetCounts.java
@@ -69,7 +69,7 @@ public class FastTaxonomyFacetCounts extends IntTaxonomyFacets {
countAll(reader);
}
- private final void count(List<MatchingDocs> matchingDocs) throws IOException {
+ private void count(List<MatchingDocs> matchingDocs) throws IOException {
for (MatchingDocs hits : matchingDocs) {
SortedNumericDocValues dv = hits.context.reader().getSortedNumericDocValues(indexFieldName);
if (dv == null) {
@@ -79,9 +79,17 @@ public class FastTaxonomyFacetCounts extends IntTaxonomyFacets {
DocIdSetIterator it =
ConjunctionUtils.intersectIterators(Arrays.asList(hits.bits.iterator(), dv));
- for (int doc = it.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = it.nextDoc()) {
- for (int i = 0; i < dv.docValueCount(); i++) {
- increment((int) dv.nextValue());
+ if (values != null) {
+ while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
+ for (int i = 0; i < dv.docValueCount(); i++) {
+ values[(int) dv.nextValue()]++;
+ }
+ }
+ } else {
+ while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
+ for (int i = 0; i < dv.docValueCount(); i++) {
+ sparseValues.addTo((int) dv.nextValue(), 1);
+ }
}
}
}
@@ -90,6 +98,7 @@ public class FastTaxonomyFacetCounts extends IntTaxonomyFacets {
}
private final void countAll(IndexReader reader) throws IOException {
+ assert values != null;
for (LeafReaderContext context : reader.leaves()) {
SortedNumericDocValues dv = context.reader().getSortedNumericDocValues(indexFieldName);
if (dv == null) {
@@ -97,25 +106,37 @@ public class FastTaxonomyFacetCounts extends IntTaxonomyFacets {
}
Bits liveDocs = context.reader().getLiveDocs();
-
NumericDocValues ndv = DocValues.unwrapSingleton(dv);
+
if (ndv != null) {
- for (int doc = ndv.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = ndv.nextDoc()) {
- if (liveDocs != null && liveDocs.get(doc) == false) {
- continue;
+ if (liveDocs == null) {
+ while (ndv.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
+ values[(int) ndv.longValue()]++;
+ }
+ } else {
+ for (int doc = ndv.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = ndv.nextDoc()) {
+ if (liveDocs.get(doc)) {
+ values[(int) ndv.longValue()]++;
+ }
}
- increment((int) ndv.longValue());
- }
- continue;
- }
-
- for (int doc = dv.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = dv.nextDoc()) {
- if (liveDocs != null && liveDocs.get(doc) == false) {
- continue;
}
-
- for (int i = 0; i < dv.docValueCount(); i++) {
- increment((int) dv.nextValue());
+ } else {
+ if (liveDocs == null) {
+ while (dv.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
+ final int dvCount = dv.docValueCount();
+ for (int i = 0; i < dvCount; i++) {
+ values[(int) dv.nextValue()]++;
+ }
+ }
+ } else {
+ for (int doc = dv.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = dv.nextDoc()) {
+ if (liveDocs.get(doc)) {
+ final int dvCount = dv.docValueCount();
+ for (int i = 0; i < dvCount; i++) {
+ values[(int) dv.nextValue()]++;
+ }
+ }
+ }
}
}
}
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.java
index 3f1dc17..cdec3f1 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
@@ -31,10 +31,21 @@ 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 {
- /** Per-ordinal value. */
- private final int[] values;
+ /**
+ * 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;
- private final IntIntHashMap sparseValues;
+ /**
+ * Sparse ordinal values.
+ *
+ * @see #values for why protected.
+ */
+ protected final IntIntHashMap sparseValues;
/** Sole constructor. */
protected IntTaxonomyFacets(