Example #1
0
		public virtual void  TestEquals()
		{
			Term base_Renamed = new Term("same", "same");
			Term same = new Term("same", "same");
			Term differentField = new Term("different", "same");
			Term differentText = new Term("same", "different");
			System.String differentType = "AString";
			Assert.AreEqual(base_Renamed, base_Renamed);
			Assert.AreEqual(base_Renamed, same);
			Assert.IsFalse(base_Renamed.Equals(differentField));
			Assert.IsFalse(base_Renamed.Equals(differentText));
			Assert.IsFalse(base_Renamed.Equals(differentType));
		}
Example #2
0
 public virtual void TestEquals()
 {
     Term @base = new Term("same", "same");
     Term same = new Term("same", "same");
     Term differentField = new Term("different", "same");
     Term differentText = new Term("same", "different");
     const string differentType = "AString";
     Assert.AreEqual(@base, @base);
     Assert.AreEqual(@base, same);
     Assert.IsFalse(@base.Equals(differentField));
     Assert.IsFalse(@base.Equals(differentText));
     Assert.IsFalse(@base.Equals(differentType));
 }
Example #3
0
 public virtual void TestEquals()
 {
     Term @base = new Term("same", "same");
     Term same = new Term("same", "same");
     Term differentField = new Term("different", "same");
     Term differentText = new Term("same", "different");
     const string differentType = "AString";
     Assert.AreEqual(@base, @base);
     Assert.AreEqual(@base, same);
     Assert.IsFalse(@base.Equals(differentField));
     Assert.IsFalse(@base.Equals(differentText));
     Assert.IsFalse(@base.Equals(differentType));
 }
Example #4
0
        public virtual void  TestEquals()
        {
            Term base_Renamed   = new Term("same", "same");
            Term same           = new Term("same", "same");
            Term differentField = new Term("different", "same");
            Term differentText  = new Term("same", "different");

            System.String differentType = "AString";
            Assert.AreEqual(base_Renamed, base_Renamed);
            Assert.AreEqual(base_Renamed, same);
            Assert.IsFalse(base_Renamed.Equals(differentField));
            Assert.IsFalse(base_Renamed.Equals(differentText));
            Assert.IsFalse(base_Renamed.Equals(differentType));
        }
Example #5
0
            /// <summary>
            /// add a term </summary>
            public virtual void Add(Term term)
            {
                Debug.Assert(LastTerm.Equals(new Term("")) || term.CompareTo(LastTerm) > 0);

                try
                {
                    int prefix = SharedPrefix(LastTerm.Bytes_Renamed, term.Bytes_Renamed);
                    int suffix = term.Bytes_Renamed.Length - prefix;
                    if (term.Field_Renamed.Equals(LastTerm.Field_Renamed))
                    {
                        Output.WriteVInt(prefix << 1);
                    }
                    else
                    {
                        Output.WriteVInt(prefix << 1 | 1);
                        Output.WriteString(term.Field_Renamed);
                    }
                    Output.WriteVInt(suffix);
                    Output.WriteBytes(term.Bytes_Renamed.Bytes, term.Bytes_Renamed.Offset + prefix, suffix);
                    LastTerm.Bytes_Renamed.CopyBytes(term.Bytes_Renamed);
                    LastTerm.Field_Renamed = term.Field_Renamed;
                }
                catch (IOException e)
                {
                    throw new Exception(e.Message, e);
                }
            }
Example #6
0
            /// <summary>
            /// add a term </summary>
            public virtual void Add(Term term)
            {
                Debug.Assert(lastTerm.Equals(new Term("")) || term.CompareTo(lastTerm) > 0);

                try
                {
                    int prefix = SharedPrefix(lastTerm.Bytes, term.Bytes);
                    int suffix = term.Bytes.Length - prefix;
                    if (term.Field.Equals(lastTerm.Field, StringComparison.Ordinal))
                    {
                        output.WriteVInt32(prefix << 1);
                    }
                    else
                    {
                        output.WriteVInt32(prefix << 1 | 1);
                        output.WriteString(term.Field);
                    }
                    output.WriteVInt32(suffix);
                    output.WriteBytes(term.Bytes.Bytes, term.Bytes.Offset + prefix, suffix);
                    lastTerm.Bytes.CopyBytes(term.Bytes);
                    lastTerm.Field = term.Field;
                }
                catch (IOException e)
                {
                    throw new Exception(e.ToString(), e);
                }
            }
