@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 byte[][] pack(Float value) {
   if (value == null) {
     // OK: open ended range
     return new byte[1][];
   }
   byte[][] result = new byte[][] {new byte[RamUsageEstimator.NUM_BYTES_INT]};
   NumericUtils.intToBytesDirect(NumericUtils.floatToSortableInt(value), result[0], 0);
   return result;
 }
Example #3
0
 @Override
 public String readableToIndexed(String val) {
   switch (type) {
     case INTEGER:
       return NumericUtils.intToPrefixCoded(Integer.parseInt(val));
     case FLOAT:
       return NumericUtils.intToPrefixCoded(
           NumericUtils.floatToSortableInt(Float.parseFloat(val)));
     case LONG:
       return NumericUtils.longToPrefixCoded(Long.parseLong(val));
     case DOUBLE:
       return NumericUtils.longToPrefixCoded(
           NumericUtils.doubleToSortableLong(Double.parseDouble(val)));
     case DATE:
       return NumericUtils.longToPrefixCoded(dateField.parseMath(null, val).getTime());
     default:
       throw new SolrException(
           SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
   }
 }
 /**
  * Initializes the token stream with the supplied <code>float</code> value.
  *
  * @param value the value, for which this TokenStream should enumerate tokens.
  * @return this instance, because of this you can use it the following way: <code>
  *     new Field(name, new NumericTokenStream(precisionStep).setFloatValue(value))</code>
  */
 public NumericTokenStream setFloatValue(final float value) {
   numericAtt.init(
       NumericUtils.floatToSortableInt(value), valSize = 32, precisionStep, -precisionStep);
   return this;
 }
 /** {@inheritDoc} */
 @Override
 public Field sortedField(String name, Float value) {
   int sortable = NumericUtils.floatToSortableInt(value);
   return new NumericDocValuesField(name, sortable);
 }
Example #6
0
 @Override
 public String storedToIndexed(Fieldable f) {
   if (f instanceof NumericField) {
     final Number val = ((NumericField) f).getNumericValue();
     if (val == null)
       throw new SolrException(
           SolrException.ErrorCode.SERVER_ERROR, "Invalid field contents: " + f.name());
     switch (type) {
       case INTEGER:
         return NumericUtils.intToPrefixCoded(val.intValue());
       case FLOAT:
         return NumericUtils.intToPrefixCoded(NumericUtils.floatToSortableInt(val.floatValue()));
       case LONG: // fallthrough!
       case DATE:
         return NumericUtils.longToPrefixCoded(val.longValue());
       case DOUBLE:
         return NumericUtils.longToPrefixCoded(
             NumericUtils.doubleToSortableLong(val.doubleValue()));
       default:
         throw new SolrException(
             SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + f.name());
     }
   } else {
     // the following code is "deprecated" and only to support pre-3.2 indexes using the old
     // BinaryField encoding:
     final byte[] arr = f.getBinaryValue();
     if (arr == null)
       throw new SolrException(
           SolrException.ErrorCode.SERVER_ERROR, "Invalid field contents: " + f.name());
     switch (type) {
       case INTEGER:
         return NumericUtils.intToPrefixCoded(toInt(arr));
       case FLOAT:
         {
           // WARNING: Code Duplication! Keep in sync with o.a.l.util.NumericUtils!
           // copied from NumericUtils to not convert to/from float two times
           // code in next 2 lines is identical to: int v =
           // NumericUtils.floatToSortableInt(Float.intBitsToFloat(toInt(arr)));
           int v = toInt(arr);
           if (v < 0) v ^= 0x7fffffff;
           return NumericUtils.intToPrefixCoded(v);
         }
       case LONG: // fallthrough!
       case DATE:
         return NumericUtils.longToPrefixCoded(toLong(arr));
       case DOUBLE:
         {
           // WARNING: Code Duplication! Keep in sync with o.a.l.util.NumericUtils!
           // copied from NumericUtils to not convert to/from double two times
           // code in next 2 lines is identical to: long v =
           // NumericUtils.doubleToSortableLong(Double.longBitsToDouble(toLong(arr)));
           long v = toLong(arr);
           if (v < 0) v ^= 0x7fffffffffffffffL;
           return NumericUtils.longToPrefixCoded(v);
         }
       default:
         throw new SolrException(
             SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + f.name());
     }
   }
 }