You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2019/11/21 18:46:44 UTC

[lucene-solr] branch master updated: SOLR-13946: Fix SpellCheckCollatorTest.testEstimatedHitCounts lower/upper bounds to match computable values based on random merge policies

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 8f30f64  SOLR-13946: Fix SpellCheckCollatorTest.testEstimatedHitCounts lower/upper bounds to match computable values based on random merge policies
8f30f64 is described below

commit 8f30f6436c13d757ea70d1168be5442810709130
Author: Chris Hostetter <ho...@apache.org>
AuthorDate: Thu Nov 21 11:46:35 2019 -0700

    SOLR-13946: Fix SpellCheckCollatorTest.testEstimatedHitCounts lower/upper bounds to match computable values based on random merge policies
---
 .../solr/spelling/SpellCheckCollatorTest.java      | 28 ++++++++++++++++------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java b/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java
index ef3718d..efa7df2 100644
--- a/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java
+++ b/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java
@@ -45,10 +45,9 @@ import org.junit.Test;
 @SuppressTempFileChecks(bugUrl = "https://issues.apache.org/jira/browse/SOLR-1877 Spellcheck IndexReader leak bug?")
 public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
   
-  //if adding documents to this test, adjust me.
-  private static final int MAX_DOC_ID=16;
-  private static final int MIN_DOC_ID_WITH_EVERYOTHER=0;
-  private static final int MAX_DOC_ID_WITH_EVERYOTHER=15;
+  // if adding documents to this test, adjust me.
+  private static final int NUM_DOCS_WITH_TERM_EVERYOTHER=8;
+  private static final int NUM_DOCS=17;
   @BeforeClass
   public static void beforeClass() throws Exception {
     initCore("solrconfig-spellcheckcomponent.xml", "schema.xml");
@@ -564,13 +563,28 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
     // (we have to be kind of flexible with our definition of "decent"
     // since we're dealing with a fairly small index here)
     for (int val = 5; val <= 20; val++) {
-      int max = MAX_DOC_ID * val / (val + MIN_DOC_ID_WITH_EVERYOTHER + 1);
-      int min = MAX_DOC_ID * val / (val + MAX_DOC_ID_WITH_EVERYOTHER + 1);
+      String hitsXPath = xpathPrefix + "long[@name='hits']"; // we will append to this...
+      
+      if (val <= NUM_DOCS_WITH_TERM_EVERYOTHER) {
+        // strongest assertions we can make given an arbirary MergePolicy on such a small index
+        // is based on the idea that the docs may all come *first* or all come *last*
+        // and then do the math on what estimate should come from that if we collected *exactly* 'val'..
+        //
+        // if they are all "first" we will overestimate and assume everything is a match...
+        int max = NUM_DOCS;
+        // if they are all "last" we will under-estimate based on how non-matches we had to skip...
+        int min = (/* min collected */ val) / (/* max docs possibly scanned */ NUM_DOCS);
+        hitsXPath += "[" + min + " <= . and . <= " + max + "]";
+      } else {
+        // we've asked for a number greater then what can possibly be found in our tiny index, which should
+        // force it to scan all docs so our hits should be exact
+        hitsXPath += "[.=" + NUM_DOCS_WITH_TERM_EVERYOTHER + "]";
+      }
       assertQ(req(reusedParams,
                   CommonParams.Q, "teststop:everother",
                   SpellingParams.SPELLCHECK_COLLATE_MAX_COLLECT_DOCS, ""+val)
               , xpathPrefix + "str[@name='collationQuery']='teststop:everyother'"
-              , xpathPrefix + "long[@name='hits' and " + min + " <= . and . <= " + max + "]"
+              , hitsXPath
               );
     }