List of usage examples for org.apache.lucene.util NumericUtils intToSortableBytes
public static void intToSortableBytes(int value, byte[] result, int offset)
From source file:com.b2international.index.lucene.IntIndexField.java
License:Apache License
@Override protected BytesRef toBytesRef(Integer value) { byte[] packed = new byte[Integer.BYTES]; NumericUtils.intToSortableBytes(value, packed, 0); return new BytesRef(packed); }
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;/*from w ww.j ava 2 s. c o 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)); } } }
From source file:org.apache.solr.schema.EnumFieldType.java
License:Apache License
@Override public void readableToIndexed(CharSequence val, BytesRefBuilder result) { final String s = val.toString(); if (s == null) return;//from w w w . j av a2s. co m result.grow(Integer.BYTES); result.setLength(Integer.BYTES); final Integer intValue = enumMapping.stringValueToIntValue(s); NumericUtils.intToSortableBytes(intValue, result.bytes(), 0); }
From source file:org.apache.solr.schema.EnumFieldType.java
License:Apache License
@Override public String storedToIndexed(IndexableField f) { final Number val = f.numericValue(); if (val == null) return null; final BytesRefBuilder bytes = new BytesRefBuilder(); bytes.grow(Integer.BYTES);//from w w w . j a v a 2 s. c o m bytes.setLength(Integer.BYTES); NumericUtils.intToSortableBytes(val.intValue(), bytes.bytes(), 0); return bytes.get().utf8ToString(); }
From source file:org.apache.solr.schema.EnumFieldType.java
License:Apache License
@Override public IndexableField createField(SchemaField field, Object value) { final Integer intValue = enumMapping.stringValueToIntValue(value.toString()); if (intValue == null || intValue.equals(EnumMapping.DEFAULT_VALUE)) { String exceptionMessage = String.format(Locale.ENGLISH, "Unknown value for enum field: %s, value: %s", field.getName(), value.toString()); throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, exceptionMessage); }// w w w . j a v a 2 s.c om org.apache.lucene.document.FieldType newType = new org.apache.lucene.document.FieldType(); newType.setTokenized(false); newType.setStored(field.stored()); newType.setOmitNorms(field.omitNorms()); newType.setIndexOptions(field.indexOptions()); newType.setStoreTermVectors(field.storeTermVector()); newType.setStoreTermVectorOffsets(field.storeTermOffsets()); newType.setStoreTermVectorPositions(field.storeTermPositions()); newType.setStoreTermVectorPayloads(field.storeTermPayloads()); byte[] bytes = new byte[Integer.BYTES]; NumericUtils.intToSortableBytes(intValue, bytes, 0); return new Field(field.getName(), bytes, newType) { @Override public Number numericValue() { return NumericUtils.sortableBytesToInt(((BytesRef) fieldsData).bytes, 0); } }; }
From source file:org.elasticsearch.index.mapper.BinaryRangeUtil.java
License:Apache License
static byte[] encodeFloat(float number) { byte[] encoded = new byte[4]; NumericUtils.intToSortableBytes(NumericUtils.floatToSortableInt(number), encoded, 0); return encoded; }