1 | package org.greenstone.gsdl3.gs3build.indexers;
|
---|
2 |
|
---|
3 | import java.util.Iterator;
|
---|
4 |
|
---|
5 | import org.greenstone.gsdl3.gs3build.doctypes.DocumentID;
|
---|
6 | import org.greenstone.gsdl3.gs3build.doctypes.DocumentInterface;
|
---|
7 | import org.greenstone.gsdl3.gs3build.doctypes.DocumentList;
|
---|
8 |
|
---|
9 | public class IndexerManager
|
---|
10 | {
|
---|
11 | IndexerInterface indexers[];
|
---|
12 | int size;
|
---|
13 | int used;
|
---|
14 | DocumentList documents;
|
---|
15 |
|
---|
16 | public static final String outputDir = "outputDir";
|
---|
17 |
|
---|
18 | public IndexerManager(DocumentList documentList)
|
---|
19 | { this.indexers = new IndexerInterface[10];
|
---|
20 | this.size = 10;
|
---|
21 | this.used = 0;
|
---|
22 | this.documents = documentList;
|
---|
23 | }
|
---|
24 |
|
---|
25 | public void addIndexer(IndexerInterface indexer)
|
---|
26 | { this.ensureCapacity(this.used + 1);
|
---|
27 |
|
---|
28 | this.indexers[this.used] = indexer;
|
---|
29 | this.used ++;
|
---|
30 | }
|
---|
31 |
|
---|
32 | public void indexDocument(DocumentID docId, DocumentInterface document)
|
---|
33 | { if (!document.isIndexed())
|
---|
34 | return;
|
---|
35 |
|
---|
36 | for (int i = 0; i < this.used; i ++)
|
---|
37 | { this.indexers[i].indexDocument(docId, document);
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | public void indexDocuments()
|
---|
42 | { for (int i = 0; i < this.used; i ++)
|
---|
43 | { for (int p = 0; p < this.indexers[i].getNumberOfPasses(); p ++)
|
---|
44 | {
|
---|
45 | this.indexers[i].startPass(p);
|
---|
46 | Iterator iterator = this.documents.iterator();
|
---|
47 |
|
---|
48 | while (iterator.hasNext()) {
|
---|
49 | DocumentInterface document = (DocumentInterface) iterator.next();
|
---|
50 |
|
---|
51 | if (document.isIndexed()) {
|
---|
52 | if (!this.indexers[i].indexDocument(document.getID(), document)) {
|
---|
53 | System.out.println("Ending document");
|
---|
54 | }
|
---|
55 |
|
---|
56 | // note any changes made to this document...
|
---|
57 | if (document.isModified()) {
|
---|
58 | this.documents.modifiedDocument(document);
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 | this.indexers[i].endPass(p);
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | public void ensureCapacity(int needSize)
|
---|
68 | { while (needSize >= this.size)
|
---|
69 | { int newSize = this.size * 2;
|
---|
70 | IndexerInterface newIndexers [] = new IndexerInterface[newSize];
|
---|
71 | System.arraycopy(indexers, 0, newIndexers, 0, this.used);
|
---|
72 | this.indexers = newIndexers;
|
---|
73 | this.size = newSize;
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|