lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ruslan Sivak <>
Subject Refreshing RAMDirectory
Date Tue, 11 Dec 2007 22:37:40 GMT
I have an index of about 10mb.  Since it's so small, I would like to 
keep it loaded in memory, and reload it about every minute or so, 
assuming that it has changed on disk.  I have the following code, which 
works, except it doesn't reload the changes. 

protected String indexName;
protected IndexReader reader;
private long lastCheck=0;
protected IndexReader getReader() throws CorruptIndexException, IOException
        if (reader==null || System.currentTimeMillis() > lastCheck+60000)
            if (reader==null || !reader.isCurrent())
                if (reader!=null)
                Directory dir = new RAMDirectory(indexName);
                reader =;
                searcher = new IndexSearcher(reader);
        return reader;

Apparently reader.isCurrent() won't tell you if the underlying 
FSDirectory has changed. 

I also had the following code before:
instead of
if (reader==null || !reader.isCurrent())
I had
if (reader==null || reader.getVersion() != 

I was getting a bunch of this indexreader is closed errors, and I'm not 
sure why there's no method like reader.isClosed().

Am I going about things the right way?  Is there a better implementation 
of what I'm looking to do?  Is there perhaps some function I'm not 
seeing which will let me know if the indexreader is closed?


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

View raw message