DiskMapBuilder implements Closeable { public void put(byte[] key, byte[] value) throws IOException { sorter.process(new KeyValuePair(key, value)); } DiskMapBuilder(String path, Parameters opts);  DiskMapBuilder(String path); void put(byte[] key, byte[] value); void close(); public DiskMapSortedBuilder endPoint; public Sorter<KeyValuePair> sorter; }
@Test public void canLiveInAnIndex() throws Exception { File tmpDir = FileUtility.createTemporaryDirectory(); try { StringBuilder trecCorpus = new StringBuilder(); for(int i=0; i<10; i++) { trecCorpus.append(AppTest.trecDocument("doc" + i, "doc" + i + " text")); } File inputFile = new File(tmpDir, "input.trectext"); File indexPath = new File(tmpDir, "index"); StreamUtil.copyStringToFile(trecCorpus.toString(), inputFile); App.main(new String[]{"build", "--stemmedPostings=false", "--corpus=false", "--indexPath=" + indexPath.getAbsolutePath(), "--inputPath=" + inputFile.getAbsolutePath()}); byte[] foo = ByteUtil.fromString("foo space"); byte[] bar = ByteUtil.fromString("bar"); byte[] baz = ByteUtil.fromString("baz"); byte[] hmm = ByteUtil.fromString("hmm"); Map<byte[], byte[]> data = new TreeMap<>(new CmpUtil.ByteArrComparator()); data.put(foo, bar); data.put(bar, baz); data.put(baz, hmm); data.put(hmm, foo); File tmp = FileUtility.createTemporary(); tmp.deleteOnExit(); DiskMapReader onDisk = DiskMapReader.fromMap((new File(indexPath, "myCustomFeature")).getAbsolutePath(), data); assertTrue(onDisk.containsKey(ByteUtil.fromString("foo space"))); assertTrue(onDisk.containsKey(ByteUtil.fromString("bar"))); assertTrue(onDisk.containsKey(ByteUtil.fromString("baz"))); assertTrue(onDisk.containsKey(ByteUtil.fromString("hmm"))); LocalRetrieval ret = new LocalRetrieval(new DiskIndex(indexPath.getAbsolutePath())); assertNotNull(ret); } finally { FSUtil.deleteDirectory(tmpDir); } }