I am wanting to write back an in-memory Lucene index to disk, overtop of the originally-loaded index. Currently if I call Directory.Copy( _ramDirectory, _fileSystemDirectory, false ), it simply adds the new files to the directory but leaves the old (stale) ones there.
I tried calling:
new IndexWriter( _fsd, _analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED ).Close();
…(to create a new empty index in the directory) but this has strange behavior and sometimes results in the entire index being wiped clean on the next run of the program.
Is there any way I can simply get a list of the files a file system index is currently using so I can delete them manually? I don’t want to blindly erase all files in the directory in case there are some non-index files there.
Apparently FSDirectory.ListAll() lists all files in the physical directory, whether or not they are actually part of the index. Is there any way I can tell if a particular file is used/created by the index? I mean I can’t even check file extensions due to Lucene’s bizarre file naming conventions.
I’d definitely recommend that you dont mix other files in a Lucene index folder.
The best solution would be to create a new index using the IndexWriter constructor that has the create parameter, which will create a new index at the location. Then you use the
IndexWriter.AddIndexesNoOptimize(Directory[] dirs)method to add your RamDirectory to the FSDirectory