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

DeleteDocuments() public method

Deletes all documents that have a given term indexed. This is useful if one uses a document field to hold a unique ID string for the document. Then to delete such a document, one merely constructs a term with the appropriate field and the unique ID string as its text and passes it to this method. See DeleteDocument(int) for information about when this deletion will become effective. since this reader was opened has this index open (write.lock could not be obtained)
public DeleteDocuments ( Lucene.Net.Index.Term term ) : int
term Lucene.Net.Index.Term
return int
		public virtual int DeleteDocuments(Term term)
		{
			EnsureOpen();
			TermDocs docs = TermDocs(term);
			if (docs == null)
				return 0;
			int n = 0;
			try
			{
				while (docs.Next())
				{
					DeleteDocument(docs.Doc);
					n++;
				}
			}
			finally
			{
				docs.Close();
			}
			return n;
		}
		

Usage Example

Example #1
0
 /// <summary> Deletes all documents containing <code>term</code>.
 /// This is useful if one uses a document field to hold a unique ID string for
 /// the document.  Then to delete such a document, one merely constructs a
 /// term with the appropriate field and the unique ID string as its text and
 /// passes it to this method.  Returns the number of documents deleted.
 /// </summary>
 /// <returns> the number of documents deleted
 /// </returns>
 /// <seealso cref="IndexReader#DeleteDocuments(Term)">
 /// </seealso>
 /// <throws>  IllegalStateException if the index is closed </throws>
 public virtual int DeleteDocuments(Term term)
 {
     lock (directory)
     {
         AssureOpen();
         CreateIndexReader();
         return(indexReader.DeleteDocuments(term));
     }
 }
All Usage Examples Of Lucene.Net.Index.IndexReader::DeleteDocuments