Example usage for org.apache.lucene.search PointRangeQuery getLowerPoint

List of usage examples for org.apache.lucene.search PointRangeQuery getLowerPoint

Introduction

In this page you can find the example usage for org.apache.lucene.search PointRangeQuery getLowerPoint.

Prototype

public byte[] getLowerPoint() 

Source Link

Usage

From source file:org.elasticsearch.search.aggregations.bucket.composite.LongValuesSource.java

License:Apache License

@Override
SortedDocsProducer createSortedDocsProducerOrNull(IndexReader reader, Query query) {
    if (checkIfSortedDocsIsApplicable(reader, fieldType) == false
            || (query != null && query.getClass() != MatchAllDocsQuery.class &&
            // if the query is a range query over the same field
                    (query instanceof PointRangeQuery
                            && fieldType.name().equals((((PointRangeQuery) query).getField()))) == false)) {
        return null;
    }/* w  w  w .  j a  v a  2 s .c  o  m*/
    final byte[] lowerPoint;
    final byte[] upperPoint;
    if (query instanceof PointRangeQuery) {
        final PointRangeQuery rangeQuery = (PointRangeQuery) query;
        lowerPoint = rangeQuery.getLowerPoint();
        upperPoint = rangeQuery.getUpperPoint();
    } else {
        lowerPoint = null;
        upperPoint = null;
    }

    if (fieldType instanceof NumberFieldMapper.NumberFieldType) {
        NumberFieldMapper.NumberFieldType ft = (NumberFieldMapper.NumberFieldType) fieldType;
        final ToLongFunction<byte[]> toBucketFunction;

        switch (ft.typeName()) {
        case "long":
            toBucketFunction = (value) -> rounding.applyAsLong(LongPoint.decodeDimension(value, 0));
            break;

        case "int":
        case "short":
        case "byte":
            toBucketFunction = (value) -> rounding.applyAsLong(IntPoint.decodeDimension(value, 0));
            break;

        default:
            return null;
        }
        return new PointsSortedDocsProducer(fieldType.name(), toBucketFunction, lowerPoint, upperPoint);
    } else if (fieldType instanceof DateFieldMapper.DateFieldType) {
        final ToLongFunction<byte[]> toBucketFunction = (value) -> rounding
                .applyAsLong(LongPoint.decodeDimension(value, 0));
        return new PointsSortedDocsProducer(fieldType.name(), toBucketFunction, lowerPoint, upperPoint);
    } else {
        return null;
    }
}