| 1 | |
|
| 2 | |
|
| 3 | |
package org.galagosearch.core.parse; |
| 4 | |
|
| 5 | |
import java.io.FileNotFoundException; |
| 6 | |
import java.io.IOException; |
| 7 | |
import org.galagosearch.core.types.DocumentSplit; |
| 8 | |
import org.galagosearch.tupleflow.Utility; |
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
public class IndexReaderSplitParser implements DocumentStreamParser { |
| 17 | |
DocumentIndexReader.Iterator iterator; |
| 18 | |
DocumentSplit split; |
| 19 | |
|
| 20 | 12 | public IndexReaderSplitParser(DocumentSplit split) throws FileNotFoundException, IOException { |
| 21 | 12 | DocumentIndexReader reader = new DocumentIndexReader(split.fileName); |
| 22 | 12 | iterator = reader.getIterator(); |
| 23 | 12 | iterator.skipTo(split.startKey); |
| 24 | 12 | this.split = split; |
| 25 | 12 | } |
| 26 | |
|
| 27 | |
public Document nextDocument() throws IOException { |
| 28 | 16 | if (iterator.isDone()) { |
| 29 | 8 | return null; |
| 30 | |
} |
| 31 | |
|
| 32 | 8 | String key = iterator.getKey(); |
| 33 | 8 | byte[] keyBytes = Utility.makeBytes(key); |
| 34 | |
|
| 35 | |
|
| 36 | 8 | if (split.endKey.length > 0 && Utility.compare(keyBytes, split.endKey) >= 0) { |
| 37 | 4 | return null; |
| 38 | |
} |
| 39 | |
|
| 40 | 4 | Document document = iterator.getDocument(); |
| 41 | 4 | iterator.nextDocument(); |
| 42 | 4 | return document; |
| 43 | |
} |
| 44 | |
} |