I have a basic search engine,(used lucene) which searches for text in documents (.txt) given in the directory. I need help how to update the indexes of modified/deleted documents.

有帮助吗?

解决方案

If I understand your added comment, you want to watch your directory of .txt files, then only re-index the files that changed. There are some classes in the java.nio.file package that should help.

Here is an overview: http://docs.oracle.com/javase/tutorial/essential/io/notification.html#overview.

其他提示

To Delete lucene document you can do something like this:

Term keyTerm = new Term(String fld, String text);
    try{
        indexWriter.deleteDocuments(keyTerm);
    }catch(IOException exp){
        //handle exception
    }

And for updating documents, there is a build in method :

    updateDocument(Term term, Iterable<? extends IndexableField> doc)

Updates a document by first deleting the document(s) containing term and then adding the new document.

So from the documentation, first it deleting the document and the add it again, so simply you can do first delete the document using the above approach and then add it again.

for example:

// 1) delete the document 
indexWriter.deleteDocuments(keyTerm);

// 2) add it again.
indexWriter.addDocument(luceneDoc);

Check IndexWriter for more details.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top