@@ -59,8 +59,15 @@ public static boolean isSuffixWildcard(String str) {
5959 return isSuffixMatchPattern (str ) && str .endsWith (".*" );
6060 }
6161
62- /** Return an {@link Automaton} that matches the given pattern. */
63- public static Automaton simpleMatchToAutomaton (String pattern ) {
62+ /**
63+ * Return a non-determinized {@link Automaton} that matches the given pattern.
64+ * WARNING: Use this method only when the resulting {@link Automaton} is used in contexts
65+ * that do not require determinism (e.g., checking the intersection of automatons).
66+ *
67+ * For pattern matching with {@link CharacterRunAutomaton}, a deterministic automaton is required.
68+ * In that case, use {@link Regex#simpleMatchToAutomaton} instead.
69+ */
70+ public static Automaton simpleMatchToNonDeterminizedAutomaton (String pattern ) {
6471 List <Automaton > automata = new ArrayList <>();
6572 int previous = 0 ;
6673 for (int i = pattern .indexOf ('*' ); i != -1 ; i = pattern .indexOf ('*' , i + 1 )) {
@@ -69,13 +76,24 @@ public static Automaton simpleMatchToAutomaton(String pattern) {
6976 previous = i + 1 ;
7077 }
7178 automata .add (Automata .makeString (pattern .substring (previous )));
72- return Operations .determinize (Operations .concatenate (automata ), Operations .DEFAULT_DETERMINIZE_WORK_LIMIT );
79+ return Operations .concatenate (automata );
80+ }
81+
82+ /** Return a deterministic {@link Automaton} that matches the given pattern. */
83+ public static Automaton simpleMatchToAutomaton (String pattern ) {
84+ return Operations .determinize (simpleMatchToNonDeterminizedAutomaton (pattern ), Operations .DEFAULT_DETERMINIZE_WORK_LIMIT );
7385 }
7486
7587 /**
76- * Return an Automaton that matches the union of the provided patterns.
88+ * Returns a non-deterministic {@link Automaton} that matches the union of the given patterns.
89+ *
90+ * WARNING: Use this method only when the resulting {@link Automaton} is used in contexts
91+ * that do not require determinism (e.g., checking the intersection of automatons).
92+ *
93+ * For pattern matching with {@link CharacterRunAutomaton}, a deterministic automaton is required.
94+ * In that case, use {@link Regex#simpleMatchToAutomaton} instead.
7795 */
78- public static Automaton simpleMatchToAutomaton (String ... patterns ) {
96+ public static Automaton simpleMatchToNonDeterminizedAutomaton (String ... patterns ) {
7997 if (patterns .length < 1 ) {
8098 throw new IllegalArgumentException ("There must be at least one pattern, zero given" );
8199 }
@@ -88,7 +106,7 @@ public static Automaton simpleMatchToAutomaton(String... patterns) {
88106 if (isSuffixWildcard (pattern ) && pattern .length () < 1000 ) {
89107 prefixes .add (new BytesRef (pattern .substring (0 , pattern .length () - 1 )));
90108 } else if (isSimpleMatchPattern (pattern ) || pattern .length () >= 1000 ) {
91- automata .add (simpleMatchToAutomaton (pattern ));
109+ automata .add (simpleMatchToNonDeterminizedAutomaton (pattern ));
92110 } else {
93111 simpleStrings .add (new BytesRef (pattern ));
94112 }
@@ -113,7 +131,14 @@ public static Automaton simpleMatchToAutomaton(String... patterns) {
113131 prefixAutomaton .add (Automata .makeAnyString ());
114132 automata .add (Operations .concatenate (prefixAutomaton ));
115133 }
116- return Operations .determinize (Operations .union (automata ), Operations .DEFAULT_DETERMINIZE_WORK_LIMIT );
134+ return Operations .union (automata );
135+ }
136+
137+ /**
138+ * Return a deterministic Automaton that matches the union of the provided patterns.
139+ */
140+ public static Automaton simpleMatchToAutomaton (String ... patterns ) {
141+ return Operations .determinize (simpleMatchToNonDeterminizedAutomaton (patterns ), Operations .DEFAULT_DETERMINIZE_WORK_LIMIT );
117142 }
118143
119144 /**
0 commit comments