I didn't describe the context fully. The app is a server that recieves updates randomly a couple of hundred times a day and I want the index to be updated at all times. If I would recieve several updates at once I could batch it but that is quite unlikely.
_____ Björn Ekengren Bankaktiebolaget Avanza Tel: 08 5622 5055 Fax: 08 5622 5051 Mobil: 0708 618 055 _____ -----Original Message----- From: karl wettin [mailto:[EMAIL PROTECTED] Sent: den 27 juli 2006 11:15 To: java-user@lucene.apache.org Subject: Re: SOLVED: Lock obtain timed out Importance: Low 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]