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

AddDocument() public method

Adds a document to this index. If the document contains more than SetMaxFieldLength(int) terms for a given field, the remainder are discarded.

Note that if an Exception is hit (for example disk full) then the index will be consistent, but this document may not have been added. Furthermore, it's possible the index will have one segment in non-compound format even when using compound files (when a merge has partially succeeded).

This method periodically flushes pending documents to the Directory (see above), and also periodically triggers segment merges in the index according to the MergePolicy in use.

Merges temporarily consume space in the directory. The amount of space required is up to 1X the size of all segments being merged, when no readers/searchers are open against the index, and up to 2X the size of all segments being merged when readers/searchers are open against the index (see Optimize() for details). The sequence of primitive merge operations performed is governed by the merge policy.

Note that each term in the document can be no longer than 16383 characters, otherwise an IllegalArgumentException will be thrown.

Note that it's possible to create an invalid Unicode string in java if a UTF16 surrogate pair is malformed. In this case, the invalid characters are silently replaced with the Unicode replacement character U+FFFD.

NOTE: if this method hits an OutOfMemoryError you should immediately close the writer. See above for details.

public AddDocument ( Lucene.Net.Documents.Document doc ) : void
doc Lucene.Net.Documents.Document
return void
		public virtual void  AddDocument(Document doc)
		{
			AddDocument(doc, analyzer);
		}
		

Same methods

IndexWriter::AddDocument ( Lucene.Net.Documents.Document doc, Lucene.Net.Analysis.Analyzer analyzer ) : void

Usage Example

        public void SetUp()
        {

            var writer = new IndexWriter(store, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);

            var doc = new Document();
            doc.Add(new Field("aaa", "foo", Field.Store.YES, Field.Index.ANALYZED));
            writer.AddDocument(doc);

            doc = new Document();
            doc.Add(new Field("aaa", "foo", Field.Store.YES, Field.Index.ANALYZED));
            writer.AddDocument(doc);

            doc = new Document();
            doc.Add(new Field("contents", "Tom", Field.Store.YES, Field.Index.ANALYZED));
            writer.AddDocument(doc);

            doc = new Document();
            doc.Add(new Field("contents", "Jerry", Field.Store.YES, Field.Index.ANALYZED));
            writer.AddDocument(doc);

            doc = new Document();
            doc.Add(new Field("zzz", "bar", Field.Store.YES, Field.Index.ANALYZED));
            writer.AddDocument(doc);

            writer.Optimize();
            writer.Close();
        }
All Usage Examples Of Lucene.Net.Index.IndexWriter::AddDocument
IndexWriter