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 18:44:27 UTC

[lucene] branch branch_9x updated: LUCENE-10356: Further optimize facet counting for single-valued TaxonomyFacetCounts (#585)

This is an automated email from the ASF dual-hosted git repository.

gsmiller pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 674eb5a  LUCENE-10356: Further optimize facet counting for single-valued TaxonomyFacetCounts (#585)
674eb5a is described below

commit 674eb5a4907b420a758a8b8a98f1d0b0722840a7
Author: Greg Miller <gs...@gmail.com>
AuthorDate: Mon Jan 10 10:23:46 2022 -0800

    LUCENE-10356: Further optimize facet counting for single-valued TaxonomyFacetCounts (#585)
---
 lucene/CHANGES.txt                                 |  2 +
 .../facet/taxonomy/FastTaxonomyFacetCounts.java    | 68 ++++++++++++++--------
 2 files changed, 46 insertions(+), 24 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 9373db11..17006fb 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -112,6 +112,8 @@ Optimizations
 
 * LUCENE-10350: Avoid some duplicate null check in facet counting for TaxonomyFacetCounts. (Guo Feng)
 
+* LUCENE-10356: Further optimize facet counting for single-valued TaxonomyFacetCounts. (Greg Miller)
+
 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 8975759..fe82726 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
@@ -72,25 +72,40 @@ public class FastTaxonomyFacetCounts extends IntTaxonomyFacets {
 
   private void count(List<MatchingDocs> matchingDocs) throws IOException {
     for (MatchingDocs hits : matchingDocs) {
-      SortedNumericDocValues dv =
+      SortedNumericDocValues multiValued =
           FacetUtils.loadOrdinalValues(hits.context.reader(), indexFieldName);
-      if (dv == null) {
+      if (multiValued == null) {
         continue;
       }
 
+      NumericDocValues singleValued = DocValues.unwrapSingleton(multiValued);
+
+      DocIdSetIterator valuesIt = singleValued != null ? singleValued : multiValued;
       DocIdSetIterator it =
-          ConjunctionUtils.intersectIterators(Arrays.asList(hits.bits.iterator(), dv));
+          ConjunctionUtils.intersectIterators(Arrays.asList(hits.bits.iterator(), valuesIt));
 
-      if (values != null) {
-        while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
-          for (int i = 0; i < dv.docValueCount(); i++) {
-            values[(int) dv.nextValue()]++;
+      if (singleValued != null) {
+        if (values != null) {
+          while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
+            values[(int) singleValued.longValue()]++;
+          }
+        } else {
+          while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
+            sparseValues.addTo((int) singleValued.longValue(), 1);
           }
         }
       } else {
-        while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
-          for (int i = 0; i < dv.docValueCount(); i++) {
-            sparseValues.addTo((int) dv.nextValue(), 1);
+        if (values != null) {
+          while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
+            for (int i = 0; i < multiValued.docValueCount(); i++) {
+              values[(int) multiValued.nextValue()]++;
+            }
+          }
+        } else {
+          while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
+            for (int i = 0; i < multiValued.docValueCount(); i++) {
+              sparseValues.addTo((int) multiValued.nextValue(), 1);
+            }
           }
         }
       }
@@ -102,40 +117,45 @@ public class FastTaxonomyFacetCounts extends IntTaxonomyFacets {
   private final void countAll(IndexReader reader) throws IOException {
     assert values != null;
     for (LeafReaderContext context : reader.leaves()) {
-      SortedNumericDocValues dv = FacetUtils.loadOrdinalValues(context.reader(), indexFieldName);
-      if (dv == null) {
+      SortedNumericDocValues multiValued =
+          FacetUtils.loadOrdinalValues(context.reader(), indexFieldName);
+      if (multiValued == null) {
         continue;
       }
 
       Bits liveDocs = context.reader().getLiveDocs();
-      NumericDocValues ndv = DocValues.unwrapSingleton(dv);
+      NumericDocValues singleValued = DocValues.unwrapSingleton(multiValued);
 
-      if (ndv != null) {
+      if (singleValued != null) {
         if (liveDocs == null) {
-          while (ndv.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
-            values[(int) ndv.longValue()]++;
+          while (singleValued.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
+            values[(int) singleValued.longValue()]++;
           }
         } else {
-          for (int doc = ndv.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = ndv.nextDoc()) {
+          for (int doc = singleValued.nextDoc();
+              doc != DocIdSetIterator.NO_MORE_DOCS;
+              doc = singleValued.nextDoc()) {
             if (liveDocs.get(doc)) {
-              values[(int) ndv.longValue()]++;
+              values[(int) singleValued.longValue()]++;
             }
           }
         }
       } else {
         if (liveDocs == null) {
-          while (dv.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
-            final int dvCount = dv.docValueCount();
+          while (multiValued.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
+            final int dvCount = multiValued.docValueCount();
             for (int i = 0; i < dvCount; i++) {
-              values[(int) dv.nextValue()]++;
+              values[(int) multiValued.nextValue()]++;
             }
           }
         } else {
-          for (int doc = dv.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = dv.nextDoc()) {
+          for (int doc = multiValued.nextDoc();
+              doc != DocIdSetIterator.NO_MORE_DOCS;
+              doc = multiValued.nextDoc()) {
             if (liveDocs.get(doc)) {
-              final int dvCount = dv.docValueCount();
+              final int dvCount = multiValued.docValueCount();
               for (int i = 0; i < dvCount; i++) {
-                values[(int) dv.nextValue()]++;
+                values[(int) multiValued.nextValue()]++;
               }
             }
           }