lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "no spam" <mrs.nos...@gmail.com>
Subject updating index
Date Wed, 21 Feb 2007 22:42:59 GMT
I have an index where I'm storing the primary key of my database record as
an unindexed field.   Nightly I want to update my search index with any
database changes / additions.

I don't really see an efficient way to update these records besides doing
something like this which I'm worried with thrash the index.  Is this
approach good/bad/ugly?

Thanks,
Mark

IndexReader reader;
ArrayList docsToUpdate;

for (int i = 0; i < reader.maxDoc(); i++)
{
    Document doc = reader.document(i);
    if (doc != null)
    {
       String prinaryKey = doc.getField("id");

        if (docsToUpdate.contains(primaryKey))
        {
             // set fields
             writer.updateDocument(doc);
        }
}

// for all docs not found in index
for (DBObject o : docsToUpdate)
{
    if (o.syncedWithIndex() == false)
    {
       // create new doc
      Document doc = ....;

       // this is a new doc
       writer.addDocument(doc);
    }
}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message