• R/O
  • SSH
  • HTTPS

nls: 提交


Commit MetaInfo

修订版20 (tree)
时间2011-05-23 19:07:03
作者linuxchecker

Log Message

fixed directory check bug in indexer

更改概述

差异

--- src/org/mathsci/distance/NldIndexer.java (revision 19)
+++ src/org/mathsci/distance/NldIndexer.java (revision 20)
@@ -34,13 +34,19 @@
3434 public NldIndexer()
3535 {
3636 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+
3742 try
3843 {
3944 final Tagger tagger = new Tagger(IPADIC);
4045 final IpadicAnalyzer analyzer = new IpadicAnalyzer(tagger);
4146 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);
4348 // new IpadicAnalyzer(tagger), IndexWriter.MaxFieldLength.LIMITED);
49+ if(writer==null) throw new IOException("cannot open index directory for writing. Please check permittion");
4450 }catch(IOException e)
4551 {
4652 e.printStackTrace();
@@ -50,11 +56,6 @@
5056
5157 static void indexer(String[] args)
5258 {
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-
5859 final File docDir = new File(args[1]);
5960 if (!docDir.exists() || !docDir.canRead()) {
6061 System.out.println("Document directory '" +docDir.getAbsolutePath()+ "' does not exist or is not readable, please check the path");
@@ -88,6 +89,7 @@
8889 if (files != null)
8990 {
9091 for (int i = 0; i < files.length; i++) {
92+ System.out.println("progress... ("+i+"/"+files.length+")");
9193 indexDocs(writer, new File(file, files[i]));
9294 }
9395 }
Show on old repository browser