Exemplo n.º 1
0
        public virtual void  TestLazyFieldsAfterClose()
        {
            Assert.IsTrue(dir != null);
            Assert.IsTrue(fieldInfos != null);
            FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos, null);

            Assert.IsTrue(reader != null);
            Assert.IsTrue(reader.Size() == 1);
            ISet <string> loadFieldNames = Support.Compatibility.SetFactory.CreateHashSet <string>();

            loadFieldNames.Add(DocHelper.TEXT_FIELD_1_KEY);
            loadFieldNames.Add(DocHelper.TEXT_FIELD_UTF1_KEY);
            ISet <string> lazyFieldNames = Support.Compatibility.SetFactory.CreateHashSet <string>();

            lazyFieldNames.Add(DocHelper.LARGE_LAZY_FIELD_KEY);
            lazyFieldNames.Add(DocHelper.LAZY_FIELD_KEY);
            lazyFieldNames.Add(DocHelper.LAZY_FIELD_BINARY_KEY);
            lazyFieldNames.Add(DocHelper.TEXT_FIELD_UTF2_KEY);
            SetBasedFieldSelector fieldSelector = new SetBasedFieldSelector(loadFieldNames, lazyFieldNames);
            Document doc = reader.Doc(0, fieldSelector, null);

            Assert.IsTrue(doc != null, "doc is null and it shouldn't be");
            IFieldable 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.Dispose();

            Assert.Throws <AlreadyClosedException>(() => { var value = field.StringValue(null); },
                                                   "did not hit AlreadyClosedException as expected");
        }
Exemplo n.º 2
0
        public virtual void  TestLoadSize()
        {
            FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos, null);
            Document     doc;

            doc = reader.Doc(0, new AnonymousClassFieldSelector(this), null);
            IFieldable f1 = doc.GetFieldable(DocHelper.TEXT_FIELD_1_KEY);
            IFieldable f3 = doc.GetFieldable(DocHelper.TEXT_FIELD_3_KEY);
            IFieldable 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.GetBinaryValue(null));
            Assert.AreEqual(DocHelper.FIELD_3_TEXT, f3.StringValue(null));
            AssertSizeEquals(DocHelper.LAZY_FIELD_BINARY_BYTES.Length, fb.GetBinaryValue(null));

            reader.Dispose();
        }
Exemplo n.º 3
0
        public virtual void  Test()
        {
            Assert.IsTrue(dir != null);
            Assert.IsTrue(fieldInfos != null);
            FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos, null);

            Assert.IsTrue(reader != null);
            Assert.IsTrue(reader.Size() == 1);
            Document doc = reader.Doc(0, null, null);

            Assert.IsTrue(doc != null);
            Assert.IsTrue(doc.GetField(DocHelper.TEXT_FIELD_1_KEY) != null);

            IFieldable 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.OmitNorms == false);
            Assert.IsTrue(field.OmitTermFreqAndPositions == 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.OmitNorms == true);
            Assert.IsTrue(field.OmitTermFreqAndPositions == 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.OmitNorms == false);
            Assert.IsTrue(field.OmitTermFreqAndPositions == true);
            reader.Dispose();
        }
Exemplo n.º 4
0
		public virtual void  TestLoadSize()
		{
			FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos);
			Document doc;
			
			doc = reader.Doc(0, new AnonymousClassFieldSelector(this));
			IFieldable f1 = doc.GetFieldable(DocHelper.TEXT_FIELD_1_KEY);
			IFieldable f3 = doc.GetFieldable(DocHelper.TEXT_FIELD_3_KEY);
			IFieldable 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.GetBinaryValue());
			Assert.AreEqual(DocHelper.FIELD_3_TEXT, f3.StringValue);
            AssertSizeEquals(DocHelper.LAZY_FIELD_BINARY_BYTES.Length, fb.GetBinaryValue());

            reader.Dispose();
		}
