public virtual void TestBasicAutomata() { AssertAutomatonHits(0, BasicAutomata.MakeEmpty()); AssertAutomatonHits(0, BasicAutomata.MakeEmptyString()); AssertAutomatonHits(2, BasicAutomata.MakeAnyChar()); AssertAutomatonHits(3, BasicAutomata.MakeAnyString()); AssertAutomatonHits(2, BasicAutomata.MakeString("doc")); AssertAutomatonHits(1, BasicAutomata.MakeChar('a')); AssertAutomatonHits(2, BasicAutomata.MakeCharRange('a', 'b')); AssertAutomatonHits(2, BasicAutomata.MakeInterval(1233, 2346, 0)); AssertAutomatonHits(1, BasicAutomata.MakeInterval(0, 2000, 0)); AssertAutomatonHits(2, BasicOperations.Union(BasicAutomata.MakeChar('a'), BasicAutomata.MakeChar('b'))); AssertAutomatonHits(0, BasicOperations.Intersection(BasicAutomata.MakeChar('a'), BasicAutomata.MakeChar('b'))); AssertAutomatonHits(1, BasicOperations.Minus(BasicAutomata.MakeCharRange('a', 'b'), BasicAutomata.MakeChar('a'))); }
/// <summary> /// Convert Lucene wildcard syntax into an automaton. /// <para/> /// @lucene.internal /// </summary> public static Automaton ToAutomaton(Term wildcardquery) { IList <Automaton> automata = new JCG.List <Automaton>(); string wildcardText = wildcardquery.Text; for (int i = 0; i < wildcardText.Length;) { int c = Character.CodePointAt(wildcardText, i); int length = Character.CharCount(c); switch (c) { case WILDCARD_STRING: automata.Add(BasicAutomata.MakeAnyString()); break; case WILDCARD_CHAR: automata.Add(BasicAutomata.MakeAnyChar()); break; case WILDCARD_ESCAPE: // add the next codepoint instead, if it exists if (i + length < wildcardText.Length) { int nextChar = Character.CodePointAt(wildcardText, i + length); length += Character.CharCount(nextChar); automata.Add(BasicAutomata.MakeChar(nextChar)); break; } // else fallthru, lenient parsing with a trailing \ goto default; default: automata.Add(BasicAutomata.MakeChar(c)); break; } i += length; } return(BasicOperations.Concatenate(automata)); }