1 | /**
|
---|
2 | *
|
---|
3 | * class for indexing XML generated by lucenebuildproc.pm
|
---|
4 | * @author [email protected]
|
---|
5 | * @author [email protected]
|
---|
6 | * @version
|
---|
7 | */
|
---|
8 |
|
---|
9 |
|
---|
10 | import java.io.*;
|
---|
11 | import java.util.Vector;
|
---|
12 |
|
---|
13 | public class GS2LuceneIndexer {
|
---|
14 |
|
---|
15 | public static void main (String args[]) throws Exception
|
---|
16 | {
|
---|
17 |
|
---|
18 | int verbosity = 1;
|
---|
19 | boolean create = false;
|
---|
20 |
|
---|
21 | Vector filtered_args = new Vector();
|
---|
22 |
|
---|
23 | int argc = args.length;
|
---|
24 | int i = 0;
|
---|
25 | while (i<argc) {
|
---|
26 | if (args[i].startsWith("-")) {
|
---|
27 |
|
---|
28 | // -create causes build to be incremental
|
---|
29 | if (args[i].equals("-create")) {
|
---|
30 | create = true;
|
---|
31 | }
|
---|
32 |
|
---|
33 | // -verbosity [num]
|
---|
34 | else if (args[i].equals("-verbosity")) {
|
---|
35 | i++;
|
---|
36 | if (i<argc) {
|
---|
37 | verbosity = Integer.parseInt(args[i]);
|
---|
38 | }
|
---|
39 | }
|
---|
40 | else {
|
---|
41 | System.out.println("Unrecognised option: " + args[i]);
|
---|
42 | }
|
---|
43 | }
|
---|
44 | else {
|
---|
45 | filtered_args.add((Object)args[i]);
|
---|
46 | }
|
---|
47 | i++;
|
---|
48 | }
|
---|
49 |
|
---|
50 | if (filtered_args.size() != 3) {
|
---|
51 | System.out.println("Usage: java GS2LuceneIndexer [-create|-verbosity [num]] doc-tag-level building_dir index");
|
---|
52 | return;
|
---|
53 | }
|
---|
54 |
|
---|
55 | String doc_tag_level = (String)filtered_args.get(0);
|
---|
56 | String building_dirname = (String)filtered_args.get(1);
|
---|
57 | String index_dirname = (String)filtered_args.get(2);
|
---|
58 |
|
---|
59 | String import_dirname = building_dirname + File.separator + "text";
|
---|
60 |
|
---|
61 | File import_dir = new File(import_dirname);
|
---|
62 | File building_dir = new File(building_dirname);
|
---|
63 |
|
---|
64 | if (!import_dir.exists()) {
|
---|
65 | System.out.println("Couldn't find import directory: "+import_dirname);
|
---|
66 | return;
|
---|
67 | }
|
---|
68 |
|
---|
69 | File idx_dir = new File(building_dir.getPath()+File.separator+index_dirname+File.separator);
|
---|
70 | idx_dir.mkdir();
|
---|
71 |
|
---|
72 | // Set up indexer
|
---|
73 | IndexXML indexer = new IndexXML(doc_tag_level,idx_dir, create);
|
---|
74 | indexer.init();
|
---|
75 |
|
---|
76 | // Read from stdin the files to process
|
---|
77 | try {
|
---|
78 | InputStreamReader isr = new InputStreamReader(System.in, "UTF-8");
|
---|
79 | BufferedReader brin = new BufferedReader(isr);
|
---|
80 |
|
---|
81 | StringBuffer xml_text = new StringBuffer(1024);
|
---|
82 | String line = null;
|
---|
83 | while ((line = brin.readLine()) != null) {
|
---|
84 | xml_text.append(line);
|
---|
85 | if (line.startsWith("</Doc>")) {
|
---|
86 | indexer.indexFile(xml_text.toString());
|
---|
87 | xml_text = new StringBuffer(1024);
|
---|
88 | }
|
---|
89 | //File xml_file = new File(import_dir + File.separator + line);
|
---|
90 | //indexer.indexFile(xml_file); // ****
|
---|
91 | }
|
---|
92 |
|
---|
93 | brin.close();
|
---|
94 | isr.close();
|
---|
95 |
|
---|
96 | } catch (IOException e) {
|
---|
97 | System.err.println("Error: unable to read from stdin");
|
---|
98 | e.printStackTrace();
|
---|
99 | }
|
---|
100 |
|
---|
101 | indexer.finish();
|
---|
102 | }
|
---|
103 | }
|
---|