-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix MaxScoreBulkScorer window-bounds bug (prevent TermScorer docID >= maxDoc EOF) #15345
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
Open
kdt523
wants to merge
9
commits into
apache:main
Choose a base branch
from
kdt523:fix/maxscore-bounds-eof-from-main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+96
−7
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c1d6515
Fix MaxScoreBulkScorer window bounds bug and add CHANGES entry
kdt523 b31f19f
Merge branch 'apache:main' into fix/maxscore-bounds-eof
kdt523 8442a1c
Merge branch 'apache:main' into fix/maxscore-bounds-eof
kdt523 75737f9
Merge branch 'fix/maxscore-bounds-eof' into fix/maxscore-bounds-eof-f…
kdt523 f84913b
Add CHANGES entry for MaxScoreBulkScorer fix
kdt523 3fec857
restore:Add-back-GITHUB15343-AcceptDocs-cost-CHANGES-entry
kdt523 ae6fab5
fix test: use newDirectory instead of RAMDirectory in TestMaxScoreBu…
kdt523 9c22756
fix: resolve CHANGES.txt merge conflict and restore GITHUB#15343 and…
kdt523 e12de50
Merge branch 'main' into fix/maxscore-bounds-eof-from-main
kdt523 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
80 changes: 80 additions & 0 deletions
80
lucene/core/src/test/org/apache/lucene/search/TestMaxScoreBulkScorerFilterBounds.java
This file contains hidden or 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,80 @@ | ||
| /* | ||
| * 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 org.apache.lucene.document.Document; | ||
| import org.apache.lucene.document.Field; | ||
| import org.apache.lucene.document.StringField; | ||
| import org.apache.lucene.index.DirectoryReader; | ||
| import org.apache.lucene.index.IndexWriter; | ||
| import org.apache.lucene.index.IndexWriterConfig; | ||
| import org.apache.lucene.index.Term; | ||
| import org.apache.lucene.store.Directory; | ||
| import org.apache.lucene.store.RAMDirectory; | ||
| import org.apache.lucene.tests.util.LuceneTestCase; | ||
|
|
||
| /** | ||
| * Regression test for a bug where MaxScoreBulkScorer could score past leaf maxDoc when a | ||
| * restrictive filter and disjunction were used together. | ||
| */ | ||
| public class TestMaxScoreBulkScorerFilterBounds extends LuceneTestCase { | ||
|
|
||
| public void testFilteredDisjunctionDoesNotScorePastMaxDoc() throws Exception { | ||
| Directory dir = new RAMDirectory(); | ||
|
||
| IndexWriterConfig iwc = new IndexWriterConfig(); | ||
| try (IndexWriter w = new IndexWriter(dir, iwc)) { | ||
| // Create a small index where one clause matches more docs than the other, and a restrictive | ||
| // filter | ||
| for (int i = 0; i < 200; i++) { | ||
| Document d = new Document(); | ||
| // Clause A matches ~1/3 | ||
| d.add(new StringField("a", (i % 3 == 0) ? "yes" : "no", Field.Store.NO)); | ||
| // Clause B matches ~1/9 | ||
| d.add(new StringField("b", (i % 9 == 0) ? "yes" : "no", Field.Store.NO)); | ||
| // Restrictive filter matches ~1% | ||
| d.add(new StringField("f", (i % 100 == 0) ? "on" : "off", Field.Store.NO)); | ||
| w.addDocument(d); | ||
| } | ||
| } | ||
|
|
||
| try (DirectoryReader reader = DirectoryReader.open(dir)) { | ||
| IndexSearcher searcher = new IndexSearcher(reader); | ||
|
|
||
| Query disjunction = | ||
| new BooleanQuery.Builder() | ||
| .add(new TermQuery(new Term("a", "yes")), BooleanClause.Occur.SHOULD) | ||
| .add(new TermQuery(new Term("b", "yes")), BooleanClause.Occur.SHOULD) | ||
| .build(); | ||
|
|
||
| Query filter = new TermQuery(new Term("f", "on")); | ||
|
|
||
| Query filtered = | ||
| new BooleanQuery.Builder() | ||
| .add(disjunction, BooleanClause.Occur.SHOULD) | ||
| .add(filter, BooleanClause.Occur.FILTER) | ||
| .build(); | ||
|
|
||
| // This triggers TOP_SCORES path internally; just execute to ensure no exceptions | ||
| TopDocs td = searcher.search(filtered, 10); | ||
| assertNotNull(td); | ||
| // Optionally assert we got at most 2 hits (since ~200 docs, ~1% filter) but not necessary for | ||
| // regression | ||
| } finally { | ||
| dir.close(); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woops, seems like a bad delete?