source: trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/IndexerManager.java@ 6897

Last change on this file since 6897 was 6897, checked in by kjdon, 20 years ago

added a new method: addServiceDescription

  • 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 documents;
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.documents = 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 Iterator iterator = this.documents.iterator();
53
54 while (iterator.hasNext()) {
55 DocumentInterface document = (DocumentInterface) iterator.next();
56
57 if (document.isIndexed()) {
58 if (!this.indexers[i].indexDocument(document.getID(), document)) {
59 System.out.println("Ending document " + document.getID());
60 }
61
62 // note any changes made to this document...
63 if (document.isModified()) {
64 this.documents.modifiedDocument(document);
65 // System.out.println("Writing document "+document.getID());
66 }
67 /**
68 if (p == 0) {
69 System.out.println("Writing document "+document.getID());
70 }
71 */
72 }
73 }
74 this.indexers[i].endPass(p);
75 }
76 }
77 }
78
79 public void ensureCapacity(int needSize)
80 { while (needSize >= this.size)
81 { int newSize = this.size * 2;
82 IndexerInterface newIndexers [] = new IndexerInterface[newSize];
83 System.arraycopy(indexers, 0, newIndexers, 0, this.used);
84 this.indexers = newIndexers;
85 this.size = newSize;
86 }
87 }
88
89 public boolean addServiceDescriptions(Element service_class_list) {
90 boolean success = true;
91 for (int i = 0; i < this.used; i ++) {
92 if (!this.indexers[i].addServiceDescriptions(service_class_list)) {
93 success = false;
94 }
95 }
96 return success;
97 }
98}
99
Note: See TracBrowser for help on using the repository browser.