1
2 package org.galagosearch.core.retrieval.structured;
3
4 import java.io.IOException;
5 import java.util.ArrayList;
6 import org.galagosearch.core.util.ExtentArray;
7
8 /***
9 *
10 * @author trevor
11 */
12 public abstract class ExtentConjunctionIterator extends ExtentIterator {
13 protected ExtentIterator[] extentIterators;
14 protected ExtentArray extents;
15 protected int document;
16 protected boolean done;
17
18 public ExtentConjunctionIterator(ExtentIterator[] extIterators) {
19 this.done = false;
20 this.extentIterators = extIterators;
21 this.extents = new ExtentArray();
22 }
23
24 public abstract void loadExtents();
25
26 public void nextDocument() throws IOException {
27 if (!done) {
28 extentIterators[0].nextDocument();
29 findDocument();
30 }
31 }
32
33 public void findDocument() throws IOException {
34 while (!done) {
35
36 document = MoveIterators.moveAllToSameDocument(extentIterators);
37
38
39 if (document == Integer.MAX_VALUE) {
40 done = true;
41 break;
42 }
43
44
45 extents.reset();
46 loadExtents();
47
48
49 if (extents.getPosition() > 0) {
50 break;
51 }
52 extentIterators[0].nextDocument();
53 }
54 }
55
56 public ExtentArray extents() {
57 return extents;
58 }
59
60 public int document() {
61 return document;
62 }
63
64 public int count() {
65 return extents().getPosition();
66 }
67
68 public boolean isDone() {
69 return done;
70 }
71
72 public void reset() throws IOException {
73 for (ExtentIterator iterator : extentIterators) {
74 iterator.reset();
75 }
76
77 done = false;
78 findDocument();
79 }
80 }