Example usage for org.apache.lucene.document SortedNumericDocValuesField newSlowRangeQuery

List of usage examples for org.apache.lucene.document SortedNumericDocValuesField newSlowRangeQuery

Introduction

In this page you can find the example usage for org.apache.lucene.document SortedNumericDocValuesField newSlowRangeQuery.

Prototype

public static Query newSlowRangeQuery(String field, long lowerValue, long upperValue) 

Source Link

Document

Create a range query that matches all documents whose value is between lowerValue and upperValue included.

Usage

From source file:org.apache.solr.schema.EnumFieldType.java

License:Apache License

@Override
public Query getRangeQuery(QParser parser, SchemaField field, String min, String max, boolean minInclusive,
        boolean maxInclusive) {
    Integer minValue = enumMapping.stringValueToIntValue(min);
    Integer maxValue = enumMapping.stringValueToIntValue(max);

    if (field.indexed()) {
        BytesRef minBytes = null;/*  ww w  .  j a v  a  2 s.co  m*/
        if (min != null) {
            byte[] bytes = new byte[Integer.BYTES];
            NumericUtils.intToSortableBytes(minValue, bytes, 0);
            minBytes = new BytesRef(bytes);
        }
        BytesRef maxBytes = null;
        if (max != null) {
            byte[] bytes = new byte[Integer.BYTES];
            NumericUtils.intToSortableBytes(maxValue, bytes, 0);
            maxBytes = new BytesRef(bytes);
        }
        return new TermRangeQuery(field.getName(), minBytes, maxBytes, minInclusive, maxInclusive);

    } else {
        long lowerValue = Long.MIN_VALUE;
        long upperValue = Long.MAX_VALUE;
        if (minValue != null) {
            lowerValue = minValue.longValue();
            if (minInclusive == false) {
                ++lowerValue;
            }
        }
        if (maxValue != null) {
            upperValue = maxValue.longValue();
            if (maxInclusive == false) {
                --upperValue;
            }
        }
        if (field.multiValued()) {
            return new ConstantScoreQuery(
                    SortedNumericDocValuesField.newSlowRangeQuery(field.getName(), lowerValue, upperValue));
        } else {
            return new ConstantScoreQuery(
                    NumericDocValuesField.newSlowRangeQuery(field.getName(), lowerValue, upperValue));
        }
    }
}