If you are going to be searching the same index, just keep that
instance of IndexSearcher around, and close it only when you no longer
need it, or when you detect that the index changed (e.g. docs
added/deleted), at which point you will want to close the old
IndexSearcher (or just throw it away and let the GC deal with it), and
get a new one.

This may actually exist as a FAQ, and if not, it's been addressed in
the past, so the list archives will have more information.

Otis

--- Christoph Meier <[EMAIL PROTECTED]> wrote:
> 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]
> 


__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

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

Reply via email to