You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2022/01/03 14:13:34 UTC

[lucene] 02/02: LUCENE-10346: Specially treat SingletonSortedNumericDocValues in FastTaxonomyFacetCounts#countAll() (#574)

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

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

commit 01f5e7bb7b4f5efb5330ab97896008c83daef657
Author: gf2121 <52...@users.noreply.github.com>
AuthorDate: Mon Jan 3 21:44:05 2022 +0800

    LUCENE-10346: Specially treat SingletonSortedNumericDocValues in FastTaxonomyFacetCounts#countAll() (#574)
---
 lucene/CHANGES.txt                                          |  2 ++
 .../lucene/facet/taxonomy/FastTaxonomyFacetCounts.java      | 13 +++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 2c87919..d11c51e 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -106,6 +106,8 @@ Optimizations
   asked to -- typically never.  This fixes a performance regression since 7.3 LUCENE-8099 when some
   older boosting queries were replaced with this. (David Smiley)
 
+* LUCENE-10346: Optimize facet counting for single-valued TaxonomyFacetCounts. (Guo Feng)
+
 Bug Fixes
 ---------------------
 
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 668b773..0d8b26e 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
@@ -23,8 +23,10 @@ import org.apache.lucene.facet.FacetUtils;
 import org.apache.lucene.facet.FacetsCollector;
 import org.apache.lucene.facet.FacetsCollector.MatchingDocs;
 import org.apache.lucene.facet.FacetsConfig;
+import org.apache.lucene.index.DocValues;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.NumericDocValues;
 import org.apache.lucene.index.SortedNumericDocValues;
 import org.apache.lucene.search.ConjunctionUtils;
 import org.apache.lucene.search.DocIdSetIterator;
@@ -98,6 +100,17 @@ 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;
+          }
+          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;