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 Cocula Remi <rc...@sopragroup.com> on 2005/01/19 18:14:56 UTC

closing an IndexSearcher

Hi ,

I remarked that after closing an IndexSearcher, queries on this Seacher will still run.
My question is : why not always closing an IndexSearcher ?
In my case I need to close all indexsearchers when I want to rebuild the index.



Sample code 
-----------------------------------------------------
searcher = new IndexSearcher("c:\\tmp\\index");
searcher.close();

Query query = QueryParser.parse("toto","text",ana);
			
			
Hits hits = searcher.search(query);
System.out.println(hits.length());
for (int i=0;i<hits.length();i++)
{
	Document d = hits.doc(i);
	System.out.println(d.get("text"));
}
System.out.println("fin");
---------------------------------------------------

Re: closing an IndexSearcher

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jan 19, 2005, at 12:14 PM, Cocula Remi wrote:

>
> Hi ,
>
> I remarked that after closing an IndexSearcher, queries on this 
> Seacher will still run.
> My question is : why not always closing an IndexSearcher ?

IndexSearcher.close:

   public void close() throws IOException {
     if(closeReader)
       reader.close();
   }

However, you open it with a String:

> -----------------------------------------------------
> searcher = new IndexSearcher("c:\\tmp\\index");

Which should close the underlying IndexReader.

Maybe this was a bug that has since been fixed in CVS (which is the 
code I'm referencing)?

	Erik


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