lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler" <...@thetaphi.de>
Subject RE: Necessary to close() IndexSearcher in 4.X?
Date Thu, 04 Apr 2013 06:20:18 GMT
Hi,

In Lucene before 4.0 there was a close method in IndexSearcher, because you were able to create
IndexSearcher using Directory, which internally opened an IndexReader. This IndexReader had
to be closed, so there was a need for IndexSearcher.close().

In 3.x this was constructor (taking Directory/String/File) was deprecated and you now have
to pass an already open IndexReader to the constructor. In 4.x this deprecated stuff was finally
removed and IndexSearcher is only a thin wrapper around IndexReader, so you are responsible
to open/close the IndexReader, IndexSearcher no longer does this.

Your try-finally block must be around IndexReader. But please note: Keep IndexReader open
as long as possible as it is very expensive to open/close them all the time.

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de


> -----Original Message-----
> From: Lewis John Mcgibbney [mailto:lewis.mcgibbney@gmail.com]
> Sent: Thursday, April 04, 2013 4:15 AM
> To: java-user@lucene.apache.org
> Subject: Necessary to close() IndexSearcher in 4.X?
> 
> Hi,
> I am encountering many situations where searcher.close() is present in finally
> blocks such as
> 
>         } finally {
>             if (searcher != null) {
>                 try {
>                     searcher.close();
>                 } catch (Exception ignore) {
>                 }
>                 searcher = null;
>             }
>         }
> 
> Is some similar implementation still necessary in the 4.X API?
> 
> Thank you very much
> 
> Lewis
> 
> --
> *Lewis*


---------------------------------------------------------------------
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