public virtual void TestSeeking() { for (int i = 0; i < numIterations; i++) { string reg = AutomatonTestUtil.RandomRegexp(Random); Automaton automaton = (new RegExp(reg, RegExpSyntax.NONE)).ToAutomaton(); TermsEnum te = MultiFields.GetTerms(reader, "field").GetIterator(null); IList <BytesRef> unsortedTerms = new List <BytesRef>(terms); unsortedTerms.Shuffle(Random); foreach (BytesRef term in unsortedTerms) { if (BasicOperations.Run(automaton, term.Utf8ToString())) { // term is accepted if (Random.NextBoolean()) { // seek exact Assert.IsTrue(te.SeekExact(term)); } else { // seek ceil Assert.AreEqual(SeekStatus.FOUND, te.SeekCeil(term)); Assert.AreEqual(term, te.Term); } } } } }
public virtual void TestFiniteVersusInfinite() { for (int i = 0; i < numIterations; i++) { string reg = AutomatonTestUtil.RandomRegexp(Random); Automaton automaton = (new RegExp(reg, RegExpSyntax.NONE)).ToAutomaton(); IList <BytesRef> matchedTerms = new List <BytesRef>(); foreach (BytesRef t in terms) { if (BasicOperations.Run(automaton, t.Utf8ToString())) { matchedTerms.Add(t); } } Automaton alternate = BasicAutomata.MakeStringUnion(matchedTerms); //System.out.println("match " + matchedTerms.Size() + " " + alternate.getNumberOfStates() + " states, sigma=" + alternate.getStartPoints().length); //AutomatonTestUtil.minimizeSimple(alternate); //System.out.println("minmize done"); AutomatonQuery a1 = new AutomatonQuery(new Term("field", ""), automaton); AutomatonQuery a2 = new AutomatonQuery(new Term("field", ""), alternate); CheckHits.CheckEqual(a1, searcher.Search(a1, 25).ScoreDocs, searcher.Search(a2, 25).ScoreDocs); } }