Lucene.Net.Index.IndexWriter.NumDocs C# (CSharp) Method

NumDocs() public method

Returns total number of docs in this index, including docs not yet flushed (still in the RAM buffer), and including deletions. NOTE: buffered deletions are not counted. If you really need these to be counted you should call Commit() first.
public NumDocs ( ) : int
return int
		public virtual int NumDocs()
		{
			lock (this)
			{
				int count;
				if (docWriter != null)
					count = docWriter.NumDocsInRAM;
				else
					count = 0;
				
				for (int i = 0; i < segmentInfos.Count; i++)
				{
					SegmentInfo info = segmentInfos.Info(i);
					count += info.docCount - info.GetDelCount();
				}
				return count;
			}
		}
		

Usage Example

Beispiel #1
0
        private static RAMDirectory MakeEmptyIndex(int numDeletedDocs)
        {
            RAMDirectory d = new RAMDirectory();
            IndexWriter  w = new IndexWriter(d, new WhitespaceAnalyzer(), true, MaxFieldLength.LIMITED, null);

            for (int i = 0; i < numDeletedDocs; i++)
            {
                w.AddDocument(new Document(), null);
            }
            w.Commit(null);
            w.DeleteDocuments(null, new MatchAllDocsQuery());
            w.Commit(null);

            if (0 < numDeletedDocs)
            {
                Assert.IsTrue(w.HasDeletions(null), "writer has no deletions");
            }

            Assert.AreEqual(numDeletedDocs, w.MaxDoc(), "writer is missing some deleted docs");
            Assert.AreEqual(0, w.NumDocs(null), "writer has non-deleted docs");
            w.Close();
            IndexReader r = IndexReader.Open((Directory)d, true, null);

            Assert.AreEqual(numDeletedDocs, r.NumDeletedDocs, "reader has wrong number of deleted docs");
            r.Close();
            return(d);
        }
All Usage Examples Of Lucene.Net.Index.IndexWriter::NumDocs
IndexWriter