Hi

it look's like a cannot close a org.apache.lucene.search.Searcher
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.search(query);
// 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;
}else{
  Hits hits = null;
  BasicException searchEx = null;
  try{
    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;
          break;
        }
      }
    }
  }
//---------

when i close the searcher (see Extract CmsSearch(1) above ), mostly everytime when getting a Lucene-Doc from Hits (2) an IOException is thrown: java.io.IOException: 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,
greez,
christoph meier


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to