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/10 07:26:17 UTC

[lucene-solr] branch branch_8_9 updated: LUCENE-9976: Fix WANDScorer assertion error (#171) (#2511)

This is an automated email from the ASF dual-hosted git repository.

zacharymorn pushed a commit to branch branch_8_9
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8_9 by this push:
     new 05c8a6f  LUCENE-9976: Fix WANDScorer assertion error (#171) (#2511)
05c8a6f is described below

commit 05c8a6f0163fe4c330e93775e8e91f3ab66a3f80
Author: zacharymorn <za...@yahoo.com>
AuthorDate: Thu Jun 10 00:25:58 2021 -0700

    LUCENE-9976: Fix WANDScorer assertion error (#171) (#2511)
---
 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 c4c353d..eee1950 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -106,6 +106,8 @@ Other
 
 * LUCENE-9985: Upgrade jetty to 9.4.41 (janhoy)
 
+* LUCENE-9976: Fix WANDScorer assertion error. (Zach Chen, Adrien Grand, Dawid Weiss)
+
 ======================= Lucene 8.8.2 =======================
 
 Bug Fixes
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 48e071f8..44f19a1 100644
--- a/lucene/core/src/java/org/apache/lucene/search/WANDScorer.java
+++ b/lucene/core/src/java/org/apache/lucene/search/WANDScorer.java
@@ -216,7 +216,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 0d0822d..d303f84 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestWANDScorer.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestWANDScorer.java
@@ -289,6 +289,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 =