Exemplo n.º 1
0
        private void TestTerms(string[] terms)
        {
            CompiledAutomaton c = Build(terms);

            BytesRef[] termBytes = new BytesRef[terms.Length];
            for (int idx = 0; idx < terms.Length; idx++)
            {
                termBytes[idx] = new BytesRef(terms[idx]);
            }
            Array.Sort(termBytes);

            if (VERBOSE)
            {
                Console.WriteLine("\nTEST: terms in unicode order");
                foreach (BytesRef t in termBytes)
                {
                    Console.WriteLine("  " + t.Utf8ToString());
                }
                //System.out.println(c.utf8.toDot());
            }

            for (int iter = 0; iter < 100 * RANDOM_MULTIPLIER; iter++)
            {
                string s = Random.Next(10) == 1 ? terms[Random.Next(terms.Length)] : RandomString();
                if (VERBOSE)
                {
                    Console.WriteLine("\nTEST: floor(" + s + ")");
                }
                int    loc = Array.BinarySearch(termBytes, new BytesRef(s));
                string expected;
                if (loc >= 0)
                {
                    expected = s;
                }
                else
                {
                    // term doesn't exist
                    loc = -(loc + 1);
                    if (loc == 0)
                    {
                        expected = null;
                    }
                    else
                    {
                        expected = termBytes[loc - 1].Utf8ToString();
                    }
                }
                if (VERBOSE)
                {
                    Console.WriteLine("  expected=" + expected);
                }
                TestFloor(c, s, expected);
            }
        }
Exemplo n.º 2
0
        public virtual void TestBasic()
        {
            CompiledAutomaton c = Build("fob", "foo", "goo");

            TestFloor(c, "goo", "goo");
            TestFloor(c, "ga", "foo");
            TestFloor(c, "g", "foo");
            TestFloor(c, "foc", "fob");
            TestFloor(c, "foz", "foo");
            TestFloor(c, "f", null);
            TestFloor(c, "", null);
            TestFloor(c, "aa", null);
            TestFloor(c, "zzz", "goo");
        }
 private void TestFloor(CompiledAutomaton c, string input, string expected)
 {
     BytesRef b = new BytesRef(input);
     BytesRef result = c.Floor(b, b);
     if (expected == null)
     {
         Assert.IsNull(result);
     }
     else
     {
         Assert.IsNotNull(result);
         Assert.AreEqual(result, new BytesRef(expected), "actual=" + result.Utf8ToString() + " vs expected=" + expected + " (input=" + input + ")");
     }
 }
Exemplo n.º 4
0
        private void TestFloor(CompiledAutomaton c, string input, string expected)
        {
            BytesRef b      = new BytesRef(input);
            BytesRef result = c.Floor(b, b);

            if (expected == null)
            {
                Assert.IsNull(result);
            }
            else
            {
                Assert.IsNotNull(result);
                Assert.AreEqual(result, new BytesRef(expected), "actual=" + result.Utf8ToString() + " vs expected=" + expected + " (input=" + input + ")");
            }
        }
Exemplo n.º 5
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (this.GetType() != obj.GetType())
            {
                return(false);
            }
            CompiledAutomaton other = (CompiledAutomaton)obj;

            if (Type != other.Type)
            {
                return(false);
            }
            if (Type == AUTOMATON_TYPE.SINGLE || Type == AUTOMATON_TYPE.PREFIX)
            {
                if (!Term.Equals(other.Term))
                {
                    return(false);
                }
            }
            else if (Type == AUTOMATON_TYPE.NORMAL)
            {
                if (!RunAutomaton.Equals(other.RunAutomaton))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 6
0
        public virtual void TestIntersect()
        {
            for (int i = 0; i < NumIterations; i++)
            {
                string reg = AutomatonTestUtil.RandomRegexp(Random());
                Automaton automaton = (new RegExp(reg, RegExp.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);
                SortedSet<BytesRef> found = new SortedSet<BytesRef>();
                while (te.Next() != null)
                {
                    found.Add(BytesRef.DeepCopyOf(te.Term()));
                }

                Automaton actual = BasicAutomata.MakeStringUnion(found);
                Assert.IsTrue(BasicOperations.SameLanguage(expected, actual));
            }
        }
 public override TermsEnum Intersect(CompiledAutomaton compiled, BytesRef startTerm)
 {
     return new SortingTermsEnum(@in.Intersect(compiled, startTerm), docMap, indexOptions);
 }