lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rjer...@apache.org
Subject svn commit: r1615945 - in /lucene/dev/trunk/lucene: CHANGES.txt core/src/java/org/apache/lucene/search/FuzzyQuery.java core/src/test/org/apache/lucene/search/TestFuzzyQuery.java
Date Tue, 05 Aug 2014 15:39:20 GMT
Author: rjernst
Date: Tue Aug  5 15:39:20 2014
New Revision: 1615945

URL: http://svn.apache.org/r1615945
Log:
LUCENE-5869: Added restriction to positive values for maxExpansions in FuzzyQuery

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1615945&r1=1615944&r2=1615945&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Tue Aug  5 15:39:20 2014
@@ -226,6 +226,9 @@ Bug Fixes
   documents will now throw IllegalStateException if the max count
   would be exceeded, instead of silently creating an unusable
   index.  (Mike McCandless)
+
+* LUCENE-5869: Added restriction to positive values for maxExpansions in FuzzyQuery.
+  (Ryan Ernst)
   
 Test Framework
 

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java?rev=1615945&r1=1615944&r2=1615945&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java Tue Aug
 5 15:39:20 2014
@@ -89,8 +89,8 @@ public class FuzzyQuery extends MultiTer
     if (prefixLength < 0) {
       throw new IllegalArgumentException("prefixLength cannot be negative.");
     }
-    if (maxExpansions < 0) {
-      throw new IllegalArgumentException("maxExpansions cannot be negative.");
+    if (maxExpansions <= 0) {
+      throw new IllegalArgumentException("maxExpansions must be positive.");
     }
     
     this.term = term;

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java?rev=1615945&r1=1615944&r2=1615945&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java Tue
Aug  5 15:39:20 2014
@@ -31,6 +31,7 @@ import org.apache.lucene.index.RandomInd
 import org.apache.lucene.index.Term;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.automaton.LevenshteinAutomata;
 
 /**
  * Tests {@link FuzzyQuery}.
@@ -372,6 +373,43 @@ public class TestFuzzyQuery extends Luce
     reader.close();
     index.close();
   }
+
+  public void testValidation() {
+    try {
+      new FuzzyQuery(new Term("field", "foo"), -1, 0, 1, false);
+      fail("Expected error for illegal max edits value");
+    } catch (IllegalArgumentException e) {
+      assertTrue(e.getMessage().contains("maxEdits"));
+    }
+
+    try {
+      new FuzzyQuery(new Term("field", "foo"), LevenshteinAutomata.MAXIMUM_SUPPORTED_DISTANCE
+ 1, 0, 1, false);
+      fail("Expected error for illegal max edits value");
+    } catch (IllegalArgumentException e) {
+      assertTrue(e.getMessage().contains("maxEdits must be between"));
+    }
+
+    try {
+      new FuzzyQuery(new Term("field", "foo"), 1, -1, 1, false);
+      fail("Expected error for illegal prefix length value");
+    } catch (IllegalArgumentException e) {
+      assertTrue(e.getMessage().contains("prefixLength cannot be negative"));
+    }
+
+    try {
+      new FuzzyQuery(new Term("field", "foo"), 1, 0, -1, false);
+      fail("Expected error for illegal max expansions value");
+    } catch (IllegalArgumentException e) {
+      assertTrue(e.getMessage().contains("maxExpansions must be positive"));
+    }
+
+    try {
+      new FuzzyQuery(new Term("field", "foo"), 1, 0, -1, false);
+      fail("Expected error for illegal max expansions value");
+    } catch (IllegalArgumentException e) {
+      assertTrue(e.getMessage().contains("maxExpansions must be positive"));
+    }
+  }
   
   private void addDoc(String text, RandomIndexWriter writer) throws IOException {
     Document doc = new Document();



Mime
View raw message