@Override
 protected void innerParseCreateField(ParseContext context, List<Field> fields)
     throws IOException {
   short value;
   float boost = fieldType().boost();
   if (context.externalValueSet()) {
     Object externalValue = context.externalValue();
     if (externalValue == null) {
       if (fieldType().nullValue() == null) {
         return;
       }
       value = fieldType().nullValue();
     } else if (externalValue instanceof String) {
       String sExternalValue = (String) externalValue;
       if (sExternalValue.length() == 0) {
         if (fieldType().nullValue() == null) {
           return;
         }
         value = fieldType().nullValue();
       } else {
         value = Short.parseShort(sExternalValue);
       }
     } else {
       value = ((Number) externalValue).shortValue();
     }
     if (context.includeInAll(includeInAll, this)) {
       context.allEntries().addText(fieldType().name(), Short.toString(value), boost);
     }
   } else {
     XContentParser parser = context.parser();
     if (parser.currentToken() == XContentParser.Token.VALUE_NULL
         || (parser.currentToken() == XContentParser.Token.VALUE_STRING
             && parser.textLength() == 0)) {
       if (fieldType().nullValue() == null) {
         return;
       }
       value = fieldType().nullValue();
       if (fieldType().nullValueAsString() != null && (context.includeInAll(includeInAll, this))) {
         context.allEntries().addText(fieldType().name(), fieldType().nullValueAsString(), boost);
       }
     } else if (parser.currentToken() == XContentParser.Token.START_OBJECT
         && Version.indexCreated(context.indexSettings()).before(Version.V_5_0_0_alpha1)) {
       XContentParser.Token token;
       String currentFieldName = null;
       Short objValue = fieldType().nullValue();
       while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
         if (token == XContentParser.Token.FIELD_NAME) {
           currentFieldName = parser.currentName();
         } else {
           if ("value".equals(currentFieldName) || "_value".equals(currentFieldName)) {
             if (parser.currentToken() != XContentParser.Token.VALUE_NULL) {
               objValue = parser.shortValue(coerce.value());
             }
           } else if ("boost".equals(currentFieldName) || "_boost".equals(currentFieldName)) {
             boost = parser.floatValue();
           } else {
             throw new IllegalArgumentException("unknown property [" + currentFieldName + "]");
           }
         }
       }
       if (objValue == null) {
         // no value
         return;
       }
       value = objValue;
     } else {
       value = parser.shortValue(coerce.value());
       if (context.includeInAll(includeInAll, this)) {
         context.allEntries().addText(fieldType().name(), parser.text(), boost);
       }
     }
   }
   if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
     CustomShortNumericField field = new CustomShortNumericField(value, fieldType());
     if (boost != 1f
         && Version.indexCreated(context.indexSettings()).before(Version.V_5_0_0_alpha1)) {
       field.setBoost(boost);
     }
     fields.add(field);
   }
   if (fieldType().hasDocValues()) {
     addDocValue(context, fields, value);
   }
 }
 @Override
 protected void innerParseCreateField(ParseContext context, List<Field> fields)
     throws IOException {
   int value;
   float boost = this.boost;
   if (context.externalValueSet()) {
     Object externalValue = context.externalValue();
     if (externalValue == null) {
       if (nullValue == null) {
         return;
       }
       value = nullValue;
     } else if (externalValue instanceof String) {
       String sExternalValue = (String) externalValue;
       if (sExternalValue.length() == 0) {
         if (nullValue == null) {
           return;
         }
         value = nullValue;
       } else {
         value = Integer.parseInt(sExternalValue);
       }
     } else {
       value = ((Number) externalValue).intValue();
     }
     if (context.includeInAll(includeInAll, this)) {
       context.allEntries().addText(names.fullName(), Integer.toString(value), boost);
     }
   } else {
     XContentParser parser = context.parser();
     if (parser.currentToken() == XContentParser.Token.VALUE_NULL
         || (parser.currentToken() == XContentParser.Token.VALUE_STRING
             && parser.textLength() == 0)) {
       if (nullValue == null) {
         return;
       }
       value = nullValue;
       if (nullValueAsString != null && (context.includeInAll(includeInAll, this))) {
         context.allEntries().addText(names.fullName(), nullValueAsString, boost);
       }
     } else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
       XContentParser.Token token;
       String currentFieldName = null;
       Integer objValue = nullValue;
       while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
         if (token == XContentParser.Token.FIELD_NAME) {
           currentFieldName = parser.currentName();
         } else {
           if ("value".equals(currentFieldName) || "_value".equals(currentFieldName)) {
             if (parser.currentToken() != XContentParser.Token.VALUE_NULL) {
               objValue = parser.intValue(coerce.value());
             }
           } else if ("boost".equals(currentFieldName) || "_boost".equals(currentFieldName)) {
             boost = parser.floatValue();
           } else {
             throw new ElasticsearchIllegalArgumentException(
                 "unknown property [" + currentFieldName + "]");
           }
         }
       }
       if (objValue == null) {
         // no value
         return;
       }
       value = objValue;
     } else {
       value = parser.intValue(coerce.value());
       if (context.includeInAll(includeInAll, this)) {
         context.allEntries().addText(names.fullName(), parser.text(), boost);
       }
     }
   }
   addIntegerFields(context, fields, value, boost);
 }
