/** encode the given value into the byte array at the defined offset */ private static void encode(double val, byte[] bytes, int offset) { NumericUtils.longToSortableBytes(NumericUtils.doubleToSortableLong(val), bytes, offset); }
/** Encode single double dimension */ public static void encodeDimension(double value, byte dest[], int offset) { NumericUtils.longToSortableBytes(NumericUtils.doubleToSortableLong(value), dest, offset); }
private BytesRef convertNumber(Number number) { if (Integer.class.isInstance(number) || Byte.class.isInstance(number) || Short.class.isInstance(number)) { BytesRef bytes = new BytesRef(NumericUtils.BUF_SIZE_INT); NumericUtils.intToPrefixCoded(number.intValue(), 0, bytes); return bytes; } else if (Double.class.isInstance(number) || BigDecimal.class.isInstance(number)) { BytesRef bytes = new BytesRef(NumericUtils.BUF_SIZE_LONG); long l = NumericUtils.doubleToSortableLong(number.doubleValue()); NumericUtils.longToPrefixCoded(l, 0, bytes); return bytes; } else if (Long.class.isInstance(number) || BigInteger.class.isInstance(number)) { BytesRef bytes = new BytesRef(NumericUtils.BUF_SIZE_LONG); NumericUtils.longToPrefixCoded(number.longValue(), 0, bytes); return bytes; } else if (Float.class.isInstance(number)) { BytesRef bytes = new BytesRef(NumericUtils.BUF_SIZE_INT); int i = NumericUtils.floatToSortableInt(number.floatValue()); NumericUtils.intToPrefixCoded(i, 0, bytes); return bytes; } else { throw new IllegalArgumentException("Unsupported numeric type " + number.getClass().getName()); } }
field = new SortedNumericDocValuesField( key, NumericUtils.doubleToSortableLong( number.doubleValue() ) );
private BytesRef convertNumber(Number number) { if (Integer.class.isInstance(number) || Byte.class.isInstance(number) || Short.class.isInstance(number)) { BytesRefBuilder ref = new BytesRefBuilder(); NumericUtils.intToPrefixCoded(number.intValue(), 0, ref); return ref.get(); } else if (Double.class.isInstance(number) || BigDecimal.class.isInstance(number)) { BytesRefBuilder ref = new BytesRefBuilder(); long l = NumericUtils.doubleToSortableLong(number.doubleValue()); NumericUtils.longToPrefixCoded(l, 0, ref); return ref.get(); } else if (Long.class.isInstance(number) || BigInteger.class.isInstance(number)) { BytesRefBuilder ref = new BytesRefBuilder(); NumericUtils.longToPrefixCoded(number.longValue(), 0, ref); return ref.get(); } else if (Float.class.isInstance(number)) { BytesRefBuilder ref = new BytesRefBuilder(); int i = NumericUtils.floatToSortableInt(number.floatValue()); NumericUtils.intToPrefixCoded(i, 0, ref); return ref.get(); } else { throw new IllegalArgumentException("Unsupported numeric type " + number.getClass().getName()); } }
static byte[] encodeDouble(double number) { byte[] encoded = new byte[8]; NumericUtils.longToSortableBytes(NumericUtils.doubleToSortableLong(number), encoded, 0); return encoded; }
@Override public long longValue() throws IOException { return NumericUtils.doubleToSortableLong(values.doubleValue()); }
@Override public long nextValue() throws IOException { return NumericUtils.doubleToSortableLong(values.nextValue()); }
@Override public List<Field> createFields(String name, Number value, boolean indexed, boolean docValued, boolean stored) { List<Field> fields = new ArrayList<>(); if (indexed) { fields.add(new DoublePoint(name, value.doubleValue())); } if (docValued) { fields.add(new SortedNumericDocValuesField(name, NumericUtils.doubleToSortableLong(value.doubleValue()))); } if (stored) { fields.add(new StoredField(name, value.doubleValue())); } return fields; }
public LongFilter convertToDoubleFilter() { if(isPartitionBased()){ return new PartitionedLongFilter(); } int numValids = includeValues == null ? 0 : includeValues.size(); int numInvalids = excludeValues == null ? 0 : excludeValues.size(); SetBackedLongFilter result = new SetBackedLongFilter(numValids, numInvalids); if (includeValues != null) { for (BytesRef val : includeValues) { double dval = Double.parseDouble(val.utf8ToString()); result.addAccept(NumericUtils.doubleToSortableLong(dval)); } } if (excludeValues != null) { for (BytesRef val : excludeValues) { double dval = Double.parseDouble(val.utf8ToString()); result.addReject(NumericUtils.doubleToSortableLong(dval)); } } return result; }
@Override public Query rangeQuery(String field, Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, boolean hasDocValues) { double l = Double.NEGATIVE_INFINITY; double u = Double.POSITIVE_INFINITY; if (lowerTerm != null) { l = parse(lowerTerm, false); if (includeLower == false) { l = DoublePoint.nextUp(l); } } if (upperTerm != null) { u = parse(upperTerm, false); if (includeUpper == false) { u = DoublePoint.nextDown(u); } } Query query = DoublePoint.newRangeQuery(field, l, u); if (hasDocValues) { Query dvQuery = SortedNumericDocValuesField.newSlowRangeQuery(field, NumericUtils.doubleToSortableLong(l), NumericUtils.doubleToSortableLong(u)); query = new IndexOrDocValuesQuery(query, dvQuery); } return query; }
LongRange toLongRange() { return new LongRange(label, NumericUtils.doubleToSortableLong(min), true, NumericUtils.doubleToSortableLong(max), true); }
LongRange toLongRange() { return new LongRange(label, NumericUtils.doubleToSortableLong(minIncl), true, NumericUtils.doubleToSortableLong(maxIncl), true); }
/** {@inheritDoc} */ @Override public Optional<Field> sortedField(String name, Double value) { long sortable = NumericUtils.doubleToSortableLong(value); return Optional.of(new SortedNumericDocValuesField(name, sortable)); }
/** * Initializes the token stream with the supplied <code>double</code> value. * @param value the value, for which this TokenStream should enumerate tokens. * @return this instance, because of this you can use it the following way: * <code>new Field(name, new NumericTokenStream(precisionStep).setDoubleValue(value))</code> */ public NumericTokenStream setDoubleValue(final double value) { numericAtt.init(NumericUtils.doubleToSortableLong(value), valSize = 64, precisionStep, -precisionStep); return this; }
static byte[] encodeDouble(double number) { byte[] encoded = new byte[8]; NumericUtils.longToSortableBytes(NumericUtils.doubleToSortableLong(number), encoded, 0); return encoded; }
static byte[] encodeDouble(double number) { byte[] encoded = new byte[8]; NumericUtils.longToSortableBytes(NumericUtils.doubleToSortableLong(number), encoded, 0); return encoded; }
@Override final void newField(final String fieldName, final Object value, final FieldConsumer consumer) { final Field field; if (value instanceof Number) field = new SortedNumericDocValuesField(fieldName, NumericUtils.doubleToSortableLong(((Number) value).doubleValue())); else field = new SortedNumericDocValuesField(fieldName, NumericUtils.doubleToSortableLong(Double.parseDouble(value.toString()))); consumer.accept(genericFieldName, fieldName, field); }
@Override public Query getQuery(final QueryContext queryContext) throws IOException { return SortedNumericDocValuesField.newRangeQuery(resolveField(queryContext.getFieldMap()), NumericUtils.doubleToSortableLong(lower_value), NumericUtils.doubleToSortableLong(upper_value)); } }
@Override public BytesRef indexedValueForSearch(Object value) { long longValue = NumericUtils.doubleToSortableLong(parseDoubleValue(value)); BytesRefBuilder bytesRef = new BytesRefBuilder(); LegacyNumericUtils.longToPrefixCoded(longValue, 0, bytesRef); // 0 because of exact match return bytesRef.get(); }