mirror of https://github.com/apache/lucene.git
LUCENE-10350: Avoid some null checking for FastTaxonomyFacetCounts#countAll() (#578)
This commit is contained in:
parent
2ebc57a465
commit
e750f6cd37
|
@ -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
|
||||
---------------------
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
if (values != null) {
|
||||
while (it.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
|
||||
for (int i = 0; i < dv.docValueCount(); i++) {
|
||||
increment((int) dv.nextValue());
|
||||
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) {
|
||||
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 != null && liveDocs.get(doc) == false) {
|
||||
continue;
|
||||
if (liveDocs.get(doc)) {
|
||||
values[(int) ndv.longValue()]++;
|
||||
}
|
||||
increment((int) ndv.longValue());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
} 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 != null && liveDocs.get(doc) == false) {
|
||||
continue;
|
||||
if (liveDocs.get(doc)) {
|
||||
final int dvCount = dv.docValueCount();
|
||||
for (int i = 0; i < dvCount; i++) {
|
||||
values[(int) dv.nextValue()]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < dv.docValueCount(); i++) {
|
||||
increment((int) dv.nextValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue