IndexWriter writer = new IndexWriter(directory, analyzer, false); //open the index writer with appropriate analyzer writer.DeleteDocuments(new Term("id", "1234")); //delete the document with id value = 1234 writer.Commit(); //commit the changes to the index writer so that they are written to disk
IndexWriter writer = new IndexWriter(directory, analyzer, false); //open the index writer with appropriate analyzer TermQuery query = new TermQuery(new Term("category", "sports")); //create a query to fetch all documents in the 'sports' category writer.DeleteDocuments(query); //delete all documents matching the query i.e. all documents in 'sports' category writer.Commit(); //commit the changes to the index writer so that they are written to diskIn both examples above, the method DeleteDocuments is called with an argument that specifies which documents to delete. The first example deletes a single document with a specific ID, whereas the second example uses a query to delete multiple documents. After deleting the documents, the changes are committed to the index writer using the Commit method. The Lucene.Net library can be downloaded and installed using NuGet package manager.
NOTE: if this method hits an OutOfMemoryError you should immediately close the writer. See above for details.
public DeleteDocuments ( ) : void | ||
return | void |