lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From karl wettin <karl.wet...@gmail.com>
Subject Re: SOLVED: Lock obtain timed out
Date Thu, 27 Jul 2006 09:15:21 GMT
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: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message