本文整理汇总了C#中Lucene.Net.Index.IndexWriter.GetDocCount方法的典型用法代码示例。如果您正苦于以下问题:C# IndexWriter.GetDocCount方法的具体用法?C# IndexWriter.GetDocCount怎么用?C# IndexWriter.GetDocCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexWriter
的用法示例。
在下文中一共展示了IndexWriter.GetDocCount方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Index
/// <summary>
/// This method indexes the content that is sent across to it. Each piece of content (or "document")
/// that is indexed has to have a unique identifier (so that the caller can take action based on the
/// document id). Therefore, this method accepts key-value pairs in the form of a dictionary. The key
/// is a ulong which uniquely identifies the string to be indexed. The string itself is the value
/// within the dictionary for that key. Be aware that stop words (like the, this, at, etc.) are _not_
/// indexed.
/// </summary>
/// <param name="txtIdPairToBeIndexed">A dictionary of key-value pairs that are sent by the caller
/// to uniquely identify each string that is to be indexed.</param>
/// <returns>The number of documents indexed.</returns>
public int Index (Dictionary<long, string> txtIdPairToBeIndexed) {
using (Directory directory = FSDirectory.Open(_indexDir))
using (Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30))
using (IndexWriter writer = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
using (IndexReader reader = writer.GetReader())
{
//writer.DeleteAll();
Dictionary<long, string>.KeyCollection keys = txtIdPairToBeIndexed.Keys;
foreach (long id in keys)
{
char[] delimiter = { ';' };
string[] text = txtIdPairToBeIndexed[id].Split(delimiter);
Document document = new Document();
Field title = new Field("title", text[0], Field.Store.YES, Field.Index.NO);
Field type = new Field("type", text[1], Field.Store.YES, Field.Index.NO);
Field idField = new Field("date", (id).ToString(), Field.Store.YES, Field.Index.ANALYZED);
document.Add(title);
document.Add(type);
document.Add(idField);
writer.AddDocument(document);
}
int numIndexed = writer.GetDocCount(0);//TODO check number
writer.Optimize();
writer.Flush(true,true,true);
return numIndexed;
}
}
示例2: CheckInvariants
private void CheckInvariants(IndexWriter writer)
{
writer.WaitForMerges();
int maxBufferedDocs = writer.GetMaxBufferedDocs();
int mergeFactor = writer.MergeFactor;
int maxMergeDocs = writer.MaxMergeDocs;
int ramSegmentCount = writer.GetNumBufferedDocuments();
Assert.IsTrue(ramSegmentCount < maxBufferedDocs);
int lowerBound = - 1;
int upperBound = maxBufferedDocs;
int numSegments = 0;
int segmentCount = writer.GetSegmentCount();
for (int i = segmentCount - 1; i >= 0; i--)
{
int docCount = writer.GetDocCount(i);
Assert.IsTrue(docCount > lowerBound);
if (docCount <= upperBound)
{
numSegments++;
}
else
{
if (upperBound * mergeFactor <= maxMergeDocs)
{
Assert.IsTrue(numSegments < mergeFactor, "maxMergeDocs=" + maxMergeDocs + "; numSegments=" + numSegments + "; upperBound=" + upperBound + "; mergeFactor=" + mergeFactor);
}
do
{
lowerBound = upperBound;
upperBound *= mergeFactor;
}
while (docCount > upperBound);
numSegments = 1;
}
}
if (upperBound * mergeFactor <= maxMergeDocs)
{
Assert.IsTrue(numSegments < mergeFactor);
}
}
示例3: TestMoreMerges
public virtual void TestMoreMerges()
{
// main directory
Directory dir = NewDirectory();
// auxiliary directory
Directory aux = NewDirectory();
Directory aux2 = NewDirectory();
SetUpDirs(dir, aux, true);
IndexWriter writer = NewWriter(aux2, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetOpenMode(OpenMode_e.CREATE).SetMaxBufferedDocs(100).SetMergePolicy(NewLogMergePolicy(10)));
writer.AddIndexes(aux);
Assert.AreEqual(30, writer.MaxDoc);
Assert.AreEqual(3, writer.SegmentCount);
writer.Dispose();
IndexWriterConfig dontMergeConfig = (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetMergePolicy(NoMergePolicy.COMPOUND_FILES);
writer = new IndexWriter(aux, dontMergeConfig);
for (int i = 0; i < 27; i++)
{
writer.DeleteDocuments(new Term("id", "" + i));
}
writer.Dispose();
IndexReader reader = DirectoryReader.Open(aux);
Assert.AreEqual(3, reader.NumDocs);
reader.Dispose();
dontMergeConfig = (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetMergePolicy(NoMergePolicy.COMPOUND_FILES);
writer = new IndexWriter(aux2, dontMergeConfig);
for (int i = 0; i < 8; i++)
{
writer.DeleteDocuments(new Term("id", "" + i));
}
writer.Dispose();
reader = DirectoryReader.Open(aux2);
Assert.AreEqual(22, reader.NumDocs);
reader.Dispose();
writer = NewWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetOpenMode(OpenMode_e.APPEND).SetMaxBufferedDocs(6).SetMergePolicy(NewLogMergePolicy(4)));
writer.AddIndexes(aux, aux2);
Assert.AreEqual(1040, writer.MaxDoc);
Assert.AreEqual(1000, writer.GetDocCount(0));
writer.Dispose();
dir.Dispose();
aux.Dispose();
aux2.Dispose();
}
示例4: TestMergeAfterCopy
public virtual void TestMergeAfterCopy()
{
// main directory
Directory dir = NewDirectory();
// auxiliary directory
Directory aux = NewDirectory();
SetUpDirs(dir, aux, true);
IndexWriterConfig dontMergeConfig = (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetMergePolicy(NoMergePolicy.COMPOUND_FILES);
IndexWriter writer = new IndexWriter(aux, dontMergeConfig);
for (int i = 0; i < 20; i++)
{
writer.DeleteDocuments(new Term("id", "" + i));
}
writer.Dispose();
IndexReader reader = DirectoryReader.Open(aux);
Assert.AreEqual(10, reader.NumDocs);
reader.Dispose();
writer = NewWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetOpenMode(OpenMode_e.APPEND).SetMaxBufferedDocs(4).SetMergePolicy(NewLogMergePolicy(4)));
if (VERBOSE)
{
Console.WriteLine("\nTEST: now addIndexes");
}
writer.AddIndexes(aux, new MockDirectoryWrapper(Random(), new RAMDirectory(aux, NewIOContext(Random()))));
Assert.AreEqual(1020, writer.MaxDoc);
Assert.AreEqual(1000, writer.GetDocCount(0));
writer.Dispose();
dir.Dispose();
aux.Dispose();
}
示例5: CheckInvariants
private void CheckInvariants(IndexWriter writer)
{
_TestUtil.SyncConcurrentMerges(writer);
int maxBufferedDocs = writer.GetMaxBufferedDocs();
int mergeFactor = writer.GetMergeFactor();
int maxMergeDocs = writer.GetMaxMergeDocs();
int ramSegmentCount = writer.GetNumBufferedDocuments();
Assert.IsTrue(ramSegmentCount < maxBufferedDocs);
int lowerBound = - 1;
int upperBound = maxBufferedDocs;
int numSegments = 0;
int segmentCount = writer.GetSegmentCount();
for (int i = segmentCount - 1; i >= 0; i--)
{
int docCount = writer.GetDocCount(i);
Assert.IsTrue(docCount > lowerBound);
if (docCount <= upperBound)
{
numSegments++;
}
else
{
if (upperBound * mergeFactor <= maxMergeDocs)
{
Assert.IsTrue(numSegments < mergeFactor);
}
do
{
lowerBound = upperBound;
upperBound *= mergeFactor;
}
while (docCount > upperBound);
numSegments = 1;
}
}
if (upperBound * mergeFactor <= maxMergeDocs)
{
Assert.IsTrue(numSegments < mergeFactor);
}
System.String[] files = writer.GetDirectory().ListAll();
int segmentCfsCount = 0;
for (int i = 0; i < files.Length; i++)
{
if (files[i].EndsWith(".cfs"))
{
segmentCfsCount++;
}
}
Assert.AreEqual(segmentCount, segmentCfsCount);
}
示例6: PrintSegmentDocCounts
private void PrintSegmentDocCounts(IndexWriter writer)
{
int segmentCount = writer.GetSegmentCount();
System.Console.Out.WriteLine("" + segmentCount + " segments total");
for (int i = 0; i < segmentCount; i++)
{
System.Console.Out.WriteLine(" segment " + i + " has " + writer.GetDocCount(i) + " docs");
}
}
示例7: CheckInvariants
private void CheckInvariants(IndexWriter writer)
{
writer.WaitForMerges();
int maxBufferedDocs = writer.Config.MaxBufferedDocs;
int mergeFactor = ((LogMergePolicy)writer.Config.MergePolicy).MergeFactor;
int maxMergeDocs = ((LogMergePolicy)writer.Config.MergePolicy).MaxMergeDocs;
int ramSegmentCount = writer.NumBufferedDocuments;
Assert.IsTrue(ramSegmentCount < maxBufferedDocs);
int lowerBound = -1;
int upperBound = maxBufferedDocs;
int numSegments = 0;
int segmentCount = writer.SegmentCount;
for (int i = segmentCount - 1; i >= 0; i--)
{
int docCount = writer.GetDocCount(i);
Assert.IsTrue(docCount > lowerBound, "docCount=" + docCount + " lowerBound=" + lowerBound + " upperBound=" + upperBound + " i=" + i + " segmentCount=" + segmentCount + " index=" + writer.SegString() + " config=" + writer.Config);
if (docCount <= upperBound)
{
numSegments++;
}
else
{
if (upperBound * mergeFactor <= maxMergeDocs)
{
Assert.IsTrue(numSegments < mergeFactor, "maxMergeDocs=" + maxMergeDocs + "; numSegments=" + numSegments + "; upperBound=" + upperBound + "; mergeFactor=" + mergeFactor + "; segs=" + writer.SegString() + " config=" + writer.Config);
}
do
{
lowerBound = upperBound;
upperBound *= mergeFactor;
} while (docCount > upperBound);
numSegments = 1;
}
}
if (upperBound * mergeFactor <= maxMergeDocs)
{
Assert.IsTrue(numSegments < mergeFactor);
}
}