tags:

views:

435

answers:

2

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

i tried the following:

Term term = new Term(); //empty coz 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?

+1  A: 

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.

Jokin
A: 

As Jokin said, the easiest was is to delete all of the file within the directory. i.e.;

DirectoryInfo directoryInfo = new DirectoryInfo(@"IndexLocation");
Parallel.ForEach(directoryInfo.GetFiles(), file => {
            file.Delete();
        });
Jeremy