lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Halácsy Péter <>
Subject RE: CachedSearcher
Date Tue, 16 Jul 2002 22:21:59 GMT

> -----Original Message-----
> From: Doug Cutting []
> 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

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 = new IndexSearcher(cache.getReader("/data/index"));;

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!" ;)


View raw message