package org.lemurproject.galago.core.repair;

import org.lemurproject.galago.core.index.disk.DiskNameReader;
import org.lemurproject.galago.core.index.disk.DiskNameReverseWriter;
import org.lemurproject.galago.core.index.source.DataSource;
import org.lemurproject.galago.core.types.NumberedDocumentData;
import org.lemurproject.galago.tupleflow.FakeParameters;
import org.lemurproject.galago.tupleflow.IncompatibleProcessorException;
import org.lemurproject.galago.tupleflow.Parameters;
import org.lemurproject.galago.tupleflow.Sorter;

import java.io.IOException;

/**
 * @author jfoley.
 */
public class IndexRepair {
  public static void createNamesReverseFromNames(String names, String outputName) throws IOException, IncompatibleProcessorException {
    // input
    DiskNameReader namesReader = new DiskNameReader(names);

    Parameters oldP = namesReader.getManifest();
    Parameters newP = Parameters.parseArray("filename", outputName,
      "blockSize", oldP.getLong("blockSize"),
      "maxKeySize", oldP.getLong("maxKeySize"));
    DiskNameReverseWriter reverseWriter = new DiskNameReverseWriter(new FakeParameters(newP));

    // build a tupleflow pipeline to resort the data
    Sorter<NumberedDocumentData> pipe = new Sorter<NumberedDocumentData>(new NumberedDocumentData.IdentifierOrder());
    pipe.setProcessor(reverseWriter);

    // iterate over the disknamesource
    DataSource<String> source = namesReader.getSource();
    long count = 0;
    while(!source.isDone()) {
      long identifier = source.currentCandidate();
      String name = source.data(identifier);
      NumberedDocumentData ndd = new NumberedDocumentData();
      ndd.identifier = name;
      ndd.number = identifier;
      pipe.process(ndd);
      if(count++ % 10000 == 0) {
        System.err.println("# converted: "+count+" names");
        pipe.flush();
      }
      source.movePast(identifier);
    }
    pipe.close();
  }
}

@@ -1639,24 +1639,96 @@
 mentData();%0A
+      ndd.fieldList = %22%22;%0A      ndd.url = %22%22;%0A      ndd.textLength = 0;%0A
       ndd.id
@@ -1744,16 +1744,16 @@
 = name;%0A
-
       nd
@@ -1818,10 +1818,8 @@
 ount
-++
  %25 1
@@ -1917,16 +1917,16 @@
 ();%0A
-
       %7D%0A
     
@@ -1917,24 +1917,39 @@
 ();%0A      %7D%0A
+      count++;%0A
       source

Fix null by default strings