Example usage for org.apache.lucene.index PointValues getMinPackedValue

List of usage examples for org.apache.lucene.index PointValues getMinPackedValue

Introduction

In this page you can find the example usage for org.apache.lucene.index PointValues getMinPackedValue.

Prototype

public abstract byte[] getMinPackedValue() throws IOException;

Source Link

Document

Returns minimum value for each dimension, packed, or null if #size is 0

Usage

From source file:org.elasticsearch.xpack.core.security.authz.accesscontrol.FieldSubsetReaderTests.java

License:Open Source License

/**
 * test filtering two int points//from w  w w  .  j a  va 2 s  .c  o m
 */
public void testPoints() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(null);
    IndexWriter iw = new IndexWriter(dir, iwc);

    // add document with 2 points
    Document doc = new Document();
    doc.add(new IntPoint("fieldA", 1));
    doc.add(new IntPoint("fieldB", 2));
    iw.addDocument(doc);

    // open reader
    DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw),
            new CharacterRunAutomaton(Automata.makeString("fieldA")));

    // see only one field
    LeafReader segmentReader = ir.leaves().get(0).reader();
    PointValues points = segmentReader.getPointValues("fieldA");
    assertNull(segmentReader.getPointValues("fieldB"));

    // size statistic
    assertEquals(1, points.size());

    // doccount statistic
    assertEquals(1, points.getDocCount());

    // min statistic
    assertNotNull(points.getMinPackedValue());

    // max statistic
    assertNotNull(points.getMaxPackedValue());

    // bytes per dimension
    assertEquals(Integer.BYTES, points.getBytesPerDimension());

    // number of dimensions
    assertEquals(1, points.getNumDimensions());

    // walk the trees: we should see stuff in fieldA
    AtomicBoolean sawDoc = new AtomicBoolean(false);
    points.intersect(new IntersectVisitor() {
        @Override
        public void visit(int docID) throws IOException {
            throw new IllegalStateException("should not get here");
        }

        @Override
        public void visit(int docID, byte[] packedValue) throws IOException {
            sawDoc.set(true);
        }

        @Override
        public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
            return Relation.CELL_CROSSES_QUERY;
        }
    });
    assertTrue(sawDoc.get());

    TestUtil.checkReader(ir);
    IOUtils.close(ir, iw, dir);
}