FileDocCategorySizeDatePackage
DeleteFiles.javaAPI DocApache Lucene 2.1.02215Wed Feb 14 10:46:42 GMT 2007org.apache.lucene.demo

DeleteFiles

public class DeleteFiles extends Object
Deletes documents from an index that do not contain a term.

Fields Summary
Constructors Summary
private DeleteFiles()

Methods Summary
public static voidmain(java.lang.String[] args)
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");
      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());
    }