lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anson <an...@linkclub-staff.com>
Subject Re: Should the IndexSearcher be closed after very search completed
Date Mon, 09 Jul 2007 08:06:55 GMT
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


Mime
View raw message