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

Last change on this file since 6349 was 6349, checked in by cs025, 20 years ago

Modified indexerinterface to allow easier configuration, improved MG section handling.

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