Skip to content

BlockJoinBulkScorer could check for parent deletions (not children) #14067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
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 @@ -532,8 +532,10 @@ public int score(LeafCollector collector, Bits acceptDocs, int min, int max)
return scoringCompleteCheck(max, max);
}

BatchAwareLeafCollector wrappedCollector = wrapCollector(collector);
childBulkScorer.score(wrappedCollector, acceptDocs, prevParent + 1, lastParent + 1);
BatchAwareLeafCollector wrappedCollector = wrapCollector(collector, acceptDocs);
// We don't propagate the acceptDocs since only parents are checked for deletion in the
// wrapped collector
childBulkScorer.score(wrappedCollector, null, prevParent + 1, lastParent + 1);
wrappedCollector.endBatch();

return scoringCompleteCheck(lastParent + 1, max);
Expand All @@ -550,7 +552,7 @@ public long cost() {
return childBulkScorer.cost();
}

private BatchAwareLeafCollector wrapCollector(LeafCollector collector) {
private BatchAwareLeafCollector wrapCollector(LeafCollector collector, Bits acceptDocs) {
return new BatchAwareLeafCollector(collector) {
private final Score currentParentScore = new Score(scoreMode);
private int currentParent = -1;
Expand Down Expand Up @@ -581,7 +583,7 @@ public void setMinCompetitiveScore(float minScore) throws IOException {
public void collect(int doc) throws IOException {
if (doc > currentParent) {
// Emit the current parent and setup scoring for the next parent
if (currentParent >= 0) {
if (currentParent >= 0 && (acceptDocs == null || acceptDocs.get(currentParent))) {
in.collect(currentParent);
}

Expand All @@ -602,7 +604,7 @@ public void collect(int doc) throws IOException {

@Override
public void endBatch() throws IOException {
if (currentParent >= 0) {
if (currentParent >= 0 && (acceptDocs == null || acceptDocs.get(currentParent))) {
in.collect(currentParent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.lucene.tests.index.RandomIndexWriter;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.tests.util.TestUtil;
import org.apache.lucene.util.FixedBitSet;

public class TestBlockJoinBulkScorer extends LuceneTestCase {
private static final String TYPE_FIELD_NAME = "type";
Expand Down Expand Up @@ -256,21 +257,36 @@ private static ToParentBlockJoinQuery buildQuery(ScoreMode scoreMode) {
}

private static void assertScores(
int maxDoc,
BulkScorer bulkScorer,
org.apache.lucene.search.ScoreMode scoreMode,
Float minScore,
Map<Integer, Float> expectedScores)
throws IOException {
assertScores(bulkScorer, scoreMode, minScore, List.of(expectedScores));
assertScores(maxDoc, bulkScorer, scoreMode, minScore, List.of(expectedScores));
}

private static void assertScores(
int maxDoc,
BulkScorer bulkScorer,
org.apache.lucene.search.ScoreMode scoreMode,
Float minScore,
List<Map<Integer, Float>> expectedScoresList)
throws IOException {
Map<Integer, Float> actualScores = new HashMap<>();
FixedBitSet acceptDocs = new FixedBitSet(maxDoc);
List<Map<Integer, Float>> expectedScoresListPruned = new ArrayList<>();
for (var map : expectedScoresList) {
Map<Integer, Float> newMap = new HashMap<>();
for (var entry : map.entrySet()) {
if (usually(random())) {
acceptDocs.set(entry.getKey());
newMap.put(entry.getKey(), entry.getValue());
}
}
expectedScoresListPruned.add(newMap);
}

bulkScorer.score(
new LeafCollector() {
private Scorable scorer;
Expand All @@ -286,18 +302,19 @@ public void setScorer(Scorable scorer) throws IOException {

@Override
public void collect(int doc) throws IOException {
assertTrue(acceptDocs.get(doc));
assertNotNull(scorer);
actualScores.put(doc, scoreMode.needsScores() ? scorer.score() : 0);
}
},
null,
acceptDocs,
0,
NO_MORE_DOCS);

if (expectedScoresList.size() == 1) {
assertEquals(expectedScoresList.getFirst(), actualScores);
if (expectedScoresListPruned.size() == 1) {
assertEquals(expectedScoresListPruned.getFirst(), actualScores);
} else {
assertEqualsToOneOf(expectedScoresList, actualScores);
assertEqualsToOneOf(expectedScoresListPruned, actualScores);
}
}

Expand Down Expand Up @@ -356,7 +373,7 @@ public void testScoreRandomIndices() throws IOException {
continue;
}

assertScores(ss.bulkScorer(), searchScoreMode, null, expectedScores);
assertScores(reader.maxDoc(), ss.bulkScorer(), searchScoreMode, null, expectedScores);
}
}
}
Expand Down Expand Up @@ -395,7 +412,7 @@ public void testSetMinCompetitiveScoreWithScoreModeMax() throws IOException {

ScorerSupplier ss = weight.scorerSupplier(searcher.getIndexReader().leaves().get(0));
ss.setTopLevelScoringClause();
assertScores(ss.bulkScorer(), scoreMode, null, expectedScores);
assertScores(reader.maxDoc(), ss.bulkScorer(), scoreMode, null, expectedScores);
}

{
Expand All @@ -418,15 +435,20 @@ public void testSetMinCompetitiveScoreWithScoreModeMax() throws IOException {

ScorerSupplier ss = weight.scorerSupplier(searcher.getIndexReader().leaves().get(0));
ss.setTopLevelScoringClause();
assertScores(ss.bulkScorer(), scoreMode, 6.0f, List.of(expectedScores1, expectedScores2));
assertScores(
reader.maxDoc(),
ss.bulkScorer(),
scoreMode,
6.0f,
List.of(expectedScores1, expectedScores2));
}

{
Map<Integer, Float> expectedScores = Map.of();

ScorerSupplier ss = weight.scorerSupplier(searcher.getIndexReader().leaves().get(0));
ss.setTopLevelScoringClause();
assertScores(ss.bulkScorer(), scoreMode, 11.0f, expectedScores);
assertScores(reader.maxDoc(), ss.bulkScorer(), scoreMode, 11.0f, expectedScores);
}
}
}
Expand Down Expand Up @@ -465,7 +487,7 @@ public void testSetMinCompetitiveScoreWithScoreModeNone() throws IOException {

ScorerSupplier ss = weight.scorerSupplier(searcher.getIndexReader().leaves().get(0));
ss.setTopLevelScoringClause();
assertScores(ss.bulkScorer(), scoreMode, null, expectedScores);
assertScores(reader.maxDoc(), ss.bulkScorer(), scoreMode, null, expectedScores);
}

{
Expand All @@ -479,15 +501,16 @@ public void testSetMinCompetitiveScoreWithScoreModeNone() throws IOException {

ScorerSupplier ss = weight.scorerSupplier(searcher.getIndexReader().leaves().get(0));
ss.setTopLevelScoringClause();
assertScores(ss.bulkScorer(), scoreMode, 0.0f, expectedScores);
assertScores(reader.maxDoc(), ss.bulkScorer(), scoreMode, 0.0f, expectedScores);
}

{
Map<Integer, Float> expectedScores = Map.of();

ScorerSupplier ss = weight.scorerSupplier(searcher.getIndexReader().leaves().get(0));
ss.setTopLevelScoringClause();
assertScores(ss.bulkScorer(), scoreMode, Math.nextUp(0f), expectedScores);
assertScores(
reader.maxDoc(), ss.bulkScorer(), scoreMode, Math.nextUp(0f), expectedScores);
}
}
}
Expand Down
Loading