Skip to content

Apache Lucene open-source search software

SOLR-13190 Fix for failing test

Mike Drob1333bd10a7b0
diff --git a/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java b/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java
index 279f9e777b6..c5e3eee4a82 100644
--- a/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java
@@ -28,6 +28,7 @@ import org.apache.lucene.util.automaton.Automaton;
import org.apache.lucene.util.automaton.ByteRunAutomaton;
import org.apache.lucene.util.automaton.LevenshteinAutomata;
import org.apache.lucene.util.automaton.Operations;
+import org.apache.lucene.util.automaton.TooComplexToDeterminizeException;
/** Implements the fuzzy search query. The similarity measurement
* is based on the Damerau-Levenshtein (optimal string alignment) algorithm,
@@ -163,8 +164,12 @@ public class FuzzyQuery extends MultiTermQuery {
visitor.consumeTerms(this, term);
} else {
// Note: we're rebuilding the automaton here, so this can be expensive
- visitor.consumeTermsMatching(this, field,
- new ByteRunAutomaton(toAutomaton(), false, Operations.DEFAULT_MAX_DETERMINIZED_STATES));
+ try {
+ visitor.consumeTermsMatching(this, field,
+ new ByteRunAutomaton(toAutomaton(), false, Operations.DEFAULT_MAX_DETERMINIZED_STATES));
+ } catch (TooComplexToDeterminizeException e) {
+ throw new FuzzyTermsEnum.FuzzyTermsException(term.text(), e);
+ }
}
}
}
diff --git a/lucene/core/src/java/org/apache/lucene/search/FuzzyTermsEnum.java b/lucene/core/src/java/org/apache/lucene/search/FuzzyTermsEnum.java
index 91c67c0236c..6f5da72fb8d 100644
--- a/lucene/core/src/java/org/apache/lucene/search/FuzzyTermsEnum.java
+++ b/lucene/core/src/java/org/apache/lucene/search/FuzzyTermsEnum.java
@@ -419,7 +419,7 @@ public final class FuzzyTermsEnum extends BaseTermsEnum {
* but also possible with shorter terms consisting of UTF-32 code points.
*/
public static class FuzzyTermsException extends RuntimeException {
- private FuzzyTermsException(String term, Throwable cause) {
+ FuzzyTermsException(String term, Throwable cause) {
super("Term too complex: " + term, cause);
}
}