本文整理汇总了C#中Lucene.Net.Index.ParallelReader.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ParallelReader.Add方法的具体用法?C# ParallelReader.Add怎么用?C# ParallelReader.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.ParallelReader
的用法示例。
在下文中一共展示了ParallelReader.Add方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestFieldNames
public virtual void TestFieldNames()
{
Directory dir1 = GetDir1();
Directory dir2 = GetDir2();
ParallelReader pr = new ParallelReader();
pr.Add(IndexReader.Open(dir1));
pr.Add(IndexReader.Open(dir2));
System.Collections.Generic.ICollection<string> fieldNames = pr.GetFieldNames(IndexReader.FieldOption.ALL);
Assert.AreEqual(4, fieldNames.Count);
Assert.IsTrue(SupportClass.CollectionsHelper.Contains(fieldNames, "f1"));
Assert.IsTrue(SupportClass.CollectionsHelper.Contains(fieldNames, "f2"));
Assert.IsTrue(SupportClass.CollectionsHelper.Contains(fieldNames, "f3"));
Assert.IsTrue(SupportClass.CollectionsHelper.Contains(fieldNames, "f4"));
}
示例2: DoReopen
protected internal virtual IndexReader DoReopen(bool doClone)
{
EnsureOpen();
bool reopened = false;
System.Collections.IList newReaders = new System.Collections.ArrayList();
bool success = false;
try
{
for (int i = 0; i < readers.Count; i++)
{
IndexReader oldReader = (IndexReader) readers[i];
IndexReader newReader = null;
if (doClone)
{
newReader = (IndexReader) oldReader.Clone();
}
else
{
newReader = oldReader.Reopen();
}
newReaders.Add(newReader);
// if at least one of the subreaders was updated we remember that
// and return a new ParallelReader
if (newReader != oldReader)
{
reopened = true;
}
}
success = true;
}
finally
{
if (!success && reopened)
{
for (int i = 0; i < newReaders.Count; i++)
{
IndexReader r = (IndexReader) newReaders[i];
if (r != readers[i])
{
try
{
r.Close();
}
catch (System.IO.IOException ignore)
{
// keep going - we want to clean up as much as possible
}
}
}
}
}
if (reopened)
{
System.Collections.IList newDecrefOnClose = new System.Collections.ArrayList();
ParallelReader pr = new ParallelReader();
for (int i = 0; i < readers.Count; i++)
{
IndexReader oldReader = (IndexReader) readers[i];
IndexReader newReader = (IndexReader) newReaders[i];
if (newReader == oldReader)
{
newDecrefOnClose.Add(true);
newReader.IncRef();
}
else
{
// this is a new subreader instance, so on close() we don't
// decRef but close it
newDecrefOnClose.Add(false);
}
pr.Add(newReader, !storedFieldReaders.Contains(oldReader));
}
pr.decrefOnClose = newDecrefOnClose;
pr.incRefReaders = incRefReaders;
return pr;
}
else
{
// No subreader was refreshed
return this;
}
}
示例3: Test1
public virtual void Test1()
{
ParallelReader pr = new ParallelReader();
pr.Add(ir1);
pr.Add(ir2);
TermDocs td = pr.TermDocs();
TermEnum te = pr.Terms();
Assert.IsTrue(te.Next());
Assert.AreEqual("field1:brown", te.Term.ToString());
td.Seek(te.Term);
Assert.IsTrue(td.Next());
Assert.AreEqual(0, td.Doc);
Assert.IsFalse(td.Next());
Assert.IsTrue(te.Next());
Assert.AreEqual("field1:fox", te.Term.ToString());
td.Seek(te.Term);
Assert.IsTrue(td.Next());
Assert.AreEqual(0, td.Doc);
Assert.IsFalse(td.Next());
Assert.IsTrue(te.Next());
Assert.AreEqual("field1:jumps", te.Term.ToString());
td.Seek(te.Term);
Assert.IsTrue(td.Next());
Assert.AreEqual(0, td.Doc);
Assert.IsFalse(td.Next());
Assert.IsTrue(te.Next());
Assert.AreEqual("field1:quick", te.Term.ToString());
td.Seek(te.Term);
Assert.IsTrue(td.Next());
Assert.AreEqual(0, td.Doc);
Assert.IsFalse(td.Next());
Assert.IsTrue(te.Next());
Assert.AreEqual("field1:the", te.Term.ToString());
td.Seek(te.Term);
Assert.IsTrue(td.Next());
Assert.AreEqual(0, td.Doc);
Assert.IsFalse(td.Next());
Assert.IsTrue(te.Next());
Assert.AreEqual("field2:brown", te.Term.ToString());
td.Seek(te.Term);
Assert.IsTrue(td.Next());
Assert.AreEqual(0, td.Doc);
Assert.IsFalse(td.Next());
Assert.IsTrue(te.Next());
Assert.AreEqual("field2:fox", te.Term.ToString());
td.Seek(te.Term);
Assert.IsTrue(td.Next());
Assert.AreEqual(0, td.Doc);
Assert.IsFalse(td.Next());
Assert.IsTrue(te.Next());
Assert.AreEqual("field2:jumps", te.Term.ToString());
td.Seek(te.Term);
Assert.IsTrue(td.Next());
Assert.AreEqual(0, td.Doc);
Assert.IsFalse(td.Next());
Assert.IsTrue(te.Next());
Assert.AreEqual("field2:quick", te.Term.ToString());
td.Seek(te.Term);
Assert.IsTrue(td.Next());
Assert.AreEqual(0, td.Doc);
Assert.IsFalse(td.Next());
Assert.IsTrue(te.Next());
Assert.AreEqual("field2:the", te.Term.ToString());
td.Seek(te.Term);
Assert.IsTrue(td.Next());
Assert.AreEqual(0, td.Doc);
Assert.IsFalse(td.Next());
Assert.IsTrue(te.Next());
Assert.AreEqual("field3:dog", te.Term.ToString());
td.Seek(te.Term);
Assert.IsTrue(td.Next());
Assert.AreEqual(0, td.Doc);
Assert.IsFalse(td.Next());
Assert.IsTrue(te.Next());
Assert.AreEqual("field3:fox", te.Term.ToString());
td.Seek(te.Term);
Assert.IsTrue(td.Next());
Assert.AreEqual(0, td.Doc);
Assert.IsFalse(td.Next());
Assert.IsTrue(te.Next());
Assert.AreEqual("field3:jumps", te.Term.ToString());
td.Seek(te.Term);
Assert.IsTrue(td.Next());
Assert.AreEqual(0, td.Doc);
Assert.IsFalse(td.Next());
Assert.IsTrue(te.Next());
Assert.AreEqual("field3:lazy", te.Term.ToString());
td.Seek(te.Term);
Assert.IsTrue(td.Next());
Assert.AreEqual(0, td.Doc);
Assert.IsFalse(td.Next());
Assert.IsTrue(te.Next());
Assert.AreEqual("field3:over", te.Term.ToString());
td.Seek(te.Term);
Assert.IsTrue(td.Next());
Assert.AreEqual(0, td.Doc);
Assert.IsFalse(td.Next());
Assert.IsTrue(te.Next());
//.........这里部分代码省略.........
示例4: TestParallelReader
public virtual void TestParallelReader()
{
Directory dir1 = new MockRAMDirectory();
TestIndexReaderReopen.CreateIndex(dir1, true);
Directory dir2 = new MockRAMDirectory();
TestIndexReaderReopen.CreateIndex(dir2, true);
IndexReader r1 = IndexReader.Open(dir1, false);
IndexReader r2 = IndexReader.Open(dir2, false);
ParallelReader pr1 = new ParallelReader();
pr1.Add(r1);
pr1.Add(r2);
PerformDefaultTests(pr1);
pr1.Close();
dir1.Close();
dir2.Close();
}
示例5: TestDocument
public virtual void TestDocument()
{
Directory dir1 = GetDir1();
Directory dir2 = GetDir2();
ParallelReader pr = new ParallelReader();
pr.Add(IndexReader.Open(dir1));
pr.Add(IndexReader.Open(dir2));
Document doc11 = pr.Document(0, new MapFieldSelector(new System.String[]{"f1"}));
Document doc24 = pr.Document(1, new MapFieldSelector(new System.Collections.ArrayList(new System.String[]{"f4"})));
Document doc223 = pr.Document(1, new MapFieldSelector(new System.String[]{"f2", "f3"}));
Assert.AreEqual(1, doc11.GetFields().Count);
Assert.AreEqual(1, doc24.GetFields().Count);
Assert.AreEqual(2, doc223.GetFields().Count);
Assert.AreEqual("v1", doc11.Get("f1"));
Assert.AreEqual("v2", doc24.Get("f4"));
Assert.AreEqual("v2", doc223.Get("f2"));
Assert.AreEqual("v2", doc223.Get("f3"));
}
示例6: TestAllTermDocs
public virtual void TestAllTermDocs()
{
Directory dir1 = GetDir1();
Directory dir2 = GetDir2();
ParallelReader pr = new ParallelReader();
pr.Add(IndexReader.Open(dir1));
pr.Add(IndexReader.Open(dir2));
int NUM_DOCS = 2;
TermDocs td = pr.TermDocs(null);
for (int i = 0; i < NUM_DOCS; i++)
{
Assert.IsTrue(td.Next());
Assert.AreEqual(i, td.Doc());
Assert.AreEqual(1, td.Freq());
}
td.Close();
pr.Close();
dir1.Close();
dir2.Close();
}
示例7: Parallel
// Fields 1 & 2 in one index, 3 & 4 in other, with ParallelReader:
private Searcher Parallel()
{
Directory dir1 = GetDir1();
Directory dir2 = GetDir2();
ParallelReader pr = new ParallelReader();
pr.Add(IndexReader.Open(dir1));
pr.Add(IndexReader.Open(dir2));
return new IndexSearcher(pr);
}
示例8: TestIsCurrent
public virtual void TestIsCurrent()
{
Directory dir1 = GetDir1();
Directory dir2 = GetDir2();
ParallelReader pr = new ParallelReader();
pr.Add(IndexReader.Open(dir1));
pr.Add(IndexReader.Open(dir2));
Assert.IsTrue(pr.IsCurrent());
IndexReader modifier = IndexReader.Open(dir1);
modifier.SetNorm(0, "f1", 100);
modifier.Close();
// one of the two IndexReaders which ParallelReader is using
// is not current anymore
Assert.IsFalse(pr.IsCurrent());
modifier = IndexReader.Open(dir2);
modifier.SetNorm(0, "f3", 100);
modifier.Close();
// now both are not current anymore
Assert.IsFalse(pr.IsCurrent());
}
示例9: TestIsOptimized
public virtual void TestIsOptimized()
{
Directory dir1 = GetDir1();
Directory dir2 = GetDir2();
// add another document to ensure that the indexes are not optimized
IndexWriter modifier = new IndexWriter(dir1, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
Document d = new Document();
d.Add(new Field("f1", "v1", Field.Store.YES, Field.Index.ANALYZED));
modifier.AddDocument(d);
modifier.Close();
modifier = new IndexWriter(dir2, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
d = new Document();
d.Add(new Field("f2", "v2", Field.Store.YES, Field.Index.ANALYZED));
modifier.AddDocument(d);
modifier.Close();
ParallelReader pr = new ParallelReader();
pr.Add(IndexReader.Open(dir1));
pr.Add(IndexReader.Open(dir2));
Assert.IsFalse(pr.IsOptimized());
pr.Close();
modifier = new IndexWriter(dir1, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
modifier.Optimize();
modifier.Close();
pr = new ParallelReader();
pr.Add(IndexReader.Open(dir1));
pr.Add(IndexReader.Open(dir2));
// just one of the two indexes are optimized
Assert.IsFalse(pr.IsOptimized());
pr.Close();
modifier = new IndexWriter(dir2, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
modifier.Optimize();
modifier.Close();
pr = new ParallelReader();
pr.Add(IndexReader.Open(dir1));
pr.Add(IndexReader.Open(dir2));
// now both indexes are optimized
Assert.IsTrue(pr.IsOptimized());
pr.Close();
}
示例10: TestReferenceCountingParallelReader
public virtual void TestReferenceCountingParallelReader()
{
for (int mode = 0; mode <= 1; mode++)
{
Directory dir1 = new MockRAMDirectory();
CreateIndex(dir1, false);
Directory dir2 = new MockRAMDirectory();
CreateIndex(dir2, true);
IndexReader reader1 = IndexReader.Open(dir1);
AssertRefCountEquals(1, reader1);
ParallelReader parallelReader1 = new ParallelReader(mode == 0);
parallelReader1.Add(reader1);
IndexReader initReader2 = IndexReader.Open(dir2);
parallelReader1.Add(initReader2);
ModifyIndex(1, dir2);
AssertRefCountEquals(1 + mode, reader1);
IndexReader parallelReader2 = parallelReader1.Reopen();
// index1 hasn't changed, so parallelReader2 should share reader1 now with multiReader1
AssertRefCountEquals(2 + mode, reader1);
ModifyIndex(0, dir1);
ModifyIndex(0, dir2);
IndexReader reader2 = reader1.Reopen();
AssertRefCountEquals(2 + mode, reader1);
if (mode == 1)
{
initReader2.Close();
}
ModifyIndex(4, dir1);
IndexReader reader3 = reader2.Reopen();
AssertRefCountEquals(2 + mode, reader1);
AssertRefCountEquals(1, reader2);
parallelReader1.Close();
AssertRefCountEquals(1 + mode, reader1);
parallelReader1.Close();
AssertRefCountEquals(1 + mode, reader1);
if (mode == 1)
{
initReader2.Close();
}
reader1.Close();
AssertRefCountEquals(1, reader1);
parallelReader2.Close();
AssertRefCountEquals(0, reader1);
parallelReader2.Close();
AssertRefCountEquals(0, reader1);
reader3.Close();
AssertRefCountEquals(0, reader1);
AssertReaderClosed(reader1, true, false);
reader2.Close();
AssertRefCountEquals(0, reader1);
AssertReaderClosed(reader1, true, false);
reader2.Close();
AssertRefCountEquals(0, reader1);
reader3.Close();
AssertRefCountEquals(0, reader1);
AssertReaderClosed(reader1, true, true);
dir1.Close();
dir2.Close();
}
}
示例11: TestIncompatibleIndexes
public virtual void TestIncompatibleIndexes()
{
// two documents:
Directory dir1 = GetDir1();
// one document only:
Directory dir2 = new MockRAMDirectory();
IndexWriter w2 = new IndexWriter(dir2, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
Document d3 = new Document();
d3.Add(new Field("f3", "v1", Field.Store.YES, Field.Index.ANALYZED));
w2.AddDocument(d3);
w2.Close();
ParallelReader pr = new ParallelReader();
pr.Add(IndexReader.Open(dir1));
try
{
pr.Add(IndexReader.Open(dir2));
Assert.Fail("didn't get exptected exception: indexes don't have same number of documents");
}
catch (System.ArgumentException e)
{
// expected exception
}
}
示例12: OpenReader
protected internal override IndexReader OpenReader()
{
ParallelReader pr = new ParallelReader();
pr.Add(IndexReader.Open(dir1));
pr.Add(IndexReader.Open(dir2));
MultiReader mr = new MultiReader(new IndexReader[]{IndexReader.Open(dir3), IndexReader.Open(dir4)});
return new MultiReader(new IndexReader[]{pr, mr, IndexReader.Open(dir5)});
}
示例13: TestIncompatibleIndexes
public virtual void TestIncompatibleIndexes()
{
// two documents:
Directory dir1 = GetDir1();
// one document only:
Directory dir2 = new MockRAMDirectory();
IndexWriter w2 = new IndexWriter(dir2, new StandardAnalyzer(Util.Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
Document d3 = new Document();
d3.Add(new Field("f3", "v1", Field.Store.YES, Field.Index.ANALYZED));
w2.AddDocument(d3);
w2.Close();
ParallelReader pr = new ParallelReader();
pr.Add(IndexReader.Open(dir1, false));
Assert.Throws<ArgumentException>(() => pr.Add(IndexReader.Open(dir2, false)),
"didn't get exptected exception: indexes don't have same number of documents");
}
示例14: OpenReader
protected internal override IndexReader OpenReader()
{
ParallelReader pr = new ParallelReader();
pr.Add(IndexReader.Open(dir3));
pr.Add(IndexReader.Open(dir4));
pr.Add(new FilterIndexReader(IndexReader.Open(dir3)));
return pr;
}