IndexRepair { public static void createNamesReverseFromNames(String names, String outputName, Parameters opts) throws IOException, IncompatibleProcessorException { DiskNameReader namesReader = new DiskNameReader(names); Parameters oldP = namesReader.getManifest(); Parameters newP = Parameters.create(); newP.put("filename", outputName); if(opts.get("keepBlockSize", true)) { newP.put("blockSize", oldP.getLong("blockSize")); } int flushSize = (int) opts.get("flushSize", 10000); DiskNameReverseWriter reverseWriter = new DiskNameReverseWriter(new FakeParameters(newP)); Sorter<DocumentNameId> pipe = new Sorter<DocumentNameId>(new DocumentNameId.NameOrder()); pipe.setProcessor(reverseWriter); DataSource<String> source = namesReader.getSource(); long count = 0; while(!source.isDone()) { long identifier = source.currentCandidate(); String name = source.data(identifier); pipe.process(new DocumentNameId(ByteUtil.fromString(name), identifier)); if(count % flushSize == 0) { logger.log(Level.INFO, "converted: "+count+" names"); pipe.flush(); } count++; source.movePast(identifier); } pipe.close(); }  static void createNamesReverseFromNames(String names, String outputName, Parameters opts);  }
@Test public void testRepairNamesReverse() throws IOException, IncompatibleProcessorException { String namesPart = (new File(tempPath, "names")).getCanonicalPath(); String originalRNames = (new File(tempPath, "names.reverse")).getCanonicalPath(); File tempPart = null; try { tempPart = FileUtility.createTemporary(); IndexRepair.createNamesReverseFromNames(namesPart, tempPart.getAbsolutePath(), Parameters.create()); DiskNameReverseReader original = new DiskNameReverseReader(originalRNames); DiskNameReverseReader recreated = new DiskNameReverseReader(tempPart.getAbsolutePath()); DiskNameReverseReader.KeyIterator iter = original.getIterator(); while(!iter.isDone()) { long id = iter.getCurrentIdentifier(); String name = iter.getCurrentName(); Assert.assertEquals(recreated.getDocumentIdentifier(name), id); iter.nextKey(); } } finally { if(tempPart != null) tempPart.delete(); } }