diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index a941c0e352b..0550efb3e84 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -576,6 +576,8 @@ Bug Fixes addresses "commitWithin" option on Update requests. (noble, hossman, and Maxim Valyanskiy) +* SOLR-2275: fix DisMax 'mm' parsing to be tolerant of whitespace + (Erick Erickson via hossman) Other Changes ---------------------- diff --git a/solr/src/java/org/apache/solr/util/SolrPluginUtils.java b/solr/src/java/org/apache/solr/util/SolrPluginUtils.java index 755a0ff413d..8560a456f0c 100644 --- a/solr/src/java/org/apache/solr/util/SolrPluginUtils.java +++ b/solr/src/java/org/apache/solr/util/SolrPluginUtils.java @@ -612,17 +612,17 @@ public class SolrPluginUtils { * helper exposed for UnitTests * @see #setMinShouldMatch */ - static int calculateMinShouldMatch(int optionalClauseCount, String spec) { + static int calculateMinShouldMatch(int optionalClauseCount, String specIn) { int result = optionalClauseCount; - + String spec = specIn.replaceAll("\\s*<\\s*", "<"); if (-1 < spec.indexOf("<")) { /* we have conditional spec(s) */ for (String s : spec.trim().split(" ")) { String[] parts = s.split("<"); - int upperBound = (new Integer(parts[0])).intValue(); + int upperBound = (new Integer(parts[0].trim())).intValue(); if (optionalClauseCount <= upperBound) { return result; } else { @@ -637,11 +637,11 @@ public class SolrPluginUtils { if (-1 < spec.indexOf("%")) { /* percentage */ - int percent = new Integer(spec.replace("%","")).intValue(); + int percent = new Integer(spec.trim().replace("%","")).intValue(); float calc = (result * percent) / 100f; result = calc < 0 ? result + (int)calc : (int)calc; } else { - int calc = (new Integer(spec)).intValue(); + int calc = (new Integer(spec.trim())).intValue(); result = calc < 0 ? result + calc : calc; } diff --git a/solr/src/test/org/apache/solr/util/SolrPluginUtilsTest.java b/solr/src/test/org/apache/solr/util/SolrPluginUtilsTest.java index 70c1364015c..b562c340730 100644 --- a/solr/src/test/org/apache/solr/util/SolrPluginUtilsTest.java +++ b/solr/src/test/org/apache/solr/util/SolrPluginUtilsTest.java @@ -296,11 +296,11 @@ public class SolrPluginUtilsTest extends SolrTestCaseJ4 { /* zero is zero is zero */ assertEquals(0, calcMSM(5, "0")); assertEquals(0, calcMSM(5, "0%")); - assertEquals(0, calcMSM(5, "-5")); - assertEquals(0, calcMSM(5, "-100%")); + assertEquals(0, calcMSM(5, " -5 ")); + assertEquals(0, calcMSM(5, "\n -100% \n")); /* basic integers */ - assertEquals(3, calcMSM(5, "3")); + assertEquals(3, calcMSM(5, " \n3\n ")); assertEquals(2, calcMSM(5, "-3")); assertEquals(3, calcMSM(3, "3")); assertEquals(0, calcMSM(3, "-3")); @@ -308,13 +308,13 @@ public class SolrPluginUtilsTest extends SolrTestCaseJ4 { assertEquals(0, calcMSM(3, "-5")); /* positive percentages with rounding */ - assertEquals(0, calcMSM(3, "25%")); + assertEquals(0, calcMSM(3, " \n25% \n")); assertEquals(1, calcMSM(4, "25%")); - assertEquals(1, calcMSM(5, "25%")); + assertEquals(1, calcMSM(5, " 25% ")); assertEquals(2, calcMSM(10, "25%")); /* negative percentages with rounding */ - assertEquals(3, calcMSM(3, "-25%")); + assertEquals(3, calcMSM(3, " \n-25%\n ")); assertEquals(3, calcMSM(4, "-25%")); assertEquals(4, calcMSM(5, "-25%")); assertEquals(8, calcMSM(10, "-25%")); @@ -326,22 +326,22 @@ public class SolrPluginUtilsTest extends SolrTestCaseJ4 { assertEquals(0, calcMSM(4, "3<0")); assertEquals(0, calcMSM(5, "3<0")); assertEquals(1, calcMSM(1, "3<25%")); - assertEquals(2, calcMSM(2, "3<25%")); + assertEquals(2, calcMSM(2, " 3\n<\n25% ")); assertEquals(3, calcMSM(3, "3<25%")); - assertEquals(1, calcMSM(4, "3<25%")); + assertEquals(1, calcMSM(4, "\n 3 < \n25%\n ")); assertEquals(1, calcMSM(5, "3<25%")); /* multiple conditionals */ - assertEquals(1, calcMSM(1, "3<-25% 10<-3")); - assertEquals(2, calcMSM(2, "3<-25% 10<-3")); - assertEquals(3, calcMSM(3, "3<-25% 10<-3")); - assertEquals(3, calcMSM(4, "3<-25% 10<-3")); - assertEquals(4, calcMSM(5, "3<-25% 10<-3")); + assertEquals(1, calcMSM(1, "\n3 < -25% 10 < -3 \n")); + assertEquals(2, calcMSM(2, " 3 < -25% 10 < -3\n")); + assertEquals(3, calcMSM(3, " 3 < -25% \n 10 < -3 \n")); + assertEquals(3, calcMSM(4, " 3 < -25% 10 < -3 ")); + assertEquals(4, calcMSM(5, " 3 < -25% 10 < -3")); assertEquals(5, calcMSM(6, "3<-25% 10<-3")); - assertEquals(6, calcMSM(7, "3<-25% 10<-3")); - assertEquals(6, calcMSM(8, "3<-25% 10<-3")); - assertEquals(7, calcMSM(9, "3<-25% 10<-3")); - assertEquals(8, calcMSM(10, "3<-25% 10<-3")); + assertEquals(6, calcMSM(7, " 3 < -25% 10 < -3 ")); + assertEquals(6, calcMSM(8, " 3 < -25% 10 \n < -3\n")); + assertEquals(7, calcMSM(9, " 3 < -25% 10 < -3 \n")); + assertEquals(8, calcMSM(10, " 3 < -25% 10 < -3")); assertEquals(8, calcMSM(11, "3<-25% 10<-3")); assertEquals(9, calcMSM(12, "3<-25% 10<-3")); assertEquals(97, calcMSM(100, "3<-25% 10<-3"));