source: trunk/greenstone3-extensions/gs3build/src/org/greenstone/gsdl3/gs3build/indexers/IndexerManager.java@ 12188

Last change on this file since 12188 was 12188, checked in by kjdon, 18 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
1package org.greenstone.gsdl3.gs3build.indexers;
2
3import java.util.Iterator;
4
5import org.w3c.dom.Element;
6
7import org.greenstone.gsdl3.gs3build.doctypes.DocumentID;
8import org.greenstone.gsdl3.gs3build.doctypes.DocumentInterface;
9import org.greenstone.gsdl3.gs3build.doctypes.DocumentList;
10
11public class IndexerManager
12{
13 IndexerInterface indexers[];
14 int size;
15 int used;
16 DocumentList documentList;
17
18 public static final String outputDir = "outputDir";
19 public static final String DEFAULT_LEVEL = "document";
20 public static final String DEFAULT_FIELD = "text";
21
22 public IndexerManager(DocumentList documentList)
23 { this.indexers = new IndexerInterface[10];
24 this.size = 10;
25 this.used = 0;
26 this.documentList = documentList;
27 }
28
29 public void addIndexer(IndexerInterface indexer)
30 { this.ensureCapacity(this.used + 1);
31
32 this.indexers[this.used] = indexer;
33 this.used ++;
34 }
35
36 public void indexDocument(DocumentID docId, DocumentInterface document)
37 { if (!document.isIndexed())
38 return;
39
40 for (int i = 0; i < this.used; i ++)
41 { this.indexers[i].indexDocument(docId, document);
42 }
43 }
44
45 public void indexDocuments()
46 { for (int i = 0; i < this.used; i ++)
47 { for (int p = 0; p < this.indexers[i].getNumberOfPasses(); p ++)
48 {
49 if (!this.indexers[i].startPass(p)) {
50 continue;
51 }
52
53 Iterator iterator = this.documentList.iterator();
54
55 while (iterator.hasNext()) {
56 DocumentInterface document = (DocumentInterface) iterator.next();
57
58 if (document.isIndexed()) {
59 if (!this.indexers[i].indexDocument(document.getID(), document)) {
60 System.out.println("Ending document " + document.getID());
61 }
62
63 // note any changes made to this document...
64 if (document.isChanged()) {
65 //System.out.println("Writing document "+document.getID());
66 this.documentList.storeChangedDocument(document);
67 }
68 /**
69 if (p == 0) {
70 System.out.println("Writing document "+document.getID());
71 }
72 */
73 }
74 }
75 this.indexers[i].endPass(p);
76 }
77 }
78 }
79
80 public void ensureCapacity(int needSize)
81 { while (needSize >= this.size)
82 { int newSize = this.size * 2;
83 IndexerInterface newIndexers [] = new IndexerInterface[newSize];
84 System.arraycopy(indexers, 0, newIndexers, 0, this.used);
85 this.indexers = newIndexers;
86 this.size = newSize;
87 }
88 }
89
90 public boolean addServiceDescriptions(Element service_class_list) {
91 boolean success = true;
92 for (int i = 0; i < this.used; i ++) {
93 if (!this.indexers[i].addServiceDescriptions(service_class_list)) {
94 success = false;
95 }
96 }
97 return success;
98 }
99}
100
Note: See TracBrowser for help on using the repository browser.