lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hoss...@apache.org
Subject svn commit: r1051641 - in /lucene/dev/trunk/solr: CHANGES.txt src/java/org/apache/solr/util/SolrPluginUtils.java src/test/org/apache/solr/util/SolrPluginUtilsTest.java
Date Tue, 21 Dec 2010 20:42:21 GMT
Author: hossman
Date: Tue Dec 21 20:42:21 2010
New Revision: 1051641

URL: http://svn.apache.org/viewvc?rev=1051641&view=rev
Log:
SOLR-2275: fix DisMax 'mm' parsing to be tolerant of whitespace

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/src/java/org/apache/solr/util/SolrPluginUtils.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/util/SolrPluginUtilsTest.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1051641&r1=1051640&r2=1051641&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Tue Dec 21 20:42:21 2010
@@ -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
 ----------------------

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/util/SolrPluginUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/util/SolrPluginUtils.java?rev=1051641&r1=1051640&r2=1051641&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/util/SolrPluginUtils.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/util/SolrPluginUtils.java Tue Dec 21 20:42:21
2010
@@ -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;
     }
 

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/util/SolrPluginUtilsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/util/SolrPluginUtilsTest.java?rev=1051641&r1=1051640&r2=1051641&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/util/SolrPluginUtilsTest.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/util/SolrPluginUtilsTest.java Tue Dec 21
20:42:21 2010
@@ -296,11 +296,11 @@ public class SolrPluginUtilsTest extends
     /* 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
     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
     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"));



Mime
View raw message