Example usage for org.apache.lucene.util NumericUtils sortableBytesToInt

List of usage examples for org.apache.lucene.util NumericUtils sortableBytesToInt

Introduction

In this page you can find the example usage for org.apache.lucene.util NumericUtils sortableBytesToInt.

Prototype

public static int sortableBytesToInt(byte[] encoded, int offset) 

Source Link

Document

Decodes an integer value previously written with #intToSortableBytes

Usage

From source file:org.apache.solr.schema.EnumFieldType.java

License:Apache License

@Override
public String indexedToReadable(String indexedForm) {
    if (indexedForm == null)
        return null;
    final BytesRef bytesRef = new BytesRef(indexedForm);
    final Integer intValue = NumericUtils.sortableBytesToInt(bytesRef.bytes, 0);
    return enumMapping.intValueToStringValue(intValue);
}

From source file:org.apache.solr.schema.EnumFieldType.java

License:Apache License

@Override
public CharsRef indexedToReadable(BytesRef input, CharsRefBuilder output) {
    final Integer intValue = NumericUtils.sortableBytesToInt(input.bytes, 0);
    final String stringValue = enumMapping.intValueToStringValue(intValue);
    output.grow(stringValue.length());/*from w  w w . j  a v a2s . c  o m*/
    output.setLength(stringValue.length());
    stringValue.getChars(0, output.length(), output.chars(), 0);
    return output.get();
}

From source file:org.apache.solr.schema.EnumFieldType.java

License:Apache License

@Override
public EnumFieldValue toObject(SchemaField sf, BytesRef term) {
    final Integer intValue = NumericUtils.sortableBytesToInt(term.bytes, 0);
    final String stringValue = enumMapping.intValueToStringValue(intValue);
    return new EnumFieldValue(intValue, stringValue);
}

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 av  a2  s.  com*/

    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);
        }
    };
}