Java 类org.apache.lucene.util.packed.DirectReader 实例源码

项目:search    文件:TestDirectPacked.java   
/** simple encode/decode */
public void testSimple() throws Exception {
  Directory dir = newDirectory();
  int bitsPerValue = DirectWriter.bitsRequired(2);
  IndexOutput output = dir.createOutput("foo", IOContext.DEFAULT);
  DirectWriter writer = DirectWriter.getInstance(output, 5, bitsPerValue);
  writer.add(1);
  writer.add(0);
  writer.add(2);
  writer.add(1);
  writer.add(2);
  writer.finish();
  output.close();
  IndexInput input = dir.openInput("foo", IOContext.DEFAULT);
  NumericDocValues reader = DirectReader.getInstance(input.randomAccessSlice(0, input.length()), bitsPerValue);
  assertEquals(1, reader.get(0));
  assertEquals(0, reader.get(1));
  assertEquals(2, reader.get(2));
  assertEquals(1, reader.get(3));
  assertEquals(2, reader.get(4));
  input.close();
  dir.close();
}
项目:search    文件:TestDirectPacked.java   
private void doTestBpv(Directory directory, int bpv) throws Exception {
  MyRandom random = new MyRandom(random().nextLong());
  for (int i = 0; i < 100; i++) {
    long original[] = randomLongs(random, bpv);
    int bitsRequired = bpv == 64 ? 64 : DirectWriter.bitsRequired(1L<<(bpv-1));
    String name = "bpv" + bpv + "_" + i;
    IndexOutput output = directory.createOutput(name, IOContext.DEFAULT);
    DirectWriter writer = DirectWriter.getInstance(output, original.length, bitsRequired);
    for (int j = 0; j < original.length; j++) {
      writer.add(original[j]);
    }
    writer.finish();
    output.close();
    IndexInput input = directory.openInput(name, IOContext.DEFAULT);
    NumericDocValues reader = DirectReader.getInstance(input.randomAccessSlice(0, input.length()), bitsRequired);
    for (int j = 0; j < original.length; j++) {
      assertEquals("bpv=" + bpv, original[j], reader.get(j));
    }
    input.close();
  }
}