Delete all indices in Lucene.net

前端 未结 4 920
栀梦
栀梦 2021-01-18 02:50

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

I tried the following:

Term term = new Term         


        
相关标签:
4条回答
  • 2021-01-18 03:27

    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.

    0 讨论(0)
  • 2021-01-18 03:27

    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();
            });
    
    0 讨论(0)
  • 2021-01-18 03:36

    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.

    0 讨论(0)
  • 2021-01-18 03:47

    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);
    
    0 讨论(0)
提交回复
热议问题