[Yanel-dev] Lucene Index Issue: AlreadyClosedException

basZero baszero at gmail.com
Mon Jul 4 10:19:23 CEST 2011


Hi,

just wanted to share this, although a final solution to the problem has not
been found yet.

1)
LuceneSearcher today is creating the searcher object like this:

   org.apache.lucene.search.Searcher searcher = new IndexSearcher
(getConfig().getFulltextSearchIndexFile().getAbsolutePath());

This has the following disadvantages:
- It opens the searcher in read/write mode --> worse performance compared to
read-only mode, and can cause LockException if two threads are instantiating
the searcher object at the same time. (occurs only under high load).
- The constructor is deprecated

2)
The version I am using in my realm at this moment is the following:

   org.apache.lucene.search.Searcher searcher = new
IndexSearcher(getConfig().getFulltextSearchIndexFile().getAbsolutePath(),
true);

Advantage:
- read-only mode, better performance and no LockExceptions

3)
With solution 2) I sometimes see an AlreadyClosedException in the logs. I
now switched to a version which does not use any deprecated API anymore in
the hope that the exception will disappear.

   Directory directory = FSDirectory.open(config
.getFulltextSearchIndexFile());

IndexSearcher searcher = new IndexSearcher(directory, true);


The only question I still have is whether the directory object should get
closed too.
Cheers
Balz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wyona.org/pipermail/yanel-development/attachments/20110704/6ebfc3e5/attachment.html>


More information about the Yanel-development mailing list