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 anson <an...@linkclub-staff.com> on 2007/07/09 09:51:41 UTC

Should the IndexSearcher be closed after very search completed

Hi,

Should the IndexSearcher instance be closed after very search completed.

I wrote a sample, but I have not closed the singleton instatnce of 
IndexSearcher unless IndexReader#isCurrent() return false.

Now the sample runs well, but I saw almost other samples would close the  
IndexSearcher instance on the end of very search.

Should I do it like them?

By the way, I use the constructor IndexSearcher(Directory directory), so  
should I call the method IndexSearcher.close()?


------------------------------------
the Code sample:
------------------------------------
public IndexSearcher getIndexSearcher() throws IOException {
		
	if (this.indexSearcher == null) {
		return new IndexSearcher(getIndexDirectory());
	} else {
		IndexReader ir = indexSearcher.getIndexReader();
		if(!ir.isCurrent()){
			this.indexSearcher.close();
			this.indexSearcher=new IndexSearcher
(getIndexDirectory());
			ir=indexSearcher.getIndexReader();
			if(ir.hasDeletions()){
				if (this.indexWriter != null) {
					this.indexWriter.optimize();
				}	
			}
		}
		return this.indexSearcher;
	}
}


Best regards
Anson

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Should the IndexSearcher be closed after very search completed

Posted by anson <an...@linkclub-staff.com>.
sorry, the subject should be "Should the IndexSearcher be closed after 
every search completed"
~~~~~
>Hi,
>
>Should the IndexSearcher instance be closed after very search completed.
>
>I wrote a sample, but I have not closed the singleton instatnce of 
>IndexSearcher unless IndexReader#isCurrent() return false.
>
>Now the sample runs well, but I saw almost other samples would close the  
>IndexSearcher instance on the end of very search.
>
>Should I do it like them?
>
>By the way, I use the constructor IndexSearcher(Directory directory), so  
>should I call the method IndexSearcher.close()?
>
>
>------------------------------------
>the Code sample:
>------------------------------------
>public IndexSearcher getIndexSearcher() throws IOException {
>		
>	if (this.indexSearcher == null) {
>		return new IndexSearcher(getIndexDirectory());
>	} else {
>		IndexReader ir = indexSearcher.getIndexReader();
>		if(!ir.isCurrent()){
>			this.indexSearcher.close();
>			this.indexSearcher=new IndexSearcher
>(getIndexDirectory());
>			ir=indexSearcher.getIndexReader();
>			if(ir.hasDeletions()){
>				if (this.indexWriter != null) {
>					this.indexWriter.optimize();
>				}	
>			}
>		}
>		return this.indexSearcher;
>	}
>}
>
>
>Best regards
>Anson
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>For additional commands, e-mail: java-user-help@lucene.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org