> -----Original Message----- > From: Doug Cutting [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, July 16, 2002 6:44 PM > To: Lucene Users List > Subject: Re: CachedSearcher > > > Kelvin Tan wrote: > > If the object has a close() method with public modifier, > isn't it a common > > idiom that client code needs to invoke close() explicitly? > If there's no > > real need to call close, maybe it can be changed to protected? > > Yes, that is a common idiom. In the case of Lucene's > FSDirectory, it's still a > good idea to close it when you know its no longer needed, to > minimize the > number of open files, but sometimes it is difficult to know > when it is no > longer needed. Finalizers are intended for precisely this > purpose. But you're > right, probably this should be better documented. > > Doug > > Doug! I made an IndexReaderCache class from the code you have sent (the code in demo/Search.jhtml). But this causes exception: IndexSearcher searcher = new IndexSearcher(cache.getReader("/data/index")); searcher.close(); searcher = new IndexSearcher(cache.getReader("/data/index")); searcher.search(aQuery); when I call the close method the searcher closes the indexreader but the cache (or your getReader method) returns the closed reader one more time that's why I made a subclass of searcher that can be closed if the user doesn't want to use it any more you wrote: "sometimes it is difficult to know when it is no longer needed" I think: "use a cache and you don't have to know when it is no longer needed!" ;) peter
IndexReaderCache.java
Description: IndexReaderCache.java
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
