Esempio n. 1
0
        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);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public virtual void TestRegexps()
        {
            int num = AtLeast(1000);

            for (int i = 0; i < num; i++)
            {
                string reg = AutomatonTestUtil.RandomRegexp(Random);
                if (Verbose)
                {
                    Console.WriteLine("TEST: regexp=" + reg);
                }
                AssertSame(reg);
            }
        }
Esempio n. 3
0
        public virtual void TestRandomRegexps()
        {
            int iters = AtLeast(30);

            for (int i = 0; i < iters; i++)
            {
                CharacterRunAutomaton dfa = new CharacterRunAutomaton(AutomatonTestUtil.RandomAutomaton(Random()));
                bool     lowercase        = Random().NextBoolean();
                int      limit            = TestUtil.NextInt(Random(), 0, 500);
                Analyzer a = new AnalyzerAnonymousInnerClassHelper2(this, dfa, lowercase, limit);
                CheckRandomData(Random(), a, 100);
                a.Dispose();
            }
        }
Esempio n. 4
0
        public virtual void TestRegexps()
        {
            // we generate aweful regexps: good for testing.
            // but for preflex codec, the test can be very slow, so use less iterations.
            int num = Codec.Default.Name.Equals("Lucene3x") ? 100 * RANDOM_MULTIPLIER : AtLeast(1000);

            for (int i = 0; i < num; i++)
            {
                string reg = AutomatonTestUtil.RandomRegexp(Random());
                if (VERBOSE)
                {
                    Console.WriteLine("TEST: regexp=" + reg);
                }
                AssertSame(reg);
            }
        }
Esempio n. 5
0
        public virtual void TestRegexps()
        {
            // we generate aweful regexps: good for testing.
            // but for preflex codec, the test can be very slow, so use less iterations.
            int num = Codec.Default.Name.Equals("Lucene3x", StringComparison.Ordinal) ? 100 * RandomMultiplier : AtLeast(1000);

            for (int i = 0; i < num; i++)
            {
                string reg = AutomatonTestUtil.RandomRegexp(Random);
                if (Verbose)
                {
                    Console.WriteLine("TEST: regexp=" + reg);
                }
                AssertSame(reg);
            }
        }
Esempio n. 6
0
        public void TestRandomRegexps()
        {
            int iters = TEST_NIGHTLY ? AtLeast(30) : AtLeast(1);

            for (int i = 0; i < iters; i++)
            {
                CharacterRunAutomaton dfa = new CharacterRunAutomaton(AutomatonTestUtil.RandomAutomaton(Random) /*, int.MaxValue*/);
                bool     lowercase        = Random.nextBoolean();
                int      limit            = TestUtil.NextInt32(Random, 0, 500);
                Analyzer a = Analyzer.NewAnonymous(createComponents: (fieldName, reader) => {
                    Tokenizer t = new MockTokenizer(reader, dfa, lowercase, limit);
                    return(new TokenStreamComponents(t, t));
                });
                CheckRandomData(Random, a, 100);
                a.Dispose();
            }
        }
Esempio n. 7
0
        public virtual void TestIntersect()
        {
            for (int i = 0; i < numIterations; i++)
            {
                string                   reg       = AutomatonTestUtil.RandomRegexp(Random);
                Automaton                automaton = (new RegExp(reg, RegExpSyntax.NONE)).ToAutomaton();
                CompiledAutomaton        ca        = new CompiledAutomaton(automaton, SpecialOperations.IsFinite(automaton), false);
                TermsEnum                te        = MultiFields.GetTerms(reader, "field").Intersect(ca, null);
                Automaton                expected  = BasicOperations.Intersection(termsAutomaton, automaton);
                JCG.SortedSet <BytesRef> found     = new JCG.SortedSet <BytesRef>();
                while (te.Next() != null)
                {
                    found.Add(BytesRef.DeepCopyOf(te.Term));
                }

                Automaton actual = BasicAutomata.MakeStringUnion(found);
                Assert.IsTrue(BasicOperations.SameLanguage(expected, actual));
            }
        }
Esempio n. 8
0
        public void TestRandomRegexps()
        {
            //int iters = TestNightly ? AtLeast(30) : AtLeast(1);
            // LUCENENET specific - reduced Nightly iterations from 30 to 15
            // to keep it under the 1 hour free limit of Azure DevOps
            int iters = TestNightly ? AtLeast(15) : AtLeast(1);

            for (int i = 0; i < iters; i++)
            {
                CharacterRunAutomaton dfa = new CharacterRunAutomaton(AutomatonTestUtil.RandomAutomaton(Random) /*, int.MaxValue*/);
                bool     lowercase        = Random.NextBoolean();
                int      limit            = TestUtil.NextInt32(Random, 0, 500);
                Analyzer a = Analyzer.NewAnonymous(createComponents: (fieldName, reader) => {
                    Tokenizer t = new MockTokenizer(reader, dfa, lowercase, limit);
                    return(new TokenStreamComponents(t, t));
                });
                CheckRandomData(Random, a, 100);
                a.Dispose();
            }
        }
Esempio n. 9
0
        public virtual void TestHashCodeWithThreads()
        {
            AutomatonQuery[] queries = new AutomatonQuery[1000];
            for (int i = 0; i < queries.Length; i++)
            {
                queries[i] = new AutomatonQuery(new Term("bogus", "bogus"), AutomatonTestUtil.RandomAutomaton(Random()));
            }
            CountdownEvent startingGun = new CountdownEvent(1);
            int            numThreads  = TestUtil.NextInt(Random(), 2, 5);

            ThreadClass[] threads = new ThreadClass[numThreads];
            for (int threadID = 0; threadID < numThreads; threadID++)
            {
                ThreadClass thread = new ThreadAnonymousInnerClassHelper(this, queries, startingGun);
                threads[threadID] = thread;
                thread.Start();
            }
            startingGun.Signal();
            foreach (ThreadClass thread in threads)
            {
                thread.Join();
            }
        }
Esempio n. 10
0
        // following code is almost an exact dup of code from TestDuelingCodecs: sorry!

        public virtual void AssertTerms(Terms leftTerms, Terms rightTerms, bool deep)
        {
            if (leftTerms == null || rightTerms == null)
            {
                Assert.IsNull(leftTerms);
                Assert.IsNull(rightTerms);
                return;
            }
            AssertTermsStatistics(leftTerms, rightTerms);

            // NOTE: we don't assert hasOffsets/hasPositions/hasPayloads because they are allowed to be different

            TermsEnum leftTermsEnum  = leftTerms.GetIterator(null);
            TermsEnum rightTermsEnum = rightTerms.GetIterator(null);

            AssertTermsEnum(leftTermsEnum, rightTermsEnum, true);

            AssertTermsSeeking(leftTerms, rightTerms);

            if (deep)
            {
                int numIntersections = AtLeast(3);
                for (int i = 0; i < numIntersections; i++)
                {
                    string            re        = AutomatonTestUtil.RandomRegexp(Random);
                    CompiledAutomaton automaton = new CompiledAutomaton((new RegExp(re, RegExpSyntax.NONE)).ToAutomaton());
                    if (automaton.Type == CompiledAutomaton.AUTOMATON_TYPE.NORMAL)
                    {
                        // TODO: test start term too
                        TermsEnum leftIntersection  = leftTerms.Intersect(automaton, null);
                        TermsEnum rightIntersection = rightTerms.Intersect(automaton, null);
                        AssertTermsEnum(leftIntersection, rightIntersection, Rarely());
                    }
                }
            }
        }
Esempio n. 11
0
        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);
            }
        }