Lucene.Net.Index.IndexWriter.AddDocument C# (CSharp) Méthode

AddDocument() public méthode

Adds a document to this index, using the provided analyzer instead of the value of GetAnalyzer(). If the document contains more than SetMaxFieldLength(int) terms for a given field, the remainder are discarded.

See AddDocument(Document) for details on index and IndexWriter state after an Exception, and flushing/merging temporary free space requirements.

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

public AddDocument ( Lucene.Net.Documents.Document doc, Lucene.Net.Analysis.Analyzer analyzer ) : void
doc Lucene.Net.Documents.Document
analyzer Lucene.Net.Analysis.Analyzer
Résultat void
		public virtual void  AddDocument(Document doc, Analyzer analyzer)
		{
			EnsureOpen();
			bool doFlush = false;
			bool success = false;
			try
			{
				try
				{
					doFlush = docWriter.AddDocument(doc, analyzer);
					success = true;
				}
				finally
				{
					if (!success)
					{
						
						if (infoStream != null)
							Message("hit exception adding document");
						
						lock (this)
						{
							// If docWriter has some aborted files that were
							// never incref'd, then we clean them up here
							if (docWriter != null)
							{
                                ICollection<string> files = docWriter.AbortedFiles();
								if (files != null)
									deleter.DeleteNewFiles(files);
							}
						}
					}
				}
				if (doFlush)
					Flush(true, false, false);
			}
			catch (System.OutOfMemoryException oom)
			{
				HandleOOM(oom, "addDocument");
			}
		}
		

Same methods

IndexWriter::AddDocument ( Lucene.Net.Documents.Document doc ) : 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