예제 #3
0
  @Override
  protected void innerParseCreateField(ParseContext context, List<Field> fields)
      throws IOException {
    double value;
    float boost = this.boost;
    if (context.externalValueSet()) {
      Object externalValue = context.externalValue();
      if (externalValue == null) {
        if (nullValue == null) {
          return;
        }
        value = nullValue;
      } else if (externalValue instanceof String) {
        String sExternalValue = (String) externalValue;
        if (sExternalValue.length() == 0) {
          if (nullValue == null) {
            return;
          }
          value = nullValue;
        } else {
          value = Double.parseDouble(sExternalValue);
        }
      } else {
        value = ((Number) externalValue).doubleValue();
      }
      if (context.includeInAll(includeInAll, this)) {
        context.allEntries().addText(names.fullName(), Double.toString(value), boost);
      }
    } else {
      XContentParser parser = context.parser();
      if (parser.currentToken() == XContentParser.Token.VALUE_NULL
          || (parser.currentToken() == XContentParser.Token.VALUE_STRING
              && parser.textLength() == 0)) {
        if (nullValue == null) {
          return;
        }
        value = nullValue;
        if (nullValueAsString != null && (context.includeInAll(includeInAll, this))) {
          context.allEntries().addText(names.fullName(), nullValueAsString, boost);
        }
      } else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
        XContentParser.Token token;
        String currentFieldName = null;
        Double objValue = nullValue;
        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
          if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
          } else {
            if ("value".equals(currentFieldName) || "_value".equals(currentFieldName)) {
              if (parser.currentToken() != XContentParser.Token.VALUE_NULL) {
                objValue = parser.doubleValue(coerce.value());
              }
            } else if ("boost".equals(currentFieldName) || "_boost".equals(currentFieldName)) {
              boost = parser.floatValue();
            } else {
              throw new ElasticsearchIllegalArgumentException(
                  "unknown property [" + currentFieldName + "]");
            }
          }
        }
        if (objValue == null) {
          // no value
          return;
        }
        value = objValue;
      } else {
        value = parser.doubleValue(coerce.value());
        if (context.includeInAll(includeInAll, this)) {
          context.allEntries().addText(names.fullName(), parser.text(), boost);
        }
      }
    }

    if (fieldType.indexOptions() != IndexOptions.NONE || fieldType.stored()) {
      CustomDoubleNumericField field = new CustomDoubleNumericField(this, value, fieldType);
      field.setBoost(boost);
      fields.add(field);
    }
    if (hasDocValues()) {
      if (useSortedNumericDocValues) {
        addDocValue(context, fields, NumericUtils.doubleToSortableLong(value));
      } else {
        CustomDoubleNumericDocValuesField field =
            (CustomDoubleNumericDocValuesField) context.doc().getByKey(names().indexName());
        if (field != null) {
          field.add(value);
        } else {
          field = new CustomDoubleNumericDocValuesField(names().indexName(), value);
          context.doc().addWithKey(names().indexName(), field);
        }
      }
    }
  }
 @Override
 protected void innerParseCreateField(ParseContext context, List<Field> fields)
     throws IOException {
   byte value;
   float boost = this.boost;
   if (context.externalValueSet()) {
     Object externalValue = context.externalValue();
     if (externalValue == null) {
       if (nullValue == null) {
         return;
       }
       value = nullValue;
     } else if (externalValue instanceof String) {
       String sExternalValue = (String) externalValue;
       if (sExternalValue.length() == 0) {
         if (nullValue == null) {
           return;
         }
         value = nullValue;
       } else {
         value = Byte.parseByte(sExternalValue);
       }
     } else {
       value = ((Number) externalValue).byteValue();
     }
     if (context.includeInAll(includeInAll, this)) {
       context.allEntries().addText(names.fullName(), Byte.toString(value), boost);
     }
   } else {
     XContentParser parser = context.parser();
     if (parser.currentToken() == XContentParser.Token.VALUE_NULL
         || (parser.currentToken() == XContentParser.Token.VALUE_STRING
             && parser.textLength() == 0)) {
       if (nullValue == null) {
         return;
       }
       value = nullValue;
       if (nullValueAsString != null && (context.includeInAll(includeInAll, this))) {
         context.allEntries().addText(names.fullName(), nullValueAsString, boost);
       }
     } else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
       XContentParser.Token token;
       String currentFieldName = null;
       Byte objValue = nullValue;
       while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
         if (token == XContentParser.Token.FIELD_NAME) {
           currentFieldName = parser.currentName();
         } else {
           if ("value".equals(currentFieldName) || "_value".equals(currentFieldName)) {
             if (parser.currentToken() != XContentParser.Token.VALUE_NULL) {
               objValue = (byte) parser.shortValue();
             }
           } else if ("boost".equals(currentFieldName) || "_boost".equals(currentFieldName)) {
             boost = parser.floatValue();
           } else {
             throw new ElasticSearchIllegalArgumentException(
                 "unknown property [" + currentFieldName + "]");
           }
         }
       }
       if (objValue == null) {
         // no value
         return;
       }
       value = objValue;
     } else {
       value = (byte) parser.shortValue();
       if (context.includeInAll(includeInAll, this)) {
         context.allEntries().addText(names.fullName(), parser.text(), boost);
       }
     }
   }
   if (fieldType.indexed() || fieldType.stored()) {
     CustomByteNumericField field = new CustomByteNumericField(this, value, fieldType);
     field.setBoost(boost);
     fields.add(field);
   }
   if (hasDocValues()) {
     addDocValue(context, value);
   }
 }
 @Override
 protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
   short value;
   float boost = this.boost;
   if (context.externalValueSet()) {
     Object externalValue = context.externalValue();
     if (externalValue == null) {
       if (nullValue == null) {
         return null;
       }
       value = nullValue;
     } else if (externalValue instanceof String) {
       String sExternalValue = (String) externalValue;
       if (sExternalValue.length() == 0) {
         if (nullValue == null) {
           return null;
         }
         value = nullValue;
       } else {
         value = Short.parseShort(sExternalValue);
       }
     } else {
       value = ((Number) externalValue).shortValue();
     }
     if (context.includeInAll(includeInAll, this)) {
       context.allEntries().addText(names.fullName(), Short.toString(value), boost);
     }
   } else {
     XContentParser parser = context.parser();
     if (parser.currentToken() == XContentParser.Token.VALUE_NULL
         || (parser.currentToken() == XContentParser.Token.VALUE_STRING
             && parser.textLength() == 0)) {
       if (nullValue == null) {
         return null;
       }
       value = nullValue;
       if (nullValueAsString != null && (context.includeInAll(includeInAll, this))) {
         context.allEntries().addText(names.fullName(), nullValueAsString, boost);
       }
     } else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
       XContentParser.Token token;
       String currentFieldName = null;
       Short objValue = nullValue;
       while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
         if (token == XContentParser.Token.FIELD_NAME) {
           currentFieldName = parser.currentName();
         } else {
           if ("value".equals(currentFieldName) || "_value".equals(currentFieldName)) {
             if (parser.currentToken() != XContentParser.Token.VALUE_NULL) {
               objValue = parser.shortValue();
             }
           } else if ("boost".equals(currentFieldName) || "_boost".equals(currentFieldName)) {
             boost = parser.floatValue();
           }
         }
       }
       if (objValue == null) {
         // no value
         return null;
       }
       value = objValue;
     } else {
       value = parser.shortValue();
       if (context.includeInAll(includeInAll, this)) {
         context.allEntries().addText(names.fullName(), parser.text(), boost);
       }
     }
   }
   CustomShortNumericField field = new CustomShortNumericField(this, value);
   field.setBoost(boost);
   return field;
 }