Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,23 @@ protected void describe(StringBuilder sb) {
sb.append(", remainingDocs=").append(remainingDocs);
}

private class PerTagsState implements LeafCollector {
private final class PerTagsState implements LeafCollector {
long totalHits;

@Override
public void setScorer(Scorable scorer) {}

@Override
public void collectRange(int min, int max) throws IOException {
// Default collectRange(min, max) delegates to collect(DocIdStream),
// overwriting this saves creating a DocIdStream instance.
if (remainingDocs > 0) {
int count = Math.min(max - min, remainingDocs);
totalHits += count;
remainingDocs -= count;
}
}

@Override
public void collect(DocIdStream stream) throws IOException {
if (remainingDocs > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@

import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.index.PointValues;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.index.Terms;
import org.apache.lucene.search.ConstantScoreScorer;
import org.apache.lucene.search.ConstantScoreScorerSupplier;
import org.apache.lucene.search.ConstantScoreWeight;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.IndexSearcher;
Expand Down Expand Up @@ -118,11 +121,17 @@ private ScorerSupplier scorerSupplier(
ScoreMode scoreMode
) throws IOException {
final int maxDoc = context.reader().maxDoc();
if (DocValues.unwrapSingleton(sortedNumerics) != null) {
NumericDocValues singleton = DocValues.unwrapSingleton(sortedNumerics);
if (singleton != null) {
// check for dense field
if (singleton.docIDRunEnd() == maxDoc) {
// Doc value fields that are truly dense will report maxDoc as docIDRunEnd.
return new DocIdSetIteratorScorerSupplier(boost, scoreMode, maxDoc, DocIdSetIterator.all(maxDoc));
}
// TODO: check doc value skippers
final PointValues points = context.reader().getPointValues(fieldData.getFieldName());
if (points != null && points.getDocCount() == maxDoc) {
return new DocIdSetIteratorScorerSupplier(boost, scoreMode, DocIdSetIterator.all(maxDoc));
return new DocIdSetIteratorScorerSupplier(boost, scoreMode, maxDoc, DocIdSetIterator.all(maxDoc));
} else {
return new PredicateScorerSupplier(boost, scoreMode, maxDoc, MULTI_VALUE_MATCH_COST, sortedNumerics::advanceExact);
}
Expand All @@ -147,11 +156,17 @@ private ScorerSupplier scorerSupplier(
ScoreMode scoreMode
) throws IOException {
final int maxDoc = context.reader().maxDoc();
if (DocValues.unwrapSingleton(sortedSetDocValues) != null) {
SortedDocValues singleton = DocValues.unwrapSingleton(sortedSetDocValues);
if (singleton != null) {
// check for dense field
if (singleton.docIDRunEnd() == maxDoc) {
// Doc value fields that are truly dense will report maxDoc as docIDRunEnd.
return new DocIdSetIteratorScorerSupplier(boost, scoreMode, maxDoc, DocIdSetIterator.all(maxDoc));
}
// TODO: check doc value skippers
final Terms terms = context.reader().terms(fieldData.getFieldName());
if (terms != null && terms.getDocCount() == maxDoc) {
return new DocIdSetIteratorScorerSupplier(boost, scoreMode, DocIdSetIterator.all(maxDoc));
return new DocIdSetIteratorScorerSupplier(boost, scoreMode, maxDoc, DocIdSetIterator.all(maxDoc));
} else {
return new PredicateScorerSupplier(
boost,
Expand Down Expand Up @@ -253,21 +268,18 @@ public int hashCode() {
return Objects.hash(classHash(), fieldData.getFieldName());
}

private static class DocIdSetIteratorScorerSupplier extends ScorerSupplier {
private static final class DocIdSetIteratorScorerSupplier extends ConstantScoreScorerSupplier {

private final float score;
private final ScoreMode scoreMode;
private final DocIdSetIterator docIdSetIterator;

private DocIdSetIteratorScorerSupplier(float score, ScoreMode scoreMode, DocIdSetIterator docIdSetIterator) {
this.score = score;
this.scoreMode = scoreMode;
private DocIdSetIteratorScorerSupplier(float boost, ScoreMode scoreMode, int maxDoc, DocIdSetIterator docIdSetIterator) {
super(boost, scoreMode, maxDoc);
this.docIdSetIterator = docIdSetIterator;
}

@Override
public Scorer get(long leadCost) {
return new ConstantScoreScorer(score, scoreMode, docIdSetIterator);
public DocIdSetIterator iterator(long leadCost) throws IOException {
return docIdSetIterator;
}

@Override
Expand Down