Ejemplo n.º 1
0
 @Override
 public String indexedToReadable(String indexedForm) {
   switch (type) {
     case INTEGER:
       return Integer.toString(NumericUtils.prefixCodedToInt(indexedForm));
     case FLOAT:
       return Float.toString(
           NumericUtils.sortableIntToFloat(NumericUtils.prefixCodedToInt(indexedForm)));
     case LONG:
       return Long.toString(NumericUtils.prefixCodedToLong(indexedForm));
     case DOUBLE:
       return Double.toString(
           NumericUtils.sortableLongToDouble(NumericUtils.prefixCodedToLong(indexedForm)));
     case DATE:
       return dateField.toExternal(new Date(NumericUtils.prefixCodedToLong(indexedForm)));
     default:
       throw new SolrException(
           SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
   }
 }
Ejemplo n.º 2
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);
   }
 }
Ejemplo n.º 3
0
  @Override
  public Fieldable createField(SchemaField field, String externalVal, float boost) {
    boolean indexed = field.indexed();
    boolean stored = field.stored();

    if (!indexed && !stored) {
      if (log.isTraceEnabled()) log.trace("Ignoring unindexed/unstored field: " + field);
      return null;
    }

    final NumericField f =
        new NumericField(
            field.getName(), precisionStep, stored ? Field.Store.YES : Field.Store.NO, indexed);
    switch (type) {
      case INTEGER:
        f.setIntValue(Integer.parseInt(externalVal));
        break;
      case FLOAT:
        f.setFloatValue(Float.parseFloat(externalVal));
        break;
      case LONG:
        f.setLongValue(Long.parseLong(externalVal));
        break;
      case DOUBLE:
        f.setDoubleValue(Double.parseDouble(externalVal));
        break;
      case DATE:
        f.setLongValue(dateField.parseMath(null, externalVal).getTime());
        break;
      default:
        throw new SolrException(
            SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
    }

    f.setOmitNorms(field.omitNorms());
    f.setIndexOptions(getIndexOptions(field, externalVal));
    f.setBoost(boost);
    return f;
  }
Ejemplo n.º 4
0
 @Override
 public String toExternal(Fieldable f) {
   return (type == TrieTypes.DATE)
       ? dateField.toExternal((Date) toObject(f))
       : toObject(f).toString();
 }
Ejemplo n.º 5
0
  @Override
  public Query getRangeQuery(
      QParser parser,
      SchemaField field,
      String min,
      String max,
      boolean minInclusive,
      boolean maxInclusive) {
    int ps = precisionStep;
    Query query = null;
    switch (type) {
      case INTEGER:
        query =
            NumericRangeQuery.newIntRange(
                field.getName(),
                ps,
                min == null ? null : Integer.parseInt(min),
                max == null ? null : Integer.parseInt(max),
                minInclusive,
                maxInclusive);
        break;
      case FLOAT:
        query =
            NumericRangeQuery.newFloatRange(
                field.getName(),
                ps,
                min == null ? null : Float.parseFloat(min),
                max == null ? null : Float.parseFloat(max),
                minInclusive,
                maxInclusive);
        break;
      case LONG:
        query =
            NumericRangeQuery.newLongRange(
                field.getName(),
                ps,
                min == null ? null : Long.parseLong(min),
                max == null ? null : Long.parseLong(max),
                minInclusive,
                maxInclusive);
        break;
      case DOUBLE:
        query =
            NumericRangeQuery.newDoubleRange(
                field.getName(),
                ps,
                min == null ? null : Double.parseDouble(min),
                max == null ? null : Double.parseDouble(max),
                minInclusive,
                maxInclusive);
        break;
      case DATE:
        query =
            NumericRangeQuery.newLongRange(
                field.getName(),
                ps,
                min == null ? null : dateField.parseMath(null, min).getTime(),
                max == null ? null : dateField.parseMath(null, max).getTime(),
                minInclusive,
                maxInclusive);
        break;
      default:
        throw new SolrException(
            SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field");
    }

    return query;
  }