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 |
|
---|
12 | public class GS2LuceneIndexer {
|
---|
13 |
|
---|
14 | public static void main (String args[]) throws Exception {
|
---|
15 | if (args.length != 3) {
|
---|
16 | System.out.println("Usage: java GS2LuceneIndexer doc-tag-level building_dir index");
|
---|
17 | return;
|
---|
18 | }
|
---|
19 |
|
---|
20 | String doc_tag_level = args[0];
|
---|
21 | String building_dirname = args[1];
|
---|
22 | String index_dirname = args[2];
|
---|
23 |
|
---|
24 | String import_dirname = building_dirname + File.separator + "text";
|
---|
25 |
|
---|
26 | File import_dir = new File(import_dirname);
|
---|
27 | File building_dir = new File(building_dirname);
|
---|
28 |
|
---|
29 | if (!import_dir.exists()) {
|
---|
30 | System.out.println("Couldn't find import directory: "+import_dirname);
|
---|
31 | return;
|
---|
32 | }
|
---|
33 |
|
---|
34 | File idx_dir = new File(building_dir.getPath()+File.separator+index_dirname+File.separator);
|
---|
35 | idx_dir.mkdir();
|
---|
36 |
|
---|
37 | // Set up indexer
|
---|
38 | IndexXML indexer = new IndexXML(doc_tag_level,idx_dir);
|
---|
39 | indexer.init();
|
---|
40 |
|
---|
41 | // Read from stdin the files to process
|
---|
42 | try {
|
---|
43 | InputStreamReader isr = new InputStreamReader(System.in);;
|
---|
44 | BufferedReader brin = new BufferedReader(isr);
|
---|
45 |
|
---|
46 | StringBuffer xml_text = new StringBuffer(1024);
|
---|
47 | String line = null;
|
---|
48 | while ((line = brin.readLine()) != null) {
|
---|
49 | xml_text.append(line);
|
---|
50 | if (line.startsWith("</Doc>")) {
|
---|
51 | indexer.indexFile(xml_text.toString());
|
---|
52 | xml_text = new StringBuffer(1024);
|
---|
53 | }
|
---|
54 | //File xml_file = new File(import_dir + File.separator + line);
|
---|
55 | //indexer.indexFile(xml_file); // ****
|
---|
56 | }
|
---|
57 |
|
---|
58 | brin.close();
|
---|
59 | isr.close();
|
---|
60 |
|
---|
61 | } catch (IOException e) {
|
---|
62 | System.err.println("Error: unable to read from stdin");
|
---|
63 | e.printStackTrace();
|
---|
64 | }
|
---|
65 |
|
---|
66 | indexer.finish();
|
---|
67 | }
|
---|
68 | }
|
---|