public virtual int Compare(System.Object o1, System.Object o2) { if (o1 == o2) return 0; f1 = (Fieldable)o1; f2 = (Fieldable)o2; return String.CompareOrdinal(f1.Name() + f1.StringValue(), f2.Name() + f2.StringValue()); }
/// <summary> /// Gets the value stored in the fieldable. /// </summary> /// <remarks> /// This method is never called if the value is not stored in the index. /// </remarks> /// <param name="fieldable">The fieldable containaing the value.</param> /// <returns>The .NET value that was stored in the field</returns> public object GetValue(Fieldable fieldable) { if (string.IsNullOrEmpty(fieldable.StringValue())) { return(null); } return(GetValueInternal((NumericField)fieldable)); }
internal virtual void ValidateField(Fieldable f) { System.String val = f.StringValue(); if (!val.StartsWith("^") || !val.EndsWith("$")) { throw new System.SystemException("Invalid field:" + f.ToString() + " val=" + val); } }
/// <summary> /// Sets the value in the field. This not only possibly sets the stored value but also the /// content to be possibly indexed and analyzed. /// </summary> /// <param name="fieldable">The field in which to set the value</param> /// <param name="value">The .NET value to set in the field</param> /// <returns>true if the value was set; false if the value was not set and the field should be ignored (not added to a document)</returns> public bool SetValue(Fieldable fieldable, object value) { if (value == null) { return(false); } SetValueInternal((NumericField)fieldable, (T)value); return(true); }
/// <summary> <p/>Removes all fields with the given name from the document. /// If there is no field with the specified name, the document remains unchanged.<p/> /// <p/> Note that the removeField(s) methods like the add method only make sense /// prior to adding a document to an index. These methods cannot /// be used to change the content of an existing index! In order to achieve this, /// a document has to be deleted from an index and a new changed version of that /// document has to be added.<p/> /// </summary> public void RemoveFields(System.String name) { for (int i = fields.Count - 1; i >= 0; i--) { Fieldable field = (Fieldable)fields[i]; if (field.Name().Equals(name)) { fields.RemoveAt(i); } } }
/// <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); }
/// <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); }
internal virtual void loadDoc(IndexReader ir) { // beware of deleted docs in the future Document doc = ir.Document(rand.Next(ir.MaxDoc()), new AnonymousClassFieldSelector(this)); System.Collections.IList fields = doc.GetFields(); for (int i = 0; i < fields.Count; i++) { Fieldable f = (Fieldable)fields[i]; Enclosing_Instance.ValidateField(f); } }
/// <summary>Returns a field with the given name if any exist in this document, or /// null. If multiple fields exists with this name, this method returns the /// first value added. /// </summary> public Fieldable GetFieldable(System.String name) { for (int i = 0; i < fields.Count; i++) { Fieldable field = (Fieldable)fields[i]; if (field.Name().Equals(name)) { return(field); } } return(null); }
/// <summary> <p/>Removes field with the specified name from the document. /// If multiple fields exist with this name, this method removes the first field that has been added. /// If there is no field with the specified name, the document remains unchanged.<p/> /// <p/> Note that the removeField(s) methods like the add method only make sense /// prior to adding a document to an index. These methods cannot /// be used to change the content of an existing index! In order to achieve this, /// a document has to be deleted from an index and a new changed version of that /// document has to be added.<p/> /// </summary> public void RemoveField(System.String name) { System.Collections.IEnumerator it = fields.GetEnumerator(); while (it.MoveNext()) { Fieldable field = (Fieldable)it.Current; if (field.Name().Equals(name)) { fields.Remove(field); return; } } }
/// <summary>Prints the fields of a document for human consumption. </summary> public override System.String ToString() { System.Text.StringBuilder buffer = new System.Text.StringBuilder(); buffer.Append("Document<"); for (int i = 0; i < fields.Count; i++) { Fieldable field = (Fieldable)fields[i]; buffer.Append(field.ToString()); if (i != fields.Count - 1) { buffer.Append(" "); } } buffer.Append(">"); return(buffer.ToString()); }
/// <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); }
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(); }
/// <summary> Returns an array of {@link Fieldable}s with the given name. /// 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>Fieldable[]</code> array /// </returns> public Fieldable[] GetFieldables(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)) { result.Add(field); } } if (result.Count == 0) { return(NO_FIELDABLES); } return((Fieldable[])result.ToArray(typeof(Fieldable))); }
/// <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 DoTest(int[] docs) { if (dataset.Count == 0) { for (int i = 0; i < data.Length; i++) { dataset.Add(data[i], data[i]); } } Directory dir = MakeIndex(); IndexReader reader = IndexReader.Open(dir); for (int i = 0; i < docs.Length; i++) { Document d = reader.Document(docs[i], SELECTOR); d.Get(MAGIC_FIELD); System.Collections.IList fields = d.GetFields(); for (System.Collections.IEnumerator fi = fields.GetEnumerator(); fi.MoveNext();) { Fieldable f = null; try { f = (Fieldable)fi.Current; System.String fname = f.Name(); System.String fval = f.StringValue(); Assert.IsNotNull(docs[i] + " FIELD: " + fname, fval); System.String[] vals = fval.Split('#'); if (!dataset.Contains(vals[0]) || !dataset.Contains(vals[1])) { Assert.Fail("FIELD:" + fname + ",VAL:" + fval); } } catch (System.Exception e) { throw new Exception(docs[i] + " WTF: " + f.Name(), e); } } } reader.Close(); }
/// <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()); }
/// <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()); }
/// <summary> Returns an array of {@link Fieldable}s with the given name. /// 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>Fieldable[]</code> array /// </returns> public Fieldable[] GetFieldables(System.String name) { List <Fieldable> result = new List <Fieldable>(); for (int i = 0; i < fields.Count; i++) { Fieldable field = fields[i]; if (field.Name().Equals(name)) { result.Add(field); } } if (result.Count == 0) { return(NO_FIELDABLES); } return(result.ToArray()); }
/// <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)))); }
public virtual void Test() { Assert.IsTrue(dir != null); Assert.IsTrue(fieldInfos != null); FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos); Assert.IsTrue(reader != null); Assert.IsTrue(reader.Size() == 1); Document doc = reader.Doc(0, null); Assert.IsTrue(doc != null); Assert.IsTrue(doc.GetField(DocHelper.TEXT_FIELD_1_KEY) != null); Fieldable field = doc.GetField(DocHelper.TEXT_FIELD_2_KEY); Assert.IsTrue(field != null); Assert.IsTrue(field.IsTermVectorStored() == true); Assert.IsTrue(field.IsStoreOffsetWithTermVector() == true); Assert.IsTrue(field.IsStorePositionWithTermVector() == true); Assert.IsTrue(field.GetOmitNorms() == false); Assert.IsTrue(field.GetOmitTf() == false); field = doc.GetField(DocHelper.TEXT_FIELD_3_KEY); Assert.IsTrue(field != null); Assert.IsTrue(field.IsTermVectorStored() == false); Assert.IsTrue(field.IsStoreOffsetWithTermVector() == false); Assert.IsTrue(field.IsStorePositionWithTermVector() == false); Assert.IsTrue(field.GetOmitNorms() == true); Assert.IsTrue(field.GetOmitTf() == false); field = doc.GetField(DocHelper.NO_TF_KEY); Assert.IsTrue(field != null); Assert.IsTrue(field.IsTermVectorStored() == false); Assert.IsTrue(field.IsStoreOffsetWithTermVector() == false); Assert.IsTrue(field.IsStorePositionWithTermVector() == false); Assert.IsTrue(field.GetOmitNorms() == false); Assert.IsTrue(field.GetOmitTf() == true); reader.Close(); }
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); } } } }
public virtual void TestLazyFieldsAfterClose() { Assert.IsTrue(dir != null); Assert.IsTrue(fieldInfos != null); FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos); Assert.IsTrue(reader != null); Assert.IsTrue(reader.Size() == 1); System.Collections.Hashtable loadFieldNames = new System.Collections.Hashtable(); SupportClass.CollectionsHelper.AddIfNotContains(loadFieldNames, DocHelper.TEXT_FIELD_1_KEY); SupportClass.CollectionsHelper.AddIfNotContains(loadFieldNames, DocHelper.TEXT_FIELD_UTF1_KEY); System.Collections.Hashtable lazyFieldNames = new System.Collections.Hashtable(); SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.LARGE_LAZY_FIELD_KEY); SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.LAZY_FIELD_KEY); SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.LAZY_FIELD_BINARY_KEY); SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.TEXT_FIELD_UTF2_KEY); SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.COMPRESSED_TEXT_FIELD_2_KEY); SetBasedFieldSelector fieldSelector = new SetBasedFieldSelector(loadFieldNames, lazyFieldNames); Document doc = reader.Doc(0, fieldSelector); Assert.IsTrue(doc != null, "doc is null and it shouldn't be"); Fieldable field = doc.GetFieldable(DocHelper.LAZY_FIELD_KEY); Assert.IsTrue(field != null, "field is null and it shouldn't be"); Assert.IsTrue(field.IsLazy(), "field is not lazy and it should be"); reader.Close(); try { field.StringValue(); Assert.Fail("did not hit AlreadyClosedException as expected"); } catch (AlreadyClosedException e) { // expected } }
/// <summary> /// Parses a string value into the correct type. /// </summary> /// <param name="field">The field containing the value</param> /// <param name="mappingType">The expected type of the value</param> /// <returns>The parsed value</returns> /// <exception cref="TypeNotSupportedException">If the type of the value is not supported</exception> public object ParseValue(Fieldable field, Type mappingType) { var type = TypeFactory.GetFor(mappingType); return(type.GetValue(field)); }
/// <summary> <p>Adds a field to a document. Several fields may be added with /// the same name. In this case, if the fields are indexed, their text is /// treated as though appended for the purposes of search.</p> /// <p> Note that add like the removeField(s) methods only makes sense /// prior to adding a document to an index. These methods cannot /// be used to change the content of an existing index! In order to achieve this, /// a document has to be deleted from an index and a new changed version of that /// document has to be added.</p> /// </summary> public void Add(Fieldable field) { fields.Add(field); }
/// <summary> <p/>Adds a field to a document. Several fields may be added with /// the same name. In this case, if the fields are indexed, their text is /// treated as though appended for the purposes of search.<p/> /// <p/> Note that add like the removeField(s) methods only makes sense /// prior to adding a document to an index. These methods cannot /// be used to change the content of an existing index! In order to achieve this, /// a document has to be deleted from an index and a new changed version of that /// document has to be added.<p/> /// </summary> public void Add(Fieldable field) { fields.Add(field); }
public virtual void TestLazyFields() { Assert.IsTrue(dir != null); Assert.IsTrue(fieldInfos != null); FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos); Assert.IsTrue(reader != null); Assert.IsTrue(reader.Size() == 1); System.Collections.Hashtable loadFieldNames = new System.Collections.Hashtable(); SupportClass.CollectionsHelper.AddIfNotContains(loadFieldNames, DocHelper.TEXT_FIELD_1_KEY); SupportClass.CollectionsHelper.AddIfNotContains(loadFieldNames, DocHelper.TEXT_FIELD_UTF1_KEY); System.Collections.Hashtable lazyFieldNames = new System.Collections.Hashtable(); //new String[]{DocHelper.LARGE_LAZY_FIELD_KEY, DocHelper.LAZY_FIELD_KEY, DocHelper.LAZY_FIELD_BINARY_KEY}; SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.LARGE_LAZY_FIELD_KEY); SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.LAZY_FIELD_KEY); SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.LAZY_FIELD_BINARY_KEY); SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.TEXT_FIELD_UTF2_KEY); SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.COMPRESSED_TEXT_FIELD_2_KEY); SetBasedFieldSelector fieldSelector = new SetBasedFieldSelector(loadFieldNames, lazyFieldNames); Document doc = reader.Doc(0, fieldSelector); Assert.IsTrue(doc != null, "doc is null and it shouldn't be"); Fieldable field = doc.GetFieldable(DocHelper.LAZY_FIELD_KEY); Assert.IsTrue(field != null, "field is null and it shouldn't be"); Assert.IsTrue(field.IsLazy(), "field is not lazy and it should be"); System.String value_Renamed = field.StringValue(); Assert.IsTrue(value_Renamed != null, "value is null and it shouldn't be"); Assert.IsTrue(value_Renamed.Equals(DocHelper.LAZY_FIELD_TEXT) == true, value_Renamed + " is not equal to " + DocHelper.LAZY_FIELD_TEXT); field = doc.GetFieldable(DocHelper.COMPRESSED_TEXT_FIELD_2_KEY); Assert.IsTrue(field != null, "field is null and it shouldn't be"); Assert.IsTrue(field.IsLazy(), "field is not lazy and it should be"); Assert.IsTrue(field.BinaryValue() == null, "binaryValue isn't null for lazy string field"); value_Renamed = field.StringValue(); Assert.IsTrue(value_Renamed != null, "value is null and it shouldn't be"); Assert.IsTrue(value_Renamed.Equals(DocHelper.FIELD_2_COMPRESSED_TEXT) == true, value_Renamed + " is not equal to " + DocHelper.FIELD_2_COMPRESSED_TEXT); field = doc.GetFieldable(DocHelper.TEXT_FIELD_1_KEY); Assert.IsTrue(field != null, "field is null and it shouldn't be"); Assert.IsTrue(field.IsLazy() == false, "Field is lazy and it should not be"); field = doc.GetFieldable(DocHelper.TEXT_FIELD_UTF1_KEY); Assert.IsTrue(field != null, "field is null and it shouldn't be"); Assert.IsTrue(field.IsLazy() == false, "Field is lazy and it should not be"); Assert.IsTrue(field.StringValue().Equals(DocHelper.FIELD_UTF1_TEXT) == true, field.StringValue() + " is not equal to " + DocHelper.FIELD_UTF1_TEXT); field = doc.GetFieldable(DocHelper.TEXT_FIELD_UTF2_KEY); Assert.IsTrue(field != null, "field is null and it shouldn't be"); Assert.IsTrue(field.IsLazy() == true, "Field is lazy and it should not be"); Assert.IsTrue(field.StringValue().Equals(DocHelper.FIELD_UTF2_TEXT) == true, field.StringValue() + " is not equal to " + DocHelper.FIELD_UTF2_TEXT); field = doc.GetFieldable(DocHelper.LAZY_FIELD_BINARY_KEY); Assert.IsTrue(field != null, "field is null and it shouldn't be"); Assert.IsTrue(field.StringValue() == null, "stringValue isn't null for lazy binary field"); byte[] bytes = field.BinaryValue(); Assert.IsTrue(bytes != null, "bytes is null and it shouldn't be"); Assert.IsTrue(DocHelper.LAZY_FIELD_BINARY_BYTES.Length == bytes.Length, ""); for (int i = 0; i < bytes.Length; i++) { Assert.IsTrue(bytes[i] == DocHelper.LAZY_FIELD_BINARY_BYTES[i], "byte[" + i + "] is mismatched"); } }
public virtual void TestLazyPerformance() { System.String tmpIODir = SupportClass.AppSettings.Get("tempDir", ""); System.String userName = System.Environment.UserName; System.String path = tmpIODir + System.IO.Path.DirectorySeparatorChar.ToString() + "lazyDir" + userName; System.IO.FileInfo file = new System.IO.FileInfo(path); _TestUtil.RmDir(file); FSDirectory tmpDir = FSDirectory.Open(file); Assert.IsTrue(tmpDir != null); IndexWriter writer = new IndexWriter(tmpDir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED); writer.SetUseCompoundFile(false); writer.AddDocument(testDoc); writer.Close(); Assert.IsTrue(fieldInfos != null); FieldsReader reader; long lazyTime = 0; long regularTime = 0; int length = 50; System.Collections.Hashtable lazyFieldNames = new System.Collections.Hashtable(); SupportClass.CollectionsHelper.AddIfNotContains(lazyFieldNames, DocHelper.LARGE_LAZY_FIELD_KEY); SetBasedFieldSelector fieldSelector = new SetBasedFieldSelector(new System.Collections.Hashtable(), lazyFieldNames); for (int i = 0; i < length; i++) { reader = new FieldsReader(tmpDir, TEST_SEGMENT_NAME, fieldInfos); Assert.IsTrue(reader != null); Assert.IsTrue(reader.Size() == 1); Document doc; doc = reader.Doc(0, null); //Load all of them Assert.IsTrue(doc != null, "doc is null and it shouldn't be"); Fieldable field = doc.GetFieldable(DocHelper.LARGE_LAZY_FIELD_KEY); Assert.IsTrue(field.IsLazy() == false, "field is lazy"); System.String value_Renamed; long start; long finish; start = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond); //On my machine this was always 0ms. value_Renamed = field.StringValue(); finish = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond); Assert.IsTrue(value_Renamed != null, "value is null and it shouldn't be"); Assert.IsTrue(field != null, "field is null and it shouldn't be"); regularTime += (finish - start); reader.Close(); reader = null; doc = null; //Hmmm, are we still in cache??? System.GC.Collect(); reader = new FieldsReader(tmpDir, TEST_SEGMENT_NAME, fieldInfos); doc = reader.Doc(0, fieldSelector); field = doc.GetFieldable(DocHelper.LARGE_LAZY_FIELD_KEY); Assert.IsTrue(field.IsLazy() == true, "field is not lazy"); start = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond); //On my machine this took around 50 - 70ms value_Renamed = field.StringValue(); finish = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond); Assert.IsTrue(value_Renamed != null, "value is null and it shouldn't be"); lazyTime += (finish - start); reader.Close(); } System.Console.Out.WriteLine("Average Non-lazy time (should be very close to zero): " + regularTime / length + " ms for " + length + " reads"); System.Console.Out.WriteLine("Average Lazy Time (should be greater than zero): " + lazyTime / length + " ms for " + length + " reads"); }