The content of this summary I will probably talk about a process of indexfiles.
For ease of view, or put Indexfile.java source code in front.
1:public class Indexfiles {
2:
3:private indexfiles () {}
4:
5:static final File index_dir = new File ("INDEX");
6:
7:/** Index All text files under a directory. */
8:public static void Main (string[] args) {
9:string usage = "java org.apache.lucene.demo.IndexFiles <root_directory>";
10:if (Args.length = = 0) {
11:system.err.println ("Usage:" + Usage);
12:system.exit (1);
13:}
14:
15:if (index_dir.exists ()) {
16:system.out.println ("Cannot Save Index to" "+index_dir+" ' Directory, please delete it ');
17:system.exit (1);
18:}
19:
20:final file Docdir = new file (Args[0]);
21:if (!docdir.exists () | | |!docdir.canread ()) {
22:system.out.println ("Document directory" +docdir.getabsolutepath () + "' does not exist or isn't not readable, pl Ease check the path);
23:system.exit (1);
24:}
25:
26:date start = new Date ();
27:try {
28:indexwriter writer = new IndexWriter (Fsdirectory.open (Index_dir), New StandardAnalyzer (version.lucene_current ), True, IndexWriter.MaxFieldLength.LIMITED);
29:system.out.println ("Indexing to Directory" "+index_dir+");
30:indexdocs (Writer,docdir);
31:system.out.println ("Optimizing ...");
://writer.optimize ();
33:writer.close ();
34:
35:date end = new Date ();
36:system.out.println (End.gettime ()-start.gettime () + "total milliseconds");
37:
: catch (IOException e) {
39:system.out.println ("caught a" + e.getclass () +
: "\ n with message:" + e.getmessage ());
41:}
42:}
43:
44:static void Indexdocs (indexwriter writer, file file)
45:throws IOException {
://Don't try to index files, cannot be read
47:if (File.canread ()) {
48:if (File.isdirectory ()) {
49:string[] files = file.list ();
://An IO error could occur
51:if (Files!= null) {
52:for (int i = 0; i < files.length; i++) {
53:indexdocs (writer, new file (file, files[i));
54:}
55:}
MORE:} else {
57:system.out.println ("adding" + file);
58:try {
59:writer.adddocument (filedocument.document (file));
60:}
://At least in Windows, some temporary files raise this exception with a "Access denied" message
://Checking if the file can be read doesn ' t help
63:catch (FileNotFoundException fnfe) {
64:;
65:}
66:}
67:}
68:}
69:
70:}