01: package org.apache.lucene.demo;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import org.apache.lucene.store.Directory;
21: import org.apache.lucene.store.FSDirectory;
22: import org.apache.lucene.index.IndexReader;
23: import org.apache.lucene.index.Term;
24:
25: //import org.apache.lucene.index.Term;
26:
27: /** Deletes documents from an index that do not contain a term. */
28: public class DeleteFiles {
29:
30: private DeleteFiles() {
31: } // singleton
32:
33: /** Deletes documents from an index that do not contain a term. */
34: public static void main(String[] args) {
35: String usage = "java org.apache.lucene.demo.DeleteFiles <unique_term>";
36: if (args.length == 0) {
37: System.err.println("Usage: " + usage);
38: System.exit(1);
39: }
40: try {
41: Directory directory = FSDirectory.getDirectory("index");
42: IndexReader reader = IndexReader.open(directory);
43:
44: Term term = new Term("path", args[0]);
45: int deleted = reader.deleteDocuments(term);
46:
47: System.out.println("deleted " + deleted
48: + " documents containing " + term);
49:
50: // one can also delete documents by their internal id:
51: /*
52: for (int i = 0; i < reader.maxDoc(); i++) {
53: System.out.println("Deleting document with id " + i);
54: reader.delete(i);
55: }*/
56:
57: reader.close();
58: directory.close();
59:
60: } catch (Exception e) {
61: System.out.println(" caught a " + e.getClass()
62: + "\n with message: " + e.getMessage());
63: }
64: }
65: }
|