lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Helen Warren <helen.war...@torchbox.com>
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 = IndexReader.open(indexName);
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 
documents.

// Do the search
hits = searcher.search(overallQuery);
	
//close the IndexSearcher object
searcher.close();

//close the IndexReader object
myReader.close();

//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 = IndexReader.open(indexName);
IndexSearcher searcher = new IndexSearcher(myReader);
	
//try to do something with the reader
Collection theseFields = myReader.getFieldNames();
	
//close the IndexSearcher object
searcher.close();
	
//try to close the reader now
myReader.close();
	
//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?

Thanks,
Helen.

	


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


Mime
View raw message