From c02126a21cb8e2b0564d245b6cd24e7616f9c7d7 Mon Sep 17 00:00:00 2001 From: Daniel Naber Date: Thu, 2 Sep 2004 21:45:23 +0000 Subject: [PATCH] Don't just silently delete the "index" directory if it exists but throw an error. Be a bit more verbose. git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150480 13f79535-47bb-0310-9956-ffa450edef68 --- src/demo/org/apache/lucene/demo/IndexFiles.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/demo/org/apache/lucene/demo/IndexFiles.java b/src/demo/org/apache/lucene/demo/IndexFiles.java index 1ff376542e5..443ca3ecf9a 100644 --- a/src/demo/org/apache/lucene/demo/IndexFiles.java +++ b/src/demo/org/apache/lucene/demo/IndexFiles.java @@ -26,6 +26,8 @@ import java.util.Date; class IndexFiles { + static final File INDEX_DIR = new File("index"); + public static void main(String[] args) { String usage = "java org.apache.lucene.demo.IndexFiles "; if (args.length == 0) { @@ -33,16 +35,22 @@ class IndexFiles { System.exit(1); } + if (INDEX_DIR.exists()) { + System.out.println("Cannot save index to '" +INDEX_DIR+ "' directory, please delete it first"); + System.exit(1); + } + Date start = new Date(); try { - IndexWriter writer = new IndexWriter("index", new StandardAnalyzer(), true); + IndexWriter writer = new IndexWriter(INDEX_DIR, new StandardAnalyzer(), true); + System.out.println("Indexing to directory '" +INDEX_DIR+ "'..."); indexDocs(writer, new File(args[0])); + System.out.println("Optimizing..."); writer.optimize(); writer.close(); Date end = new Date(); - System.out.print(end.getTime() - start.getTime()); - System.out.println(" total milliseconds"); + System.out.println(end.getTime() - start.getTime() + " total milliseconds"); } catch (IOException e) { System.out.println(" caught a " + e.getClass() +