Java Code Examples for org.apache.lucene.util.NumericUtils#sortableIntToFloat()

The following examples show how to use org.apache.lucene.util.NumericUtils#sortableIntToFloat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TrieField.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public Object toObject(SchemaField sf, BytesRef term) {
  switch (type) {
    case INTEGER:
      return LegacyNumericUtils.prefixCodedToInt(term);
    case FLOAT:
      return NumericUtils.sortableIntToFloat(LegacyNumericUtils.prefixCodedToInt(term));
    case LONG:
      return LegacyNumericUtils.prefixCodedToLong(term);
    case DOUBLE:
      return NumericUtils.sortableLongToDouble(LegacyNumericUtils.prefixCodedToLong(term));
    case DATE:
      return new Date(LegacyNumericUtils.prefixCodedToLong(term));
    default:
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
  }
}
 
Example 2
Source File: MultiFieldWriter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
static LongFunction<Object> bitsToValue(FieldType fieldType) {
  switch (fieldType.getNumberType()) {
    case LONG:
      return (bits)-> bits;
    case DATE:
      return (bits)-> new Date(bits);
    case INTEGER:
      return (bits)-> (int)bits;
    case FLOAT:
      return (bits)-> NumericUtils.sortableIntToFloat((int)bits);
    case DOUBLE:
      return (bits)-> NumericUtils.sortableLongToDouble(bits);
    default:
      throw new AssertionError("Unsupported NumberType: " + fieldType.getNumberType());
  }
}
 
Example 3
Source File: FloatColumnReference.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Float value() {
    try {
        if (values.advanceExact(docId)) {
            switch (values.docValueCount()) {
                case 1:
                    return NumericUtils.sortableIntToFloat((int) values.nextValue());

                default:
                    throw new GroupByOnArrayUnsupportedException(columnName);
            }
        } else {
            return null;
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example 4
Source File: DocValuesAcc.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * converts given long value to double based on field type
 */
protected double getDouble(long val) {
  switch (sf.getType().getNumberType()) {
    case INTEGER:
    case LONG:
    case DATE:
      return val;
    case FLOAT:
      return NumericUtils.sortableIntToFloat((int) val);
    case DOUBLE:
      return NumericUtils.sortableLongToDouble(val);
    default:
      // this would never happen
      return 0.0d;
  }
}
 
Example 5
Source File: PercentileAgg.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * converts given long value to double based on field type
 */
protected double getDouble(long val) {
  switch (sf.getType().getNumberType()) {
    case INTEGER:
    case LONG:
    case DATE:
      return val;
    case FLOAT:
      return NumericUtils.sortableIntToFloat((int) val);
    case DOUBLE:
      return NumericUtils.sortableLongToDouble(val);
    default:
      // this would never happen
      return 0.0d;
  }
}
 
Example 6
Source File: FloatFieldMapper.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@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
    );
}
 
Example 7
Source File: FloatPointField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public Object toObject(IndexableField f) {
  final Number val = f.numericValue();
  if (val != null) {
    if (f.fieldType().stored() == false && f.fieldType().docValuesType() == DocValuesType.NUMERIC) {
      return Float.intBitsToFloat(val.intValue());
    } else if (f.fieldType().stored() == false && f.fieldType().docValuesType() == DocValuesType.SORTED_NUMERIC) {
      return NumericUtils.sortableIntToFloat(val.intValue());
    } else  {
      return val;
    }
  } else {
    throw new AssertionError("Unexpected state. Field: '" + f + "'");
  }
}
 
Example 8
Source File: SortedNumericStatsValues.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Number toCorrectType(long value) {
  switch (numberType) {
    case INTEGER:
    case LONG:
      return value;
    case FLOAT:
      return NumericUtils.sortableIntToFloat((int)value);
    case DOUBLE:
      return NumericUtils.sortableLongToDouble(value);
    default:
      throw new AssertionError("Unsupported number type");
  }
}
 
Example 9
Source File: FloatMultiTrieField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
  count = 0;
  if (docValues.advanceExact(doc)) {
    int term;
    while ((term = (int)docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
      if (count == values.length) {
        resizeValues();
      }
      values[count++] = NumericUtils.sortableIntToFloat(LegacyNumericUtils.prefixCodedToInt(docValues.lookupOrd(term)));
    }
  }
}
 
Example 10
Source File: FloatMultiPointField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
  if (docValues.advanceExact(doc)) {
    count = docValues.docValueCount();
    resizeEmptyValues(count);
    for (int i = 0; i < count; ++i) {
      values[i] = NumericUtils.sortableIntToFloat((int)docValues.nextValue());
    }
  } else {
    count = 0;
  }
}
 
