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