You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by za...@apache.org on 2021/06/09 07:11:19 UTC
[lucene] branch main updated: LUCENE-9976: Fix WANDScorer assertion
error (#171)
This is an automated email from the ASF dual-hosted git repository.
zacharymorn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/main by this push:
new 8bcaf87 LUCENE-9976: Fix WANDScorer assertion error (#171)
8bcaf87 is described below
commit 8bcaf87a836588b26b3b3b2b3f760ddc0d1ef4d7
Author: zacharymorn <za...@yahoo.com>
AuthorDate: Wed Jun 9 00:11:10 2021 -0700
LUCENE-9976: Fix WANDScorer assertion error (#171)
LUCENE-9976: Fix WANDScorer assertion error as (tailMaxScore >= minCompetitiveScore) && (tailSize < minShouldMatch) are valid now
---
lucene/CHANGES.txt | 2 +
.../java/org/apache/lucene/search/WANDScorer.java | 4 +-
.../org/apache/lucene/search/TestWANDScorer.java | 49 ++++++++++++++++++++++
3 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 0fb9fa1..676df6e 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -352,6 +352,8 @@ Other
* LUCENE-9907: Remove dependency on PackedInts#getReader() from the current codecs and move the
method to backwards codec. (Ignacio Vera)
+* LUCENE-9976: Fix WANDScorer assertion error. (Zach Chen, Adrien Grand, Dawid Weiss)
+
======================= Lucene 8.9.0 =======================
API Changes
diff --git a/lucene/core/src/java/org/apache/lucene/search/WANDScorer.java b/lucene/core/src/java/org/apache/lucene/search/WANDScorer.java
index 48e3a2c..3a655fa 100644
--- a/lucene/core/src/java/org/apache/lucene/search/WANDScorer.java
+++ b/lucene/core/src/java/org/apache/lucene/search/WANDScorer.java
@@ -220,7 +220,9 @@ final class WANDScorer extends Scorer {
}
assert maxScoreSum == leadMaxScore : maxScoreSum + " " + leadMaxScore;
- assert minCompetitiveScore == 0 || tailMaxScore < minCompetitiveScore;
+ assert minCompetitiveScore == 0
+ || tailMaxScore < minCompetitiveScore
+ || tailSize < minShouldMatch;
assert doc <= upTo;
}
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestWANDScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestWANDScorer.java
index 5c92cfd..3d480c4 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestWANDScorer.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestWANDScorer.java
@@ -312,6 +312,55 @@ public class TestWANDScorer extends LuceneTestCase {
}
}
+ public void testBasicsWithDisjunctionAndMinShouldMatchAndTailSizeCondition() throws Exception {
+ try (Directory dir = newDirectory()) {
+ try (IndexWriter w =
+ new IndexWriter(dir, newIndexWriterConfig().setMergePolicy(newLogMergePolicy()))) {
+ for (String[] values :
+ Arrays.asList(
+ new String[] {"A", "B"}, // 0
+ new String[] {"A"}, // 1
+ new String[] {}, // 2
+ new String[] {"A", "B", "C"}, // 3
+ // 2 "B"s here and the non constant score term query below forces the
+ // tailMaxScore >= minCompetitiveScore && tailSize < minShouldMatch condition
+ new String[] {"B", "B"}, // 4
+ new String[] {"B", "C"} // 5
+ )) {
+ Document doc = new Document();
+ for (String value : values) {
+ doc.add(new StringField("foo", value, Store.NO));
+ }
+ w.addDocument(doc);
+ }
+
+ w.forceMerge(1);
+ }
+
+ try (IndexReader reader = DirectoryReader.open(dir)) {
+ IndexSearcher searcher = newSearcher(reader);
+
+ Query query =
+ new BooleanQuery.Builder()
+ .add(new TermQuery(new Term("foo", "A")), Occur.SHOULD)
+ .add(new TermQuery(new Term("foo", "B")), Occur.SHOULD)
+ .add(new TermQuery(new Term("foo", "C")), Occur.SHOULD)
+ .setMinimumNumberShouldMatch(2)
+ .build();
+
+ Scorer scorer =
+ searcher
+ .createWeight(searcher.rewrite(query), ScoreMode.TOP_SCORES, 1)
+ .scorer(searcher.getIndexReader().leaves().get(0));
+
+ assertEquals(0, scorer.iterator().nextDoc());
+ scorer.setMinCompetitiveScore(scorer.score());
+
+ assertEquals(3, scorer.iterator().nextDoc());
+ }
+ }
+ }
+
public void testBasicsWithDisjunctionAndMinShouldMatchAndNonScoringMode() throws Exception {
try (Directory dir = newDirectory()) {
try (IndexWriter w =