Example #1
0
 /// <summary>Returns the string value of the field with the given name if any exist in
 /// this document, or null.  If multiple fields exist with this name, this
 /// method returns the first value added. If only binary fields with this name
 /// exist, returns null.
 /// </summary>
 public System.String Get(System.String name)
 {
     for (int i = 0; i < fields.Count; i++)
     {
         Fieldable field = fields[i];
         if (field.Name().Equals(name) && (!field.IsBinary()))
         {
             return(field.StringValue());
         }
     }
     return(null);
 }
Example #2
0
 /// <summary> Returns an array of bytes for the first (or only) field that has the name
 /// specified as the method parameter. This method will return <code>null</code>
 /// if no binary fields with the specified name are available.
 /// There may be non-binary fields with the same name.
 ///
 /// </summary>
 /// <param name="name">the name of the field.
 /// </param>
 /// <returns> a <code>byte[]</code> containing the binary field value or <code>null</code>
 /// </returns>
 public byte[] GetBinaryValue(System.String name)
 {
     for (int i = 0; i < fields.Count; i++)
     {
         Fieldable field = (Fieldable)fields[i];
         if (field.Name().Equals(name) && (field.IsBinary()))
         {
             return(field.BinaryValue());
         }
     }
     return(null);
 }
Example #3
0
        /// <summary> Returns an array of byte arrays for of the fields that have the name specified
        /// as the method parameter. This method will return <code>null</code> if no
        /// binary fields with the specified name are available.
        ///
        /// </summary>
        /// <param name="name">the name of the field
        /// </param>
        /// <returns> a  <code>byte[][]</code> of binary field values or <code>null</code>
        /// </returns>
        public byte[][] GetBinaryValues(System.String name)
        {
            System.Collections.IList result = new System.Collections.ArrayList();
            for (int i = 0; i < fields.Count; i++)
            {
                Fieldable field = (Fieldable)fields[i];
                if (field.Name().Equals(name) && (field.IsBinary()))
                {
                    byte[] byteArray       = field.BinaryValue();
                    byte[] resultByteArray = new byte[byteArray.Length];
                    for (int index = 0; index < byteArray.Length; index++)
                    {
                        resultByteArray[index] = (byte)byteArray[index];
                    }

                    result.Add(resultByteArray);
                }
            }

            if (result.Count == 0)
            {
                return(null);
            }

            System.Collections.ICollection c = result;
            System.Object[] objects          = new byte[result.Count][];

            System.Type     type = objects.GetType().GetElementType();
            System.Object[] objs = (System.Object[])Array.CreateInstance(type, c.Count);

            System.Collections.IEnumerator e = c.GetEnumerator();
            int ii = 0;

            while (e.MoveNext())
            {
                objs[ii++] = e.Current;
            }

            // If objects is smaller than c then do not return the new array in the parameter
            if (objects.Length >= c.Count)
            {
                objs.CopyTo(objects, 0);
            }

            return((byte[][])objs);
        }
Example #4
0
        /// <summary> Returns an array of values of the field specified as the method parameter.
        /// This method returns an empty array when there are no
        /// matching fields.  It never returns null.
        /// </summary>
        /// <param name="name">the name of the field
        /// </param>
        /// <returns> a <code>String[]</code> of field values
        /// </returns>
        public System.String[] GetValues(System.String name)
        {
            System.Collections.ArrayList result = new System.Collections.ArrayList();
            for (int i = 0; i < fields.Count; i++)
            {
                Fieldable field = (Fieldable)fields[i];
                if (field.Name().Equals(name) && (!field.IsBinary()))
                {
                    result.Add(field.StringValue());
                }
            }

            if (result.Count == 0)
            {
                return(NO_STRINGS);
            }

            return((System.String[])result.ToArray(typeof(System.String)));
        }
        public virtual void  TestLoadSize()
        {
            FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos);
            Document     doc;

            doc = reader.Doc(0, new AnonymousClassFieldSelector(this));
            Fieldable f1 = doc.GetFieldable(DocHelper.TEXT_FIELD_1_KEY);
            Fieldable f3 = doc.GetFieldable(DocHelper.TEXT_FIELD_3_KEY);
            Fieldable fb = doc.GetFieldable(DocHelper.LAZY_FIELD_BINARY_KEY);

            Assert.IsTrue(f1.IsBinary());
            Assert.IsTrue(!f3.IsBinary());
            Assert.IsTrue(fb.IsBinary());
            AssertSizeEquals(2 * DocHelper.FIELD_1_TEXT.Length, f1.BinaryValue());
            Assert.AreEqual(DocHelper.FIELD_3_TEXT, f3.StringValue());
            AssertSizeEquals(DocHelper.LAZY_FIELD_BINARY_BYTES.Length, fb.BinaryValue());

            reader.Close();
        }
