The on-disk index gets updated.  Something like this:
The second indexDoc function is what does the actual indexing, but this should have the relevant content. public void indexDoc(int userId) throws ClassNotFoundException, SQLException, CorruptIndexException, IOException
   {
       IndexWriter iw=new IndexWriter(indexName, analyzer, false);
       deleteDoc(userId, iw);
       ResultSet rs=sg.getSomeData(userId);
       indexDoc(iw,rs);
       iw.close();
   }

Russ


Erick Erickson wrote:
I can't speak to the errors, but how is the index being updated? An
indexwriter buffers changes and periodically flushes them out to
disk. So the writer may not have flushed your data, depending
upon how it's written.

Best
Erick

On Dec 11, 2007 5:37 PM, Ruslan Sivak <[EMAIL PROTECTED]> wrote:

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)
       {
           lastCheck=System.currentTimeMillis();
           if (reader==null || !reader.isCurrent())
           {
               if (reader!=null)
                   reader.close();

               Directory dir = new RAMDirectory(indexName);
               reader = IndexReader.open(dir);
               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() !=
IndexReader.getCurrentVersion(indexName))


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?

Russ

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





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

Reply via email to