Example 11
Source File: SolrDocumentFetcher.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private Object decodeNumberFromDV(SchemaField schemaField, long value, boolean sortableNumeric) {
  // note: This special-case is unfortunate; if we have to add any more than perhaps the fieldType should
  //  have this method so that specific field types can customize it.
  if (schemaField.getType() instanceof LatLonPointSpatialField) {
    return LatLonPointSpatialField.decodeDocValueToString(value);
  }

  if (schemaField.getType().getNumberType() == null) {
    log.warn("Couldn't decode docValues for field: [{}], schemaField: [{}], numberType is unknown",
        schemaField.getName(), schemaField);
    return null;
  }

  switch (schemaField.getType().getNumberType()) {
    case INTEGER:
      final int raw = (int)value;
      if (schemaField.getType() instanceof AbstractEnumField) {
        return ((AbstractEnumField)schemaField.getType()).getEnumMapping().intValueToStringValue(raw);
      } else {
        return raw;
      }
    case LONG:
      return value;
    case FLOAT:
      if (sortableNumeric) {
        return NumericUtils.sortableIntToFloat((int)value);
      } else {
        return Float.intBitsToFloat((int)value);
      }
    case DOUBLE:
      if (sortableNumeric) {
        return NumericUtils.sortableLongToDouble(value);
      } else {
        return Double.longBitsToDouble(value);
      }
    case DATE:
      return new Date(value);
    default:
      // catched all possible values, this line will never be reached
      throw new AssertionError();
  }
}
 
Example 12
Source File: FloatFieldTypeDefinition.java    From incubator-retired-blur with Apache License 2.0 4 votes vote down vote up
@Override
public String readTerm(BytesRef byteRef) {
 if(NumericUtils.getPrefixCodedIntShift(byteRef) == 0)
  return NumericUtils.sortableIntToFloat(NumericUtils.prefixCodedToInt(byteRef))+"";
 return null;
}
 
Example 13
Source File: TrieField.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public Object toObject(IndexableField f) {
  final Number val = f.numericValue();
  if (val != null) {

    if (f.fieldType().stored() == false && f.fieldType().docValuesType() == DocValuesType.NUMERIC ) {
      long bits = val.longValue();
      switch (type) {
        case INTEGER:
          return (int)bits;
        case FLOAT:
          return Float.intBitsToFloat((int)bits);
        case LONG:
          return bits;
        case DOUBLE:
          return Double.longBitsToDouble(bits);
        case DATE:
          return new Date(bits);
        default:
          throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + f.name());
      }
    }

    // normal stored case
    return (type == NumberType.DATE) ? new Date(val.longValue()) : val;
  } else {
    // multi-valued numeric docValues currently use SortedSet on the indexed terms.
    BytesRef term = f.binaryValue();
    switch (type) {
      case INTEGER:
        return LegacyNumericUtils.prefixCodedToInt(term);
      case FLOAT:
        return NumericUtils.sortableIntToFloat(LegacyNumericUtils.prefixCodedToInt(term));
      case LONG:
        return LegacyNumericUtils.prefixCodedToLong(term);
      case DOUBLE:
        return NumericUtils.sortableLongToDouble(LegacyNumericUtils.prefixCodedToLong(term));
      case DATE:
        return new Date(LegacyNumericUtils.prefixCodedToLong(term));
      default:
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + f.name());
    }
  }

}
 
Example 14
Source File: IndexNumericFieldData.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public double toDouble(BytesRef indexForm) {
    return NumericUtils.sortableIntToFloat(NumericUtils.prefixCodedToInt(indexForm));
}
 
Example 15
Source File: FloatPoint.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/** Decode single float dimension */
public static float decodeDimension(byte value[], int offset) {
  return NumericUtils.sortableIntToFloat(NumericUtils.sortableBytesToInt(value, offset));
}
 
Example 16
Source File: FloatRange.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/** decodes the max value (for the defined dimension) from the encoded input byte array */
static float decodeMax(byte[] b, int dimension) {
  int offset = b.length/2 + dimension*BYTES;
  return NumericUtils.sortableIntToFloat(NumericUtils.sortableBytesToInt(b, offset));
}
 
Example 17
Source File: FloatRange.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/** 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));
}
 
Example 18
Source File: SortedNumericDVIndexFieldData.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public double valueAt(int index) {
    return NumericUtils.sortableIntToFloat((int) in.valueAt(index));
}
 
Example 19
Source File: SortedNumericDVIndexFieldData.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public double get(int docID) {
    return NumericUtils.sortableIntToFloat((int) in.get(docID));
}
 
Example 20
Source File: IndexNumericFieldData.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public Number toNumber(BytesRef indexForm) {
    return NumericUtils.sortableIntToFloat(NumericUtils.prefixCodedToInt(indexForm));
}