Delete all indices in Lucene.net

k03123 picture k03123 · Oct 13, 2008 · Viewed 7.7k times · Source

I want to delete all the previously created indices. I am using Lucene.net.

I tried the following:

Term term = new Term(); //empty because I want to delete all the indices
IndexReader rdr = IndexReader.Open(_directory);

rdr.DeleteDocuments(term);
rdr.Close();

But I get error. Any idea how to go about it?

Answer

Jokin picture Jokin · Oct 23, 2008

The best way to delete an index is to wipe the filesystem directory. However, if you wan't to regenerate the index, the easiest way is to open a new indexwriter with the create parameter as true. It will start a new index deleting the contents of the existing one.