删除Lucene.net中的所有索引

时间:2021-07-05 03:08:21

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

我想删除所有以前创建的索引。我正在使用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?

但我得到错误。任何想法如何去做?

4 个解决方案

#1


16  

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.

删除索引的最佳方法是擦除文件系统目录。但是,如果您不想重新生成索引,最简单的方法是使用create参数为true打开一个新的索引编写器。它将启动一个新索引,删除现有索引的内容。

#2


6  

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.

虽然线程很旧但我认为最好给出答案..对其他人可能有用。 indexWriter的deleteAll()方法可用于删除索引的所有文档。

#3


1  

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

正如Jokin所说,最简单的方法是删除目录中的所有文件。即;

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

#4


0  

From the Lucene.Net API Doc:

来自Lucene.Net API Doc:

public static IndexReader Open(Directory);

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.

专家:使用自定义IndexDeletionPolicy返回读取/写入IndexReader,读取给定目录中的索引。注意:从3.0开始,这将返回readOnly IndexReader。如果索引已损坏,则抛出CorruptIndexException。如果存在低级IO错误,则抛出IOException。

i guess you should try

我猜你应该试试

IndexReader rdr = IndexReader.Open(_directory, true);

#1


16  

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.

删除索引的最佳方法是擦除文件系统目录。但是,如果您不想重新生成索引,最简单的方法是使用create参数为true打开一个新的索引编写器。它将启动一个新索引,删除现有索引的内容。

#2


6  

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.

虽然线程很旧但我认为最好给出答案..对其他人可能有用。 indexWriter的deleteAll()方法可用于删除索引的所有文档。

#3


1  

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

正如Jokin所说,最简单的方法是删除目录中的所有文件。即;

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

#4


0  

From the Lucene.Net API Doc:

来自Lucene.Net API Doc:

public static IndexReader Open(Directory);

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.

专家:使用自定义IndexDeletionPolicy返回读取/写入IndexReader,读取给定目录中的索引。注意:从3.0开始,这将返回readOnly IndexReader。如果索引已损坏,则抛出CorruptIndexException。如果存在低级IO错误,则抛出IOException。

i guess you should try

我猜你应该试试

IndexReader rdr = IndexReader.Open(_directory, true);