I want to delete all the previously created indices. I am using Lucene.net
.
I tried the following:
Term term = new Term
although the thread is old i think it's better to give answer.. might be useful for somebody else. deleteAll() method of IndexWriter can be used to delete all documents indexed.
As Jokin said, the easiest was is to delete all of the files within the directory. i.e.;
DirectoryInfo directoryInfo = new DirectoryInfo(@"IndexLocation");
Parallel.ForEach(directoryInfo.GetFiles(), file => {
file.Delete();
});
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.
From the Lucene.Net API Doc:
public static IndexReader Open(Directory);
Expert: Returns a read/write IndexReader reading the index in the given Directory, with a custom IndexDeletionPolicy. NOTE: Starting in 3.0 this will return a readOnly IndexReader. Throws CorruptIndexException if the index is corrupt. Throws IOException if there is a low-level IO error.
i guess you should try
IndexReader rdr = IndexReader.Open(_directory, true);