lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guillermo Payet <gpa...@localharvest.org>
Subject Re: running out of file handles
Date Fri, 15 Apr 2005 04:36:55 GMT
> Are you opening a new IndexSearcher when you see a new index version
> (using IndexReader.getCurrentVersion())?  If so, you may need to
> explicitly call close() on your IndexSearcher before opening a new
> one.

no.. I'm not doing that.. but the index get's updated very
seldom.  Maybe 4 times a day. The process that regenerates the 
index also reloads the bean that contains the IndexSearcher.
Even if that was the source of the leak, it wouldn't account
for hundreds in a few hours.

> Also note that IndexSearcher has 3 constructors.  Two of them
> automatically close the underlying IndexReader, but one does not.  So
> if you're calling the IndexSearcher constructor that takes an
> IndexReader parameter, you also need to close the IndexReader
> yourself.

See above...

> If this doesn't help, can you post your code for us?  

Sure.. I'm posting it all below.

Thanks!

    --G

-------------------------------------------------------------------------------
Bean instantiation:
-------------------------------------------------------------------------------

<jsp:useBean id="indexer" class="com.oceangroup.projects.localharvest.LHIndexer" scope="application"
><%
    indexer.setIndexDir(request.getRealPath("/../index/store/"));
%></jsp:useBean>

-------------------------------------------------------------------------------
Bean:
-------------------------------------------------------------------------------
package com.oceangroup.projects.localharvest;

import com.oceangroup.beans.sql.*;
import java.util.*;
import java.io.*;

import org.apache.lucene.search.*;
import org.apache.lucene.store.*;

public class LHIndexer {

    private String dirPath = null;
    private static IndexSearcher is = null;

    public LHIndexer () {
    }

    public void setIndexDir (String aPath) throws IOException {
        this.dirPath = aPath;
        reload();
    }

    public void reload() throws IOException {
        File indexDir = new File(this.dirPath);
        Directory fsDir = FSDirectory.getDirectory(indexDir, false);
        synchronized (this) {
            is = new IndexSearcher(fsDir);
        }
    }

    public IndexSearcher getSearcher(){
        return this.is;
    }
}

-------------------------------------------------------------------------------
Search Code:
-------------------------------------------------------------------------------
String[] fields = {"name","longDesc"};
Query lQuery = MultiFieldQueryParser.parse(q, fields, new SnowballAnalyzer("English"));
hits = is.search(lQuery);

-------------------------------------------------------------------------------
Index Re-Generation  Code:
-------------------------------------------------------------------------------
No need to add it all here, I think, but it generates the indexer, and then calls:

indexer.reload();


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


Mime
View raw message