/** Encode single float dimension */ public static void encodeDimension(float value, byte dest[], int offset) { NumericUtils.intToSortableBytes(NumericUtils.floatToSortableInt(value), dest, offset); }
/** encode the given value into the byte array at the defined offset */ private static void encode(float val, byte[] bytes, int offset) { NumericUtils.intToSortableBytes(NumericUtils.floatToSortableInt(val), bytes, 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()); } }
if ( value instanceof Float ) field = new SortedNumericDocValuesField( key, NumericUtils.floatToSortableInt( number.floatValue() ) );
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[] encodeFloat(float number) { byte[] encoded = new byte[4]; NumericUtils.intToSortableBytes(NumericUtils.floatToSortableInt(number), encoded, 0); return encoded; }
@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 FloatPoint(name, value.floatValue())); } if (docValued) { fields.add(new SortedNumericDocValuesField(name, NumericUtils.floatToSortableInt(value.floatValue()))); } if (stored) { fields.add(new StoredField(name, value.floatValue())); } return fields; }
@Override public Query rangeQuery(String field, Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, boolean hasDocValues) { float l = Float.NEGATIVE_INFINITY; float u = Float.POSITIVE_INFINITY; if (lowerTerm != null) { l = parse(lowerTerm, false); if (includeLower == false) { l = FloatPoint.nextUp(l); } } if (upperTerm != null) { u = parse(upperTerm, false); if (includeUpper == false) { u = FloatPoint.nextDown(u); } } Query query = FloatPoint.newRangeQuery(field, l, u); if (hasDocValues) { Query dvQuery = SortedNumericDocValuesField.newSlowRangeQuery(field, NumericUtils.floatToSortableInt(l), NumericUtils.floatToSortableInt(u)); query = new IndexOrDocValuesQuery(query, dvQuery); } return query; }
/** {@inheritDoc} */ @Override public Optional<Field> sortedField(String name, Float value) { int sortable = NumericUtils.floatToSortableInt(value); return Optional.of(new SortedNumericDocValuesField(name, sortable)); }
/** * Initializes the token stream with the supplied <code>float</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).setFloatValue(value))</code> */ public NumericTokenStream setFloatValue(final float value) { numericAtt.init(NumericUtils.floatToSortableInt(value), valSize = 32, precisionStep, -precisionStep); return this; }
static byte[] encodeFloat(float number) { byte[] encoded = new byte[4]; NumericUtils.intToSortableBytes(NumericUtils.floatToSortableInt(number), encoded, 0); return encoded; }
/** * Initializes the token stream with the supplied <code>float</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).setFloatValue(value))</code> */ public NumericTokenStream setFloatValue(final float value) { numericAtt.init(NumericUtils.floatToSortableInt(value), valSize = 32, precisionStep, -precisionStep); return this; }
static Long docValue(Float value) { return value == null ? null : docValue(NumericUtils.floatToSortableInt(value)); }
static byte[] encodeFloat(float number) { byte[] encoded = new byte[4]; NumericUtils.intToSortableBytes(NumericUtils.floatToSortableInt(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.floatToSortableInt(((Number) value).floatValue())); else field = new SortedNumericDocValuesField(fieldName, NumericUtils.floatToSortableInt(Float.parseFloat(value.toString()))); consumer.accept(genericFieldName, fieldName, field); }
@Override public Query getQuery(final QueryContext queryContext) throws IOException { return SortedNumericDocValuesField.newRangeQuery(resolveField(queryContext.getFieldMap()), NumericUtils.floatToSortableInt(lower_value), NumericUtils.floatToSortableInt(upper_value)); } }
public static BytesRef fromFloat(float value) { final BytesRef bytesRef = new BytesRef(new byte[4]); NumericUtils.intToSortableBytes(NumericUtils.floatToSortableInt(value), bytesRef.bytes, 0); return bytesRef; }
@Override public Query getQuery(final QueryContext queryContext) throws IOException { return SortedNumericDocValuesField.newExactQuery(resolveField(queryContext.getFieldMap()), NumericUtils.floatToSortableInt(value)); } }
@Override public BytesRef indexedValueForSearch(Object value) { int intValue = NumericUtils.floatToSortableInt(parseValue(value)); BytesRefBuilder bytesRef = new BytesRefBuilder(); LegacyNumericUtils.intToPrefixCoded(intValue, 0, bytesRef); // 0 because of exact match return bytesRef.get(); }
@Override public Query getQuery(final QueryContext queryContext) throws IOException { return NumericDocValuesField.newExactQuery(resolveField(queryContext.getFieldMap()), NumericUtils.floatToSortableInt(value)); } }