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("os.name").indexOf("indows")!=-1;
            IndexReader reader = searcher.getIndexSearcher().getIndexReader();
            try {
                if(isWindows)
                    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();
                if(isWindows)
                    searcher.setIndexSearcher(new 
IndexSearcher(searcher.getIndexDir()));//restore index searcher
            } catch (IOException e) {
                e.printStackTrace();
            }

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 ?

--regards

/Bjorn

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to