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: u...@thetaphi.de


> -----Original Message-----
> From: Lewis John Mcgibbney [mailto:lewis.mcgibb...@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-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

Reply via email to