| 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 | |
|
| 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 | 28 | public ExtentConjunctionIterator(ExtentIterator[] extIterators) { |
| 19 | 28 | this.done = false; |
| 20 | 28 | this.extentIterators = extIterators; |
| 21 | 28 | this.extents = new ExtentArray(); |
| 22 | 28 | } |
| 23 | |
|
| 24 | |
public abstract void loadExtents(); |
| 25 | |
|
| 26 | |
public void nextDocument() throws IOException { |
| 27 | 16 | if (!done) { |
| 28 | 16 | extentIterators[0].nextDocument(); |
| 29 | 16 | findDocument(); |
| 30 | |
} |
| 31 | 16 | } |
| 32 | |
|
| 33 | |
public void findDocument() throws IOException { |
| 34 | 48 | while (!done) { |
| 35 | |
|
| 36 | 48 | document = MoveIterators.moveAllToSameDocument(extentIterators); |
| 37 | |
|
| 38 | |
|
| 39 | 48 | if (document == Integer.MAX_VALUE) { |
| 40 | 24 | done = true; |
| 41 | 24 | break; |
| 42 | |
} |
| 43 | |
|
| 44 | |
|
| 45 | 24 | extents.reset(); |
| 46 | 24 | loadExtents(); |
| 47 | |
|
| 48 | |
|
| 49 | 24 | if (extents.getPosition() > 0) { |
| 50 | 20 | break; |
| 51 | |
} |
| 52 | 4 | extentIterators[0].nextDocument(); |
| 53 | |
} |
| 54 | 44 | } |
| 55 | |
|
| 56 | |
public ExtentArray extents() { |
| 57 | 24 | return extents; |
| 58 | |
} |
| 59 | |
|
| 60 | |
public int document() { |
| 61 | 0 | return document; |
| 62 | |
} |
| 63 | |
|
| 64 | |
public int count() { |
| 65 | 0 | return extents().getPosition(); |
| 66 | |
} |
| 67 | |
|
| 68 | |
public boolean isDone() { |
| 69 | 32 | return done; |
| 70 | |
} |
| 71 | |
|
| 72 | |
public void reset() throws IOException { |
| 73 | 0 | for (ExtentIterator iterator : extentIterators) { |
| 74 | 0 | iterator.reset(); |
| 75 | |
} |
| 76 | |
|
| 77 | 0 | done = false; |
| 78 | 0 | findDocument(); |
| 79 | 0 | } |
| 80 | |
} |