lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Helen Warren <>
Subject indexReader close method
Date Mon, 06 Dec 2004 14:45:01 GMT
Hi All,
I'm having some trouble closing an index reader. I'm getting a 
IOException (bad file descriptor). Can anybody tell me what I'm doing 
wrong and how I should be closing this object?

An outline of an extract of my code:

// Make a new searcher (indexName passed in as string).
IndexReader myReader =;
searcher = new IndexSearcher(myReader);

//Create a snowball analyzer object.
//Create a MultifieldQueryParser object with the snowball analyzer and 
build a luceneQuery from a user entered search string.
//Create a new BooleanQuery (overallQuery), add the luceneQuery to it 
and add several other BooleanQueries specific to other fields in the 

// Do the search
hits =;
//close the IndexSearcher object

//close the IndexReader object

//return results
return hits;

The myReader.close() line causes the IOException to be thrown. To try 
to debug, I wrote a simplified code to open and close a reader and 
searcher, and in the process discovered something else that I have 
found confusing:
Here's an extract of the simplified code:

String indexName = "foo";

// Make a new searcher
IndexReader myReader =;
IndexSearcher searcher = new IndexSearcher(myReader);
//try to do something with the reader
Collection theseFields = myReader.getFieldNames();
//close the IndexSearcher object
//try to close the reader now
//now try to do something with the reader again;
try {
	int maximum = myReader.maxDoc();
	System.err.println("Next document would be: "+maximum);
catch (Exception e) {
	System.err.println("Exception: "+e.getMessage());	
In this case, the reader appears to close without error but even after 
I've called myReader.close() I can execute the maxDoc() method on that 
object and return results. Anybody shed any light?



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message