lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Meier <>
Subject When is the right time to close() a Searcher?
Date Fri, 21 Nov 2003 03:39:19 GMT

it look's like a cannot close a
before iterating over the Hits
(for most of you this is obvious?)

however, if i do not close the Searcher, everything is fine (concerning 
the search an its results) but some ressources cannot be released as i 
read here in this mailing list.
(in "Lucene is not closing connections to index files")

i'll try to shortly explain what i did, and one of you may be can tell 
me when to close the Searcher (or what i completly did wrong)

I have a class "TestService" (preparing XML for some kind of response).

TestService calls the singleton CmsSearch for to query an Index.

extract of Class CmsSearch (Exception-Handling not shown)
public Hits searchCmsPages(String theQueryStr) throws BasicException {
   Searcher searcher = new IndexSearcher(getCmsPages_INDEX_location());
   Query query = QueryParser.parse(theQueryStr,             		 
TEXT_CONTENTS, getCmsPagesSearchAnalyzer());
   Hits hits =;
   // searcher.close(); // (1)
   return hits;

extract of Class TestService (Exception-Handling not shown)

String queryStr = (String) theRequest.getParameter("query");
if (queryStr == null || queryStr.length() == 0) {
aResponse.put("NO_QUERY_INPUT", "keine Suchparameter");
   return aResponse;
   Hits hits = null;
   BasicException searchEx = null;
     hits = search.searchCmsPages(queryStr);
   }catch(BasicException bex){
     searchEx = bex;
   if (searchEx == null && hits!=null){
     Document luceneDoc = null;
       for (int i = 0; i < hits.length(); i++) {
         try {
           luceneDoc = hits.doc(i); // (2)
           // fetching some fields out of the luceneDoc ...	
         } catch (IOException e2) {
           searchEx = e2;

when i close the searcher (see Extract CmsSearch(1) above ), mostly 
everytime when getting a Lucene-Doc from Hits (2) an IOException is 
thrown: Bad file descriptor

Hm... is it NOT possible, to close the Searcher before iterating over 
the Hits?
Should i close the searcher after iterating?
Or would it make sense to keep a Searcher for a specific Index in a 
static Variable without closing it all the time?

thanks anyway,
christoph meier

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

View raw message