Skip to content

Commit c5c082e

Browse files
gsmillergf2121
andcommitted
LUCENE-10379: Count directly into the dense values array in FastTaxonomyFacetCounts#countAll
Co-authored-by: guofeng.my <[email protected]>
1 parent cfc6e54 commit c5c082e

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

lucene/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ Optimizations
122122

123123
* LUCENE-10356: Further optimize facet counting for single-valued TaxonomyFacetCounts. (Greg Miller)
124124

125+
* LUCENE-10379: Count directly into the dense values array in FastTaxonomyFacetCounts#countAll.
126+
(Guo Feng, Greg Miller)
127+
125128
Changes in runtime behavior
126129
---------------------
127130

lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FastTaxonomyFacetCounts.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public FastTaxonomyFacetCounts(
7070
countAll(reader);
7171
}
7272

73-
private final void count(List<MatchingDocs> matchingDocs) throws IOException {
73+
private void count(List<MatchingDocs> matchingDocs) throws IOException {
7474
for (MatchingDocs hits : matchingDocs) {
7575
SortedNumericDocValues multiValued =
7676
FacetUtils.loadOrdinalValues(hits.context.reader(), indexFieldName);
@@ -85,13 +85,27 @@ private final void count(List<MatchingDocs> matchingDocs) throws IOException {
8585
ConjunctionUtils.intersectIterators(Arrays.asList(hits.bits.iterator(), valuesIt));
8686

8787
if (singleValued != null) {
88-
while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
89-
increment((int) singleValued.longValue());
88+
if (values != null) {
89+
while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
90+
values[(int) singleValued.longValue()]++;
91+
}
92+
} else {
93+
while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
94+
sparseValues.addTo((int) singleValued.longValue(), 1);
95+
}
9096
}
9197
} else {
92-
while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
93-
for (int i = 0; i < multiValued.docValueCount(); i++) {
94-
increment((int) multiValued.nextValue());
98+
if (values != null) {
99+
while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
100+
for (int i = 0; i < multiValued.docValueCount(); i++) {
101+
values[(int) multiValued.nextValue()]++;
102+
}
103+
}
104+
} else {
105+
while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
106+
for (int i = 0; i < multiValued.docValueCount(); i++) {
107+
sparseValues.addTo((int) multiValued.nextValue(), 1);
108+
}
95109
}
96110
}
97111
}
@@ -100,7 +114,8 @@ private final void count(List<MatchingDocs> matchingDocs) throws IOException {
100114
rollup();
101115
}
102116

103-
private final void countAll(IndexReader reader) throws IOException {
117+
private void countAll(IndexReader reader) throws IOException {
118+
assert values != null;
104119
for (LeafReaderContext context : reader.leaves()) {
105120
SortedNumericDocValues multiValued =
106121
FacetUtils.loadOrdinalValues(context.reader(), indexFieldName);
@@ -118,7 +133,7 @@ private final void countAll(IndexReader reader) throws IOException {
118133
if (liveDocs != null && liveDocs.get(doc) == false) {
119134
continue;
120135
}
121-
increment((int) singleValued.longValue());
136+
values[(int) singleValued.longValue()]++;
122137
}
123138
} else {
124139
for (int doc = multiValued.nextDoc();
@@ -128,7 +143,7 @@ private final void countAll(IndexReader reader) throws IOException {
128143
continue;
129144
}
130145
for (int i = 0; i < multiValued.docValueCount(); i++) {
131-
increment((int) multiValued.nextValue());
146+
values[(int) multiValued.nextValue()]++;
132147
}
133148
}
134149
}

lucene/facet/src/java/org/apache/lucene/facet/taxonomy/IntTaxonomyFacets.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,21 @@
3131
/** Base class for all taxonomy-based facets that aggregate to a per-ords int[]. */
3232
public abstract class IntTaxonomyFacets extends TaxonomyFacets {
3333

34-
/** Per-ordinal value. */
35-
private final int[] values;
34+
/**
35+
* Dense ordinal values.
36+
*
37+
* <p>We are making this and {@link #sparseValues} protected for some expert usage. e.g. It can be
38+
* checked which is being used before a loop instead of calling {@link #increment} for each
39+
* iteration.
40+
*/
41+
protected final int[] values;
3642

37-
private final IntIntHashMap sparseValues;
43+
/**
44+
* Sparse ordinal values.
45+
*
46+
* @see #values for why protected.
47+
*/
48+
protected final IntIntHashMap sparseValues;
3849

3950
/** Sole constructor. */
4051
protected IntTaxonomyFacets(

0 commit comments

Comments
 (0)