Example #7
0
        public virtual void  TestEquals()
        {
            Term original = new Term("same", "same");
            Term same = new Term("same", "same");
            Term differentField = new Term("different", "same");
            Term differentText = new Term("same", "different");
            System.String differentType = "AString";

            Assert.AreEqual(original, original);
            Assert.AreEqual(original, same);

            Assert.AreNotEqual(original, null);
            Assert.IsTrue(null == null);

            Assert.IsFalse(original.Equals(differentField));
            Assert.IsFalse(original.Equals(differentText));
            Assert.IsFalse(original.Equals(differentType));
        }
Example #8
0
        public virtual void  TestEquals()
        {
            Term original       = new Term("same", "same");
            Term same           = new Term("same", "same");
            Term differentField = new Term("different", "same");
            Term differentText  = new Term("same", "different");

            System.String differentType = "AString";

            Assert.AreEqual(original, original);
            Assert.AreEqual(original, same);

            Assert.AreNotEqual(original, null);
            Assert.IsTrue(null == null);

            Assert.IsFalse(original.Equals(differentField));
            Assert.IsFalse(original.Equals(differentText));
            Assert.IsFalse(original.Equals(differentType));
        }
 protected internal override bool TermCompare(Term term)
 {
     if (term.Equals(singleTerm))
     {
         return true;
     }
     else
     {
         _endEnum = true;
         return false;
     }
 }
Example #10
0
        public override bool Equals(System.Object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (!base.Equals(obj))
            {
                return(false);
            }
            if (GetType() != obj.GetType())
            {
                return(false);
            }
            FuzzyQuery other = (FuzzyQuery)obj;

            if (BitConverter.ToInt32(BitConverter.GetBytes(minimumSimilarity), 0) != BitConverter.ToInt32(BitConverter.GetBytes(other.minimumSimilarity), 0))
            {
                return(false);
            }
            if (prefixLength != other.prefixLength)
            {
                return(false);
            }
            if (Term == null)
            {
                if (other.Term != null)
                {
                    return(false);
                }
            }
            else if (!Term.Equals(other.Term))
            {
                return(false);
            }
            return(true);
        }
