-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use DenseConjunctionBulkScorer for single queries sometimes.
Even though there is a single clause, it often needs to be intersected, either with live docs or with the collector's competitive iterator. This uses `DenseConjunctionBulkScorer` for: - `MatchAllDocsQuery`, - `TermQuery` when scores are not needed and `docFreq >= maxDoc / 32`, - some constant-score queries including `PointRangeQuery` when `cost >= maxDoc / 32`. In addition, - `DenseConjunctionBulkScorer` was improved to stop collecting hits when the min competitive score is greater than the configured constant score, - Added test coverage to sorting tests to make sure that their competitive iterators are happy with how `DenseConjunctionBulkScorer` reads ahead. The downside of this change is that it forces the impacted queries to score at least 4096 (the window size) docs at once. So queries that can start skipping very early (and which are thus very fast) may see a slowdown (e.g. `TermMonthSort`). On the other hand, when it takes time before dynamic pruning becomes effective, there could be a speedup thanks to the more efficient intersection logic (e.g. `TermDTSort`). This change should also help in the presence of deleted docs, by taking advantage of the more efficient way how deleted docs are applied in this bulk scorer. Closes #14283
- Loading branch information
Showing
19 changed files
with
885 additions
and
480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
lucene/core/src/java/org/apache/lucene/search/ConstantScoreScorerSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.lucene.search; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import org.apache.lucene.search.Weight.DefaultBulkScorer; | ||
|
||
/** Specialization of {@link ScorerSupplier} for queries that produce constant scores. */ | ||
public abstract class ConstantScoreScorerSupplier extends ScorerSupplier { | ||
|
||
public static ConstantScoreScorerSupplier fromIterator( | ||
DocIdSetIterator iterator, float score, ScoreMode scoreMode, int maxDoc) { | ||
return new ConstantScoreScorerSupplier(score, scoreMode, maxDoc) { | ||
|
||
@Override | ||
public long cost() { | ||
return iterator.cost(); | ||
} | ||
|
||
@Override | ||
public DocIdSetIterator iterator(long leadCost) throws IOException { | ||
return iterator; | ||
} | ||
}; | ||
} | ||
|
||
private final ScoreMode scoreMode; | ||
private final float score; | ||
private final int maxDoc; | ||
|
||
/** Constructor, invoked by sub-classes. */ | ||
protected ConstantScoreScorerSupplier(float score, ScoreMode scoreMode, int maxDoc) { | ||
this.scoreMode = scoreMode; | ||
this.score = score; | ||
this.maxDoc = maxDoc; | ||
} | ||
|
||
/** Return an iterator given the cost of the leading clause. */ | ||
public abstract DocIdSetIterator iterator(long leadCost) throws IOException; | ||
|
||
@Override | ||
public final Scorer get(long leadCost) throws IOException { | ||
DocIdSetIterator iterator = iterator(leadCost); | ||
TwoPhaseIterator twoPhase = TwoPhaseIterator.unwrap(iterator); | ||
if (twoPhase == null) { | ||
return new ConstantScoreScorer(score, scoreMode, iterator); | ||
} else { | ||
return new ConstantScoreScorer(score, scoreMode, twoPhase); | ||
} | ||
} | ||
|
||
@Override | ||
public final BulkScorer bulkScorer() throws IOException { | ||
DocIdSetIterator iterator = iterator(Long.MAX_VALUE); | ||
if (maxDoc >= DenseConjunctionBulkScorer.WINDOW_SIZE / 2 | ||
&& iterator.cost() >= maxDoc / DenseConjunctionBulkScorer.DENSITY_THRESHOLD_INVERSE | ||
&& TwoPhaseIterator.unwrap(iterator) == null) { | ||
return new DenseConjunctionBulkScorer(Collections.singletonList(iterator), maxDoc, score); | ||
} else { | ||
return new DefaultBulkScorer(new ConstantScoreScorer(score, scoreMode, iterator)); | ||
} | ||
} | ||
} |
Oops, something went wrong.