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()); } }
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()); } }
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()); } }
@Override public void accept(long value) { NumericUtils.longToPrefixCoded((int)value, 0, bytes); } };
/** * 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); } }
/** * Returns prefix coded bits after reducing the precision by <code>shift</code> bits. * This is method is used by {@link NumericTokenStream}. * After encoding, {@code bytes.offset} will always be 0. * @param val the numeric value * @param shift how many bits to strip from the right * @param bytes will contain the encoded value * @deprecated Use {@link #longToPrefixCoded} instead. */ @Deprecated public static void longToPrefixCodedBytes(final long val, final int shift, final BytesRefBuilder bytes) { longToPrefixCoded(val, shift, bytes); }
public static Term tsTerm(long ts) { BytesRefBuilder tsBytes = new BytesRefBuilder(); NumericUtils.longToPrefixCoded(ts, NumericUtils.PRECISION_STEP_DEFAULT, tsBytes); return new Term(CF_TS_INDEXED, tsBytes); }
@Override public String readableToIndexed(String val) { return NumericUtils.longToPrefixCoded(super.parseMath(null, val).getTime()); }
/** * Creates a term enum matching intersected interval segments. * @param reader the index to filter terms from * @throws IOException if IO issues occur */ private NumericIntervalIntersectionTermEnum(final IndexReader reader) throws IOException { this.reader = reader; setEnum(reader.terms(new Term( NumericIntervalIntersectionQuery.this.name, NumericUtils.longToPrefixCoded( NumericIntervalIntersectionQuery.this.start)))); }
@Override public BytesRef indexedValueForSearch(Object value) { BytesRefBuilder bytesRef = new BytesRefBuilder(); NumericUtils.longToPrefixCoded(parseValue(value), 0, bytesRef); // 0 because of exact match return bytesRef.get(); }
private Query query(Long value) { if (docValues) { return new DocValuesNumbersQuery(field, docValue(value)); } else { BytesRefBuilder ref = new BytesRefBuilder(); NumericUtils.longToPrefixCoded(value, 0, ref); return new TermQuery(new Term(field, ref.toBytesRef())); } }
/** * Overwrite this method, if you like to receive the raw long range bounds. * You can use this for e.g. debugging purposes (print out range bounds). */ public void addRange(final long min, final long max, final int shift) { final BytesRefBuilder minBytes = new BytesRefBuilder(), maxBytes = new BytesRefBuilder(); longToPrefixCoded(min, shift, minBytes); longToPrefixCoded(max, shift, maxBytes); addRange(minBytes.get(), maxBytes.get()); }
/** * Overwrite this method, if you like to receive the raw long range bounds. * You can use this for e.g. debugging purposes (print out range bounds). */ public void addRange(final long min, final long max, final int shift) { final BytesRefBuilder minBytes = new BytesRefBuilder(), maxBytes = new BytesRefBuilder(); longToPrefixCoded(min, shift, minBytes); longToPrefixCoded(max, shift, maxBytes); addRange(minBytes.get(), maxBytes.get()); }
@Override public BytesRef next() { BytesRefBuilder b = new BytesRefBuilder(); NumericUtils.longToPrefixCoded((int) values.valueAt(this.count++), 0, b); return b.toBytesRef(); }
@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 BytesRef indexedValueForSearch(Object value) { BytesRefBuilder bytesRef = new BytesRefBuilder(); NumericUtils.longToPrefixCoded(parseLongValue(value), 0, bytesRef); // 0 because of exact match return bytesRef.get(); }
@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 BytesRef indexedValueForSearch(Object value) { BytesRefBuilder bytesRef = new BytesRefBuilder(); NumericUtils.longToPrefixCoded(parseValue(value), 0, bytesRef); // 0 because of exact match return bytesRef.get(); }
@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(); }
/** * Converts a list of long value to their bytes ref representation as performed by * {@link org.apache.lucene.analysis.NumericTokenStream} */ private BytesRef[] toBytesRefs(long[] values) { BytesRef[] bytesRefs = new BytesRef[values.length]; for (int i = 0; i < values.length; i++) { BytesRefBuilder b = new BytesRefBuilder(); NumericUtils.longToPrefixCoded(values[i], 0, b); bytesRefs[i] = b.toBytesRef(); } return bytesRefs; }