Example usage for org.apache.lucene.index LeafReader getPointValues

List of usage examples for org.apache.lucene.index LeafReader getPointValues

Introduction

In this page you can find the example usage for org.apache.lucene.index LeafReader getPointValues.

Prototype

public abstract PointValues getPointValues(String field) throws IOException;

Source Link

Document

Returns the PointValues used for numeric or spatial searches for the given field, or null if there are no point fields.

Usage

From source file:org.apache.solr.uninverting.FieldCacheImpl.java

License:Apache License

@Override
public NumericDocValues getNumerics(LeafReader reader, String field, Parser parser) throws IOException {
    if (parser == null) {
        throw new NullPointerException();
    }//from   w  ww.  java 2s. c  om
    final NumericDocValues valuesIn = reader.getNumericDocValues(field);
    if (valuesIn != null) {
        return valuesIn;
    } else {
        final FieldInfo info = reader.getFieldInfos().fieldInfo(field);
        if (info == null) {
            return DocValues.emptyNumeric();
        } else if (info.getDocValuesType() != DocValuesType.NONE) {
            throw new IllegalStateException(
                    "Type mismatch: " + field + " was indexed as " + info.getDocValuesType());
        }

        if (parser instanceof PointParser) {
            // points case
            // no points in this segment
            if (info.getPointDimensionCount() == 0) {
                return DocValues.emptyNumeric();
            }
            if (info.getPointDimensionCount() != 1) {
                throw new IllegalStateException("Type mismatch: " + field + " was indexed with dimensions="
                        + info.getPointDimensionCount());
            }
            PointValues values = reader.getPointValues(field);
            // no actual points for this field (e.g. all points deleted)
            if (values == null || values.size() == 0) {
                return DocValues.emptyNumeric();
            }
            // not single-valued
            if (values.size() != values.getDocCount()) {
                throw new IllegalStateException(
                        "Type mismatch: " + field + " was indexed with multiple values, numValues="
                                + values.size() + ",numDocs=" + values.getDocCount());
            }
        } else {
            // postings case 
            // not indexed
            if (info.getIndexOptions() == IndexOptions.NONE) {
                return DocValues.emptyNumeric();
            }
        }

        return ((LongsFromArray) caches.get(Long.TYPE).get(reader, new CacheKey(field, parser))).iterator();
    }
}

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

License:Open Source License

/**
 * test filtering two int points/* w w w.  j  av  a2 s  .co  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);
}