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