Example #11
0
        // FIXME: OG: remove hard-coded file names
        public static void  Test()
        {
            System.IO.FileInfo file = new System.IO.FileInfo("words.txt");
            System.Console.Out.WriteLine(" reading word file containing " + file.Length + " bytes");

            System.DateTime start = System.DateTime.Now;

            System.Collections.ArrayList keys = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            System.IO.FileStream         ws   = new System.IO.FileStream(file.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.StreamReader       wr   = new System.IO.StreamReader(new System.IO.StreamReader(ws, System.Text.Encoding.Default).BaseStream, new System.IO.StreamReader(ws, System.Text.Encoding.Default).CurrentEncoding);

            for (System.String key = wr.ReadLine(); key != null; key = wr.ReadLine())
            {
                keys.Add(new Term("word", key));
            }
            wr.Close();

            System.DateTime end = System.DateTime.Now;

            System.Console.Out.Write(end.Ticks - start.Ticks);
            System.Console.Out.WriteLine(" milliseconds to read " + keys.Count + " words");

            start = System.DateTime.Now;

            System.Random gen = new System.Random((System.Int32) 1251971);
            long          fp  = (gen.Next() & 0xF) + 1;
            long          pp  = (gen.Next() & 0xF) + 1;

            int[]  docFreqs     = new int[keys.Count];
            long[] freqPointers = new long[keys.Count];
            long[] proxPointers = new long[keys.Count];
            for (int i = 0; i < keys.Count; i++)
            {
                docFreqs[i]     = (gen.Next() & 0xF) + 1;
                freqPointers[i] = fp;
                proxPointers[i] = pp;
                fp += (gen.Next() & 0xF) + 1;
                ;
                pp += (gen.Next() & 0xF) + 1;
                ;
            }

            end = System.DateTime.Now;

            System.Console.Out.Write(end.Ticks - start.Ticks);
            System.Console.Out.WriteLine(" milliseconds to generate values");

            start = System.DateTime.Now;

            Directory  store = FSDirectory.GetDirectory("test.store", true);
            FieldInfos fis   = new FieldInfos();

            TermInfosWriter writer = new TermInfosWriter(store, "words", fis);

            fis.Add("word", false);

            for (int i = 0; i < keys.Count; i++)
            {
                writer.Add((Term)keys[i], new TermInfo(docFreqs[i], freqPointers[i], proxPointers[i]));
            }

            writer.Close();

            end = System.DateTime.Now;

            System.Console.Out.Write(end.Ticks - start.Ticks);
            System.Console.Out.WriteLine(" milliseconds to write table");

            System.Console.Out.WriteLine(" table occupies " + store.FileLength("words.tis") + " bytes");

            start = System.DateTime.Now;

            TermInfosReader reader = new TermInfosReader(store, "words", fis);

            end = System.DateTime.Now;

            System.Console.Out.Write(end.Ticks - start.Ticks);
            System.Console.Out.WriteLine(" milliseconds to open table");

            start = System.DateTime.Now;

            SegmentTermEnum enumerator = reader.Terms();

            for (int i = 0; i < keys.Count; i++)
            {
                enumerator.Next();
                Term key = (Term)keys[i];
                if (!key.Equals(enumerator.Term()))
                {
                    throw new System.Exception("wrong term: " + enumerator.Term() + ", expected: " + key + " at " + i);
                }
                TermInfo ti = enumerator.TermInfo();
                if (ti.docFreq != docFreqs[i])
                {
                    throw new System.Exception("wrong value: " + System.Convert.ToString(ti.docFreq, 16) + ", expected: " + System.Convert.ToString(docFreqs[i], 16) + " at " + i);
                }
                if (ti.freqPointer != freqPointers[i])
                {
                    throw new System.Exception("wrong value: " + System.Convert.ToString(ti.freqPointer, 16) + ", expected: " + System.Convert.ToString(freqPointers[i], 16) + " at " + i);
                }
                if (ti.proxPointer != proxPointers[i])
                {
                    throw new System.Exception("wrong value: " + System.Convert.ToString(ti.proxPointer, 16) + ", expected: " + System.Convert.ToString(proxPointers[i], 16) + " at " + i);
                }
            }

            end = System.DateTime.Now;

            System.Console.Out.Write(end.Ticks - start.Ticks);
            System.Console.Out.WriteLine(" milliseconds to iterate over " + keys.Count + " words");

            start = System.DateTime.Now;

            for (int i = 0; i < keys.Count; i++)
            {
                Term     key = (Term)keys[i];
                TermInfo ti  = reader.Get(key);
                if (ti.docFreq != docFreqs[i])
                {
                    throw new System.Exception("wrong value: " + System.Convert.ToString(ti.docFreq, 16) + ", expected: " + System.Convert.ToString(docFreqs[i], 16) + " at " + i);
                }
                if (ti.freqPointer != freqPointers[i])
                {
                    throw new System.Exception("wrong value: " + System.Convert.ToString(ti.freqPointer, 16) + ", expected: " + System.Convert.ToString(freqPointers[i], 16) + " at " + i);
                }
                if (ti.proxPointer != proxPointers[i])
                {
                    throw new System.Exception("wrong value: " + System.Convert.ToString(ti.proxPointer, 16) + ", expected: " + System.Convert.ToString(proxPointers[i], 16) + " at " + i);
                }
            }

            end = System.DateTime.Now;

            System.Console.Out.Write((end.Ticks - start.Ticks) / (float)keys.Count);
            System.Console.Out.WriteLine(" average milliseconds per lookup");

            TermEnum e = reader.Terms(new Term("word", "azz"));

            System.Console.Out.WriteLine("Word after azz is " + e.Term().text);

            reader.Close();

            store.Close();
        }