Deletes documents from an index that do not contain a term.
String usage = "java org.apache.lucene.demo.DeleteFiles <unique_term>";
if (args.length == 0) {
System.err.println("Usage: " + usage);
System.exit(1);
}
try {
Directory directory = FSDirectory.getDirectory("index", false);
IndexReader reader = IndexReader.open(directory);
Term term = new Term("path", args[0]);
int deleted = reader.deleteDocuments(term);
System.out.println("deleted " + deleted +
" documents containing " + term);
// one can also delete documents by their internal id:
/*
for (int i = 0; i < reader.maxDoc(); i++) {
System.out.println("Deleting document with id " + i);
reader.delete(i);
}*/
reader.close();
directory.close();
} catch (Exception e) {
System.out.println(" caught a " + e.getClass() +
"\n with message: " + e.getMessage());
}