Exemplo n.º 5
0
		public virtual void  TestLazyPerformance()
		{
			System.String tmpIODir = AppSettings.Get("tempDir", "");
			System.String userName = System.Environment.UserName;
			System.String path = tmpIODir + System.IO.Path.DirectorySeparatorChar.ToString() + "lazyDir" + userName;
            System.IO.DirectoryInfo file = new System.IO.DirectoryInfo(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.UseCompoundFile = false;
			writer.AddDocument(testDoc);
			writer.Close();
			
			Assert.IsTrue(fieldInfos != null);
			FieldsReader reader;
			long lazyTime = 0;
			long regularTime = 0;
			int length = 50;
            ISet<string> lazyFieldNames = Support.Compatibility.SetFactory.GetSet<string>();
			lazyFieldNames.Add(DocHelper.LARGE_LAZY_FIELD_KEY);
			SetBasedFieldSelector fieldSelector = new SetBasedFieldSelector(Support.Compatibility.SetFactory.GetSet<string>(), 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");
				IFieldable 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.Dispose();
				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.Dispose();
			}
			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");
		}
Exemplo n.º 6
0
		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);
            ISet<string> loadFieldNames = Support.Compatibility.SetFactory.GetSet<string>();
            loadFieldNames.Add(DocHelper.TEXT_FIELD_1_KEY);
            loadFieldNames.Add(DocHelper.TEXT_FIELD_UTF1_KEY);
            ISet<string> lazyFieldNames = Support.Compatibility.SetFactory.GetSet<string>();
            lazyFieldNames.Add(DocHelper.LARGE_LAZY_FIELD_KEY);
            lazyFieldNames.Add(DocHelper.LAZY_FIELD_KEY);
            lazyFieldNames.Add(DocHelper.LAZY_FIELD_BINARY_KEY);
            lazyFieldNames.Add(DocHelper.TEXT_FIELD_UTF2_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");
			IFieldable 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.Dispose();

		    Assert.Throws<AlreadyClosedException>(() => { var value = field.StringValue; },
		                                          "did not hit AlreadyClosedException as expected");
		}
Exemplo n.º 7
0
		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);
			
			IFieldable 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.OmitNorms == false);
			Assert.IsTrue(field.OmitTermFreqAndPositions == 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.OmitNorms == true);
			Assert.IsTrue(field.OmitTermFreqAndPositions == 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.OmitNorms == false);
			Assert.IsTrue(field.OmitTermFreqAndPositions == true);
			reader.Dispose();
		}
Exemplo n.º 8
0
        public virtual void  TestLazyPerformance()
        {
            System.String           tmpIODir = AppSettings.Get("tempDir", Path.GetTempPath());
            System.String           path     = tmpIODir + System.IO.Path.DirectorySeparatorChar.ToString() + "lazyDir" + Guid.NewGuid();
            System.IO.DirectoryInfo file     = new System.IO.DirectoryInfo(path);
            _TestUtil.RmDir(file);
            FSDirectory tmpDir = FSDirectory.Open(file);

            Assert.IsTrue(tmpDir != null);

            IndexWriter writer = new IndexWriter(tmpDir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED, null);

            writer.UseCompoundFile = false;
            writer.AddDocument(testDoc, null);
            writer.Close();

            Assert.IsTrue(fieldInfos != null);
            FieldsReader  reader;
            long          lazyTime       = 0;
            long          regularTime    = 0;
            int           length         = 50;
            ISet <string> lazyFieldNames = Support.Compatibility.SetFactory.CreateHashSet <string>();

            lazyFieldNames.Add(DocHelper.LARGE_LAZY_FIELD_KEY);
            SetBasedFieldSelector fieldSelector = new SetBasedFieldSelector(Support.Compatibility.SetFactory.CreateHashSet <string>(), lazyFieldNames);

            for (int i = 0; i < length; i++)
            {
                reader = new FieldsReader(tmpDir, TEST_SEGMENT_NAME, fieldInfos, null);
                Assert.IsTrue(reader != null);
                Assert.IsTrue(reader.Size() == 1);

                Document doc;
                doc = reader.Doc(0, null, null);                 //Load all of them
                Assert.IsTrue(doc != null, "doc is null and it shouldn't be");
                IFieldable 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(null);
                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.Dispose();
                reader = null;
                doc    = null;
                //Hmmm, are we still in cache???
                System.GC.Collect();
                reader = new FieldsReader(tmpDir, TEST_SEGMENT_NAME, fieldInfos, null);
                doc    = reader.Doc(0, fieldSelector, null);
                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(null);
                finish        = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);
                Assert.IsTrue(value_Renamed != null, "value is null and it shouldn't be");
                lazyTime += (finish - start);
                reader.Dispose();
            }
            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");
        }