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()); } }
/** decodes the min value (for the defined dimension) from the encoded input byte array */ static double decodeMin(byte[] b, int dimension) { int offset = dimension*BYTES; return NumericUtils.sortableLongToDouble(NumericUtils.sortableBytesToLong(b, offset)); }
/** decodes the min value (for the defined dimension) from the encoded input byte array */ static float decodeMin(byte[] b, int dimension) { int offset = dimension*BYTES; return NumericUtils.sortableIntToFloat(NumericUtils.sortableBytesToInt(b, offset)); }
/** 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(double val, byte[] bytes, int offset) { NumericUtils.longToSortableBytes(NumericUtils.doubleToSortableLong(val), bytes, offset); }
private String convertNumber(Number number) { if (Integer.class.isInstance(number)) { return NumericUtils.intToPrefixCoded(number.intValue()); } else if (Double.class.isInstance(number)) { return NumericUtils.doubleToPrefixCoded(number.doubleValue()); } else if (Long.class.isInstance(number)) { return NumericUtils.longToPrefixCoded(number.longValue()); } else if (Float.class.isInstance(number)) { return NumericUtils.floatToPrefixCoded(number.floatValue()); } else if (Byte.class.isInstance(number)) { return NumericUtils.intToPrefixCoded(number.intValue()); } else if (Short.class.isInstance(number)) { return NumericUtils.intToPrefixCoded(number.intValue()); } else if (BigDecimal.class.isInstance(number)) { return NumericUtils.doubleToPrefixCoded(number.doubleValue()); } else if (BigInteger.class.isInstance(number)) { return NumericUtils.longToPrefixCoded(number.longValue()); } else { throw new IllegalArgumentException("Unsupported numeric type " + number.getClass().getName()); } }
/** * Encode as a BytesRef using a reusable object. This allows us to lazily create the BytesRef (which is * quite expensive), only when we need it. */ @Override protected void fillBytesRef(BytesRefBuilder result) { assert result != null; NumericUtils.longToPrefixCoded(start, shift, result); } }
@Override public long longValue() throws IOException { return NumericUtils.doubleToSortableLong(values.doubleValue()); }
@Override public BytesRef getBytesRef() { assert valueSize == 64 || valueSize == 32; if (shift >= valueSize) { bytes.clear(); } else if (valueSize == 64) { NumericUtils.longToPrefixCoded(value, shift, bytes); } else { NumericUtils.intToPrefixCoded((int) value, shift, bytes); } return bytes.get(); }
@Override public void accept(long value) { NumericUtils.intToPrefixCoded((int)value, 0, bytes); } };
if ( value instanceof Float ) field = new SortedNumericDocValuesField( key, NumericUtils.floatToSortableInt( number.floatValue() ) ); field = new SortedNumericDocValuesField( key, NumericUtils.doubleToSortableLong( number.doubleValue() ) );
@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 BytesRef indexedValueForSearch(Object value) { long longValue = NumericUtils.doubleToSortableLong(parseDoubleValue(value)); BytesRefBuilder bytesRef = new BytesRefBuilder(); NumericUtils.longToPrefixCoded(longValue, 0, bytesRef); // 0 because of exact match return bytesRef.get(); }
@Override public BytesRef indexedValueForSearch(Object value) { int intValue = NumericUtils.floatToSortableInt(parseValue(value)); BytesRefBuilder bytesRef = new BytesRefBuilder(); NumericUtils.intToPrefixCoded(intValue, 0, bytesRef); // 0 because of exact match return bytesRef.get(); }
private static DoubleTerms.Bucket convertToDouble(LongTerms.Bucket bucket) { double value = NumericUtils.sortableLongToDouble(bucket.term); return new DoubleTerms.Bucket(value, bucket.docCount, bucket.aggregations, bucket.showDocCountError, bucket.docCountError, bucket.format); } }
/** Encode single integer dimension */ public static void encodeDimension(int value, byte dest[], int offset) { NumericUtils.intToSortableBytes(value, dest, offset); }
@Override public double nextValue() throws IOException { return NumericUtils.sortableIntToFloat((int) in.nextValue()); }
/** encode the given value into the byte array at the defined offset */ private static void encode(long val, byte[] bytes, int offset) { NumericUtils.longToSortableBytes(val, bytes, offset); }
@Override public Number toNumber(BytesRef indexForm) { return NumericUtils.sortableIntToFloat(NumericUtils.prefixCodedToInt(indexForm)); } },
@Override public FieldStats stats(Terms terms, int maxDoc) throws IOException { float minValue = NumericUtils.sortableIntToFloat(NumericUtils.getMinInt(terms)); float maxValue = NumericUtils.sortableIntToFloat(NumericUtils.getMaxInt(terms)); return new FieldStats.Float( maxDoc, terms.getDocCount(), terms.getSumDocFreq(), terms.getSumTotalTermFreq(), minValue, maxValue ); } }