You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Lewis John Mcgibbney <le...@gmail.com> on 2013/04/04 04:15:14 UTC

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*

Re: Necessary to close() IndexSearcher in 4.X?

Posted by Lewis John Mcgibbney <le...@gmail.com>.
Thanks for feeback Uwe.
I'll not be looking at this until again tomorrow so at least this gives me
time to think it through.

On Wednesday, April 3, 2013, Uwe Schindler <uw...@thetaphi.de> wrote:
> 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
>
>

-- 
*Lewis*

RE: Necessary to close() IndexSearcher in 4.X?

Posted by Uwe Schindler <uw...@thetaphi.de>.
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