本文整理汇总了C#中Lucene.Net.Store.RAMDirectory.CreateOutput方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Store.RAMDirectory.CreateOutput方法的具体用法?C# Lucene.Net.Store.RAMDirectory.CreateOutput怎么用?C# Lucene.Net.Store.RAMDirectory.CreateOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Store.RAMDirectory
的用法示例。
在下文中一共展示了Lucene.Net.Store.RAMDirectory.CreateOutput方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
示例2: Test
public virtual void Test()
{
//Positive test of FieldInfos
Assert.IsTrue(testDoc != null);
FieldInfos fieldInfos = new FieldInfos();
fieldInfos.Add(testDoc);
//Since the complement is stored as well in the fields map
Assert.IsTrue(fieldInfos.Size() == DocHelper.all.Count); //this is all b/c we are using the no-arg constructor
RAMDirectory dir = new RAMDirectory();
System.String name = "testFile";
IndexOutput output = dir.CreateOutput(name);
Assert.IsTrue(output != null);
//Use a RAMOutputStream
try
{
fieldInfos.Write(output);
output.Close();
Assert.IsTrue(output.Length() > 0);
FieldInfos readIn = new FieldInfos(dir, name);
Assert.IsTrue(fieldInfos.Size() == readIn.Size());
FieldInfo info = readIn.FieldInfo("textField1");
Assert.IsTrue(info != null);
Assert.IsTrue(info.storeTermVector_ForNUnit == false);
Assert.IsTrue(info.omitNorms_ForNUnit == false);
info = readIn.FieldInfo("textField2");
Assert.IsTrue(info != null);
Assert.IsTrue(info.storeTermVector_ForNUnit == true);
Assert.IsTrue(info.omitNorms_ForNUnit == false);
info = readIn.FieldInfo("textField3");
Assert.IsTrue(info != null);
Assert.IsTrue(info.storeTermVector_ForNUnit == false);
Assert.IsTrue(info.omitNorms_ForNUnit == true);
info = readIn.FieldInfo("omitNorms");
Assert.IsTrue(info != null);
Assert.IsTrue(info.storeTermVector_ForNUnit == false);
Assert.IsTrue(info.omitNorms_ForNUnit == true);
dir.Close();
}
catch (System.IO.IOException e)
{
Assert.IsTrue(false);
}
}
示例3: 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();
}
}
示例4: 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();
}
示例5: 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();
}