修订版 | 20 (tree) |
---|---|
时间 | 2011-05-23 19:07:03 |
作者 | linuxchecker |
fixed directory check bug in indexer
@@ -34,13 +34,19 @@ | ||
34 | 34 | public NldIndexer() |
35 | 35 | { |
36 | 36 | super(); |
37 | + if (INDEX_DIR.exists()) { | |
38 | + System.out.println("Cannot save index to '" +INDEX_DIR+ "' directory, please delete it first"); | |
39 | + System.exit(1); | |
40 | + } | |
41 | + | |
37 | 42 | try |
38 | 43 | { |
39 | 44 | final Tagger tagger = new Tagger(IPADIC); |
40 | 45 | final IpadicAnalyzer analyzer = new IpadicAnalyzer(tagger); |
41 | 46 | INDEX_CONFIG = new IndexWriterConfig(Version.LUCENE_31, analyzer); |
42 | - IndexWriter writer = new IndexWriter(FSDirectory.open(INDEX_DIR), INDEX_CONFIG); | |
47 | + writer = new IndexWriter(FSDirectory.open(INDEX_DIR), INDEX_CONFIG); | |
43 | 48 | // new IpadicAnalyzer(tagger), IndexWriter.MaxFieldLength.LIMITED); |
49 | + if(writer==null) throw new IOException("cannot open index directory for writing. Please check permittion"); | |
44 | 50 | }catch(IOException e) |
45 | 51 | { |
46 | 52 | e.printStackTrace(); |
@@ -50,11 +56,6 @@ | ||
50 | 56 | |
51 | 57 | static void indexer(String[] args) |
52 | 58 | { |
53 | - if (INDEX_DIR.exists()) { | |
54 | - System.out.println("Cannot save index to '" +INDEX_DIR+ "' directory, please delete it first"); | |
55 | - System.exit(1); | |
56 | - } | |
57 | - | |
58 | 59 | final File docDir = new File(args[1]); |
59 | 60 | if (!docDir.exists() || !docDir.canRead()) { |
60 | 61 | System.out.println("Document directory '" +docDir.getAbsolutePath()+ "' does not exist or is not readable, please check the path"); |
@@ -88,6 +89,7 @@ | ||
88 | 89 | if (files != null) |
89 | 90 | { |
90 | 91 | for (int i = 0; i < files.length; i++) { |
92 | + System.out.println("progress... ("+i+"/"+files.length+")"); | |
91 | 93 | indexDocs(writer, new File(file, files[i])); |
92 | 94 | } |
93 | 95 | } |