lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Björn Ekengren <>
Subject Problem updating index while reader is open
Date Wed, 23 Aug 2006 11:04:23 GMT
If I try to add documents to an index while a reader is open I get en error message saying
"Cannot delete C:\myindex\_3n.f0". I suspect that this is due to the fact that the windows
fs won't allow deletion of a file when there is a filehandler connected to it. The solution
I have at the moment is this:

            boolean isWindows = System.getProperty("").indexOf("indows")!=-1;
            IndexReader reader = searcher.getIndexSearcher().getIndexReader();
            try {
                    reader.close(); // Need to close reader on windows since the windows file
system won't allow deletion of a file with an open filehandler
                IIndexer indexer = searcher.getIndexer();
                addedDocuments = indexer.rebuildIndex();
                    searcher.setIndexSearcher(new IndexSearcher(searcher.getIndexDir()));//restore
index searcher
            } catch (IOException e) {

However this means that I cannot search the index while updating it (or in this case rebuilding
it completely). Are there any workaround for this ? Maybe you could rebuild the index into
another place on the disk and when it is finished set the searcher to operate in the new place.
This would lead to that it is not possible to query the new index until finished. Could you
get around this if you build the new index as a RamDirectory which is flushed to disk when
finished ?



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message