On Thu, 2006-07-27 at 11:06 +0200, Björn Ekengren wrote: > Thancks everybody for the feedback. I now rewrote my app like this: > > synchronized (searcher.getWriteLock()){ > IndexReader reader = searcher.getIndexSearcher().getIndexReader(); > try { > reader.deleteDocuments(new Term("id",id)); > reader.close(); > IIndexer indexer = searcher.getIndexer(); > addedDocuments = indexer.addDocument(id); //creates and close > writer > reader = IndexReader.open(searcher.getIndexDir()); > } catch (IOException e) { > e.printStackTrace(); > } > } > > Now there are write locks only during the short period the synchronized > block runs. It gets a lot of opening and closing of the reader and > writer but I guess that is the way is has to be.
No, you should not have to do that. Do as I wrote: > If you need to update lots of documents in your corpus (delete and > add) then first delete the documents with the reader, close it and add > them again with the writer. And then close the writer when you are > done. And don't open it again until you need to add documents again. So something like this instead: > IndexReader reader = new IndexReader(dir); > for (MyDocument doc : myDocuments) { > reader.deleteDocuments(new Term("id", id); > } > reader.close(); > IndexWriter writer = new IndexWriter(dir, analyzer, false); > for (MyDocument doc : myDocuments) { > writer.addDocument(luceneDocFactory(doc)); > } > writer.close(); > setSearcher(new IndexSearcher(dir)); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]