Example #6
0
        /// <summary> Returns an array of byte arrays for of the fields that have the name specified
        /// as the method parameter.  This method returns an empty
        /// array when there are no matching fields.  It never
        /// returns null.
        ///
        /// </summary>
        /// <param name="name">the name of the field
        /// </param>
        /// <returns> a <code>byte[][]</code> of binary field values
        /// </returns>
        public byte[][] GetBinaryValues(System.String name)
        {
            List <byte[]> result = new List <byte[]>();

            for (int i = 0; i < fields.Count; i++)
            {
                Fieldable field = fields[i];
                if (field.Name().Equals(name) && (field.IsBinary()))
                {
                    result.Add(field.BinaryValue());
                }
            }

            if (result.Count == 0)
            {
                return(NO_BYTES);
            }

            return(result.ToArray());
        }
Example #7
0
        /// <summary> Returns an array of values of the field specified as the method parameter.
        /// This method returns an empty array when there are no
        /// matching fields.  It never returns null.
        /// </summary>
        /// <param name="name">the name of the field
        /// </param>
        /// <returns> a <code>String[]</code> of field values
        /// </returns>
        public string[] GetValues(System.String name)
        {
            List <string> result = new List <string>();

            for (int i = 0; i < fields.Count; i++)
            {
                Fieldable field = fields[i];
                if (field.Name().Equals(name) && (!field.IsBinary()))
                {
                    result.Add(field.StringValue());
                }
            }

            if (result.Count == 0)
            {
                return(NO_STRINGS);
            }

            return(result.ToArray());
        }
Example #8
0
        /// <summary> Returns an array of values of the field specified as the method parameter.
        /// This method returns an empty array when there are no
        /// matching fields.  It never returns null.
        /// </summary>
        /// <param name="name">the name of the field
        /// </param>
        /// <returns> a <code>String[]</code> of field values</returns>
        public System.String[] GetValues(System.String name)
        {
            System.Collections.ArrayList result = new System.Collections.ArrayList();
            for (int i = 0; i < fields.Count; i++)
            {
                Fieldable field = (Fieldable)fields[i];
                if (field.Name().Equals(name) && (!field.IsBinary()))
                {
                    result.Add(field.StringValue());
                }
            }
            /// This method returns an empty array when there are no
            /// matching fields.  It never returns null.

            if (result.Count == 0)
            {
                return(NO_STRINGS);
            }

            return((System.String[])(result.ToArray(typeof(System.String))));
        }
Example #9
0
        public static void  VerifyEquals(Document d1, Document d2)
        {
            System.Collections.IList ff1 = d1.GetFields();
            System.Collections.IList ff2 = d2.GetFields();

            SupportClass.CollectionsHelper.Sort(ff1, fieldNameComparator);
            SupportClass.CollectionsHelper.Sort(ff2, fieldNameComparator);

            if (ff1.Count != ff2.Count)
            {
                System.Console.Out.WriteLine(SupportClass.CollectionsHelper.CollectionToString(ff1));
                System.Console.Out.WriteLine(SupportClass.CollectionsHelper.CollectionToString(ff2));
                Assert.AreEqual(ff1.Count, ff2.Count);
            }


            for (int i = 0; i < ff1.Count; i++)
            {
                Fieldable f1 = (Fieldable)ff1[i];
                Fieldable f2 = (Fieldable)ff2[i];
                if (f1.IsBinary())
                {
                    System.Diagnostics.Debug.Assert(f2.IsBinary());
                    //TODO
                }
                else
                {
                    System.String s1 = f1.StringValue();
                    System.String s2 = f2.StringValue();
                    if (!s1.Equals(s2))
                    {
                        // print out whole doc on error
                        System.Console.Out.WriteLine(SupportClass.CollectionsHelper.CollectionToString(ff1));
                        System.Console.Out.WriteLine(SupportClass.CollectionsHelper.CollectionToString(ff2));
                        Assert.AreEqual(s1, s2);
                    }
                }
            }
        }