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

DeleteDocuments() public method

Deletes the document(s) containing any of the terms. All deletes are flushed at the same time.

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

public DeleteDocuments ( ) : void
return void
		public virtual void  DeleteDocuments(params Term[] terms)
		{
			EnsureOpen();
			try
			{
				bool doFlush = docWriter.BufferDeleteTerms(terms);
				if (doFlush)
					Flush(true, false, false);
			}
			catch (System.OutOfMemoryException oom)
			{
				HandleOOM(oom, "deleteDocuments(params Term[])");
			}
		}
		

Same methods

IndexWriter::DeleteDocuments ( Lucene.Net.Search.Query query ) : void
IndexWriter::DeleteDocuments ( Lucene.Net.Index.Term term ) : void

Usage Example

        //END
        //this method creates document from an ObjectToIndex
        public void BuildIndex(FileToIndex file)
        {
            using (var analyzer = new Lucene.Net.Analysis.Ru.RussianAnalyzer(Version.LUCENE_30))
            {
                using (IndexWriter idxw = new IndexWriter(_directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
                {
                    //check if document exists, if true deletes existing

                    var searchQuery = new TermQuery(new Term("Id", file.Id.ToString()));
                    idxw.DeleteDocuments(searchQuery);
                    //creation
                    Document doc = new Document();
                    doc.Add(new Field("Id", file.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));//аналайзер разбивает строки на слова
                    doc.Add(new Field("Title", file.Title, Field.Store.YES, Field.Index.ANALYZED));
                    doc.Add(new Field("Description", file.Description, Field.Store.YES, Field.Index.ANALYZED));
                    doc.Add(new Field("Authors", file.Authors, Field.Store.YES, Field.Index.ANALYZED));
                    doc.Add(new Field("Text", file.Text, Field.Store.YES, Field.Index.ANALYZED));
                    doc.Add(new Field("Hashtags", file.Hashtags, Field.Store.YES, Field.Index.ANALYZED));
                    doc.Add(new Field("Discipline", file.Discipline, Field.Store.YES, Field.Index.ANALYZED));
                    //write the document to the index
                    idxw.AddDocument(doc);
                    //optimize and close the writer
                    idxw.Commit();

                    idxw.Optimize();

                }
            }
        }
All Usage Examples Of Lucene.Net.Index.IndexWriter::DeleteDocuments
IndexWriter