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); } }