Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../../img/srcFileCovDistChart0.png 86% of files have more coverage
13   63   4   6.5
2   28   0.31   2
2     2  
1    
 
  DeleteFiles       Line # 27 13 4 0% 0.0
 
No Tests
 
1    package org.apache.lucene.demo;
2   
3    /**
4    * Copyright 2004 The Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18   
19    import org.apache.lucene.store.Directory;
20    import org.apache.lucene.store.FSDirectory;
21    import org.apache.lucene.index.IndexReader;
22    import org.apache.lucene.index.Term;
23    //import org.apache.lucene.index.Term;
24   
25   
26    /** Deletes documents from an index that do not contain a term. */
 
27    public class DeleteFiles {
28   
 
29  0 toggle private DeleteFiles() {} // singleton
30   
31    /** Deletes documents from an index that do not contain a term. */
 
32  0 toggle public static void main(String[] args) {
33  0 String usage = "java org.apache.lucene.demo.DeleteFiles <unique_term>";
34  0 if (args.length == 0) {
35  0 System.err.println("Usage: " + usage);
36  0 System.exit(1);
37    }
38  0 try {
39  0 Directory directory = FSDirectory.getDirectory("index", false);
40  0 IndexReader reader = IndexReader.open(directory);
41   
42  0 Term term = new Term("path", args[0]);
43  0 int deleted = reader.deleteDocuments(term);
44   
45  0 System.out.println("deleted " + deleted +
46    " documents containing " + term);
47   
48    // one can also delete documents by their internal id:
49    /*
50    for (int i = 0; i < reader.maxDoc(); i++) {
51    System.out.println("Deleting document with id " + i);
52    reader.delete(i);
53    }*/
54   
55  0 reader.close();
56  0 directory.close();
57   
58    } catch (Exception e) {
59  0 System.out.println(" caught a " + e.getClass() +
60    "\n with message: " + e.getMessage());
61    }
62    }
63    }