lucene: como realizar uma indexação incremental e evitar 'delete and redo'

Eu tenho uma pasta (MY_FILES) que tem cerca de 500 arquivos e cada dia um novo arquivo chega e é colocado lá. O tamanho de cada arquivo é de cerca de 4Mb.

Eu acabei de desenvolver um 'void main' simples para testar se eu posso procurar um curinga específico nesses arquivos. Funciona muito bem.

O problema é que estou excluindo a antiga indexed_folder e reindex novamente. Isso leva muito tempo e, obviamente, é ineficiente. O que estou procurando é uma 'indexação incremental'. Ou seja, se o índice já existir - basta adicionar os novos arquivos ao índice.

Eu queria saber se o Lucene tem algum tipo de mecanismo para verificar se o 'doc' foi indexado antes de tentar indexá-lo. Algo como writer.isDocExists?

Obrigado!

Meu código é assim:

       // build the writer
       IndexWriter writer;
       IndexWriterConfig indexWriter = new IndexWriterConfig(Version.LUCENE_36, analyzer);
       writer = new IndexWriter(fsDir, indexWriter);
       writer.deleteAll();  //must - otherwise it will return duplicated result 
       //build the docs and add to writer
       File dir = new File(MY_FILES);
       File[] files = dir.listFiles();
       int counter = 0;
       for (File file : files) 
       { 
           String path = file.getCanonicalPath();
           FileReader reader = new FileReader(file);
           Document doc = new Document();  
           doc.add(new Field("filename", file.getName(), Field.Store.YES, Field.Index.ANALYZED));
           doc.add(new Field("path", path, Field.Store.YES, Field.Index.ANALYZED));
           doc.add(new Field("content", reader));  

           writer.addDocument(doc);
           System.out.println("indexing "+file.getName()+" "+ ++counter+"/"+files.length);
       }

questionAnswers(2)

yourAnswerToTheQuestion