当前位置: 首页>>代码示例>>C#>>正文


C# Lucene.Net.Store.RAMDirectory.OpenInput方法代码示例

本文整理汇总了C#中Lucene.Net.Store.RAMDirectory.OpenInput方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Store.RAMDirectory.OpenInput方法的具体用法?C# Lucene.Net.Store.RAMDirectory.OpenInput怎么用?C# Lucene.Net.Store.RAMDirectory.OpenInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lucene.Net.Store.RAMDirectory的用法示例。


在下文中一共展示了Lucene.Net.Store.RAMDirectory.OpenInput方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestSimulatedCorruptIndex1

		public virtual void  TestSimulatedCorruptIndex1()
		{
			Directory dir = new RAMDirectory();
			
			IndexWriter writer = null;
			
			writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
			
			// add 100 documents
			for (int i = 0; i < 100; i++)
			{
				AddDoc(writer);
			}
			
			// close
			writer.Close();
			
			long gen = SegmentInfos.GetCurrentSegmentGeneration(dir);
			Assert.IsTrue(gen > 1, "segment generation should be > 1 but got " + gen);
			
			System.String fileNameIn = SegmentInfos.GetCurrentSegmentFileName(dir);
			System.String fileNameOut = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", 1 + gen);
			IndexInput in_Renamed = dir.OpenInput(fileNameIn);
			IndexOutput out_Renamed = dir.CreateOutput(fileNameOut);
			long length = in_Renamed.Length();
			for (int i = 0; i < length - 1; i++)
			{
				out_Renamed.WriteByte(in_Renamed.ReadByte());
			}
			in_Renamed.Close();
			out_Renamed.Close();
			dir.DeleteFile(fileNameIn);
			
			IndexReader reader = null;
			try
			{
				reader = IndexReader.Open(dir);
				Assert.Fail("reader did not hit IOException on opening a corrupt index");
			}
			catch (System.Exception)
			{
			}
			if (reader != null)
			{
				reader.Close();
			}
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:47,代码来源:TestIndexWriter.cs

示例2: TestEncodeDecode

        public virtual void TestEncodeDecode()
        {
            int iterations = RandomInts.NextIntBetween(Random(), 1, 1000);
            float AcceptableOverheadRatio = (float)Random().NextDouble();
            int[] values = new int[(iterations - 1) * Lucene41PostingsFormat.BLOCK_SIZE + ForUtil.MAX_DATA_SIZE];
            for (int i = 0; i < iterations; ++i)
            {
                int bpv = Random().Next(32);
                if (bpv == 0)
                {
                    int value = RandomInts.NextIntBetween(Random(), 0, int.MaxValue);
                    for (int j = 0; j < Lucene41PostingsFormat.BLOCK_SIZE; ++j)
                    {
                        values[i * Lucene41PostingsFormat.BLOCK_SIZE + j] = value;
                    }
                }
                else
                {
                    for (int j = 0; j < Lucene41PostingsFormat.BLOCK_SIZE; ++j)
                    {
                        values[i * Lucene41PostingsFormat.BLOCK_SIZE + j] = RandomInts.NextIntBetween(Random(), 0, (int)PackedInts.MaxValue(bpv));
                    }
                }
            }

            Directory d = new RAMDirectory();
            long endPointer;

            {
                // encode
                IndexOutput @out = d.CreateOutput("test.bin", IOContext.DEFAULT);
                ForUtil forUtil = new ForUtil(AcceptableOverheadRatio, @out);

                for (int i = 0; i < iterations; ++i)
                {
                    forUtil.WriteBlock(Arrays.CopyOfRange(values, i * Lucene41PostingsFormat.BLOCK_SIZE, values.Length), new byte[Lucene41.ForUtil.MAX_ENCODED_SIZE], @out);
                }
                endPointer = @out.FilePointer;
                @out.Dispose();
            }

            {
                // decode
                IndexInput @in = d.OpenInput("test.bin", IOContext.READONCE);
                ForUtil forUtil = new ForUtil(@in);
                for (int i = 0; i < iterations; ++i)
                {
                    if (Random().NextBoolean())
                    {
                        forUtil.SkipBlock(@in);
                        continue;
                    }
                    int[] restored = new int[Lucene41.ForUtil.MAX_DATA_SIZE];
                    forUtil.ReadBlock(@in, new byte[Lucene41.ForUtil.MAX_ENCODED_SIZE], restored);
                    Assert.AreEqual(Arrays.CopyOfRange(values, i * Lucene41PostingsFormat.BLOCK_SIZE, (i + 1) * Lucene41PostingsFormat.BLOCK_SIZE), Arrays.CopyOf(restored, Lucene41PostingsFormat.BLOCK_SIZE));
                }
                Assert.AreEqual(endPointer, @in.FilePointer);
                @in.Dispose();
            }
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:60,代码来源:TestForUtil.cs

示例3: TestSimulatedCrashedWriter

		public virtual void  TestSimulatedCrashedWriter()
		{
			Directory dir = new RAMDirectory();
			
			IndexWriter writer = null;
			
			writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
			
			// add 100 documents
			for (int i = 0; i < 100; i++)
			{
				AddDoc(writer);
			}
			
			// close
			writer.Close();
			
			long gen = SegmentInfos.GetCurrentSegmentGeneration(dir);
			Assert.IsTrue(gen > 1, "segment generation should be > 1 but got " + gen);
			
			// Make the next segments file, with last byte
			// missing, to simulate a writer that crashed while
			// writing segments file:
			System.String fileNameIn = SegmentInfos.GetCurrentSegmentFileName(dir);
			System.String fileNameOut = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", 1 + gen);
			IndexInput in_Renamed = dir.OpenInput(fileNameIn);
			IndexOutput out_Renamed = dir.CreateOutput(fileNameOut);
			long length = in_Renamed.Length();
			for (int i = 0; i < length - 1; i++)
			{
				out_Renamed.WriteByte(in_Renamed.ReadByte());
			}
			in_Renamed.Close();
			out_Renamed.Close();
			
			IndexReader reader = null;
			try
			{
				reader = IndexReader.Open(dir);
			}
			catch (System.Exception)
			{
				Assert.Fail("reader failed to open on a crashed index");
			}
			reader.Close();
			
			try
			{
				writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
			}
			catch (System.Exception)
			{
				Assert.Fail("writer failed to open on a crashed index");
			}
			
			// add 100 documents
			for (int i = 0; i < 100; i++)
			{
				AddDoc(writer);
			}
			
			// close
			writer.Close();
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:64,代码来源:TestIndexWriter.cs

示例4: TestRawIndexInputRead

        public virtual void TestRawIndexInputRead()
        {
            Random random = Random();
            RAMDirectory dir = new RAMDirectory();
            IndexOutput os = dir.CreateOutput("foo", NewIOContext(random));
            os.WriteBytes(READ_TEST_BYTES, READ_TEST_BYTES.Length);
            os.Dispose();
            IndexInput @is = dir.OpenInput("foo", NewIOContext(random));
            CheckReads(@is, typeof(IOException));
            @is.Dispose();

            os = dir.CreateOutput("bar", NewIOContext(random));
            os.WriteBytes(RANDOM_TEST_BYTES, RANDOM_TEST_BYTES.Length);
            os.Dispose();
            @is = dir.OpenInput("bar", NewIOContext(random));
            CheckRandomReads(@is);
            @is.Dispose();
            dir.Dispose();
        }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:19,代码来源:TestIndexInput.cs


注:本文中的Lucene.Net.Store.RAMDirectory.OpenInput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。