SOLR-2275: fix DisMax 'mm' parsing to be tolerant of whitespace

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1051641 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2010-12-21 20:42:21 +00:00
parent c2f80515cf
commit 1d9135f0e4
3 changed files with 24 additions and 22 deletions

View File

@ -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
----------------------

View File

@ -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;
}

View File

@ -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"));