Delete all indices in Lucene.net

故事扮演 提交于 2019-12-01 16:39:29

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.

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();
        });

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);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!