lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mylnikov Sergey <semy...@yandex.ru>
Subject How to close IndexSearcher so that index file gets released?
Date Mon, 16 Aug 2010 13:21:47 GMT
Hi,

I want to be able to regenerate index from time to time. I'm using IndexSearcher for search
and want to be able to release the current index file so that I can replace it with the new
one. But once IndexSearcher is instantiated it does not seem to release index file even if
I call close().

I'm running the test on Windows XP. Here is a short test that I use:

String indexDir = "C:/IndexTemp2/index/";
IndexSearcher searcher = new IndexSearcher(new MMapDirectory(new File(indexDir)));
searcher.close();
/*
 Trying to see if the index file can be modified
 */
new FileWriter(indexDir + "_0.cfs");
/*
 java.io.FileNotFoundException: C:\IndexTemp2\index\_0.cfs 
 (The requested operation cannot be performed on a file with a user-mapped section open.)
 */

After I close IndexSearcher I try to check if I can modify file, but it is in use.

Could someone tell me what is the correct way to close the IndexReader?

I will try to attach the JUnit test class and index directory as ZIP archive to this message.

Thanks,
Sergey

Mime
View raw message