问题
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?
回答1:
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.
回答2:
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.
回答3:
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();
});
回答4:
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);
来源:https://stackoverflow.com/questions/196509/delete-all-indices-in-lucene-net