1
2
3 package org.galagosearch.core.index;
4
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
7 import java.io.OutputStream;
8 import org.galagosearch.tupleflow.Utility;
9 import org.galagosearch.tupleflow.InputClass;
10 import org.galagosearch.tupleflow.Parameters;
11 import org.galagosearch.tupleflow.TupleFlowParameters;
12 import org.galagosearch.tupleflow.execution.Verified;
13 import org.galagosearch.core.types.NumberedValuedExtent;
14
15 /***
16 *
17 * @author trevor
18 */
19 @InputClass(className = "org.galagosearch.core.types.NumberedValuedExtent", order = {"+extentName", "+number", "+begin"})
20 @Verified
21 public class ExtentValueIndexWriter implements NumberedValuedExtent.ExtentNameNumberBeginOrder.ShreddedProcessor {
22 long minimumSkipListLength = 2048;
23 int skipByteLength = 128;
24 byte[] lastWord;
25 long lastPosition = 0;
26 long lastDocument = 0;
27 ExtentListBuffer invertedList;
28 OutputStream output;
29 long filePosition;
30 IndexWriter writer;
31 long documentCount = 0;
32 long collectionLength = 0;
33 Parameters header;
34
35 /***
36 * Creates a new instance of ExtentIndexWriter
37 */
38 public ExtentValueIndexWriter(TupleFlowParameters parameters) throws FileNotFoundException, IOException {
39 writer = new IndexWriter(parameters);
40 writer.getManifest().add("readerClass", ExtentIndexReader.class.getName());
41 writer.getManifest().add("writerClass", getClass().toString());
42 header = parameters.getXML();
43 }
44
45 public void processExtentName(byte[] wordBytes) throws IOException {
46 if (invertedList != null) {
47 invertedList.close();
48 writer.add(invertedList);
49 invertedList = null;
50 }
51
52 invertedList = new ExtentListBuffer();
53 invertedList.setWord(wordBytes);
54
55 assert lastWord == null || 0 != Utility.compare(lastWord, wordBytes) : "Duplicate word";
56 lastWord = wordBytes;
57 }
58
59 public void processNumber(long document) {
60 invertedList.addDocument(document);
61 }
62
63 public void processBegin(int begin) throws IOException {
64 invertedList.addBegin(begin);
65 }
66
67 public void processTuple(int end, long value) throws IOException {
68 invertedList.setValue(value);
69 invertedList.addEnd(end);
70 }
71
72 public void close() throws IOException {
73 if (invertedList != null) {
74 invertedList.close();
75 writer.add(invertedList);
76 }
77
78 writer.close();
79 }
80 }