当前位置: 首页>>代码示例>>Java>>正文


Java ParseContext.externalValueSet方法代码示例

本文整理汇总了Java中org.elasticsearch.index.mapper.ParseContext.externalValueSet方法的典型用法代码示例。如果您正苦于以下问题:Java ParseContext.externalValueSet方法的具体用法?Java ParseContext.externalValueSet怎么用?Java ParseContext.externalValueSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.index.mapper.ParseContext的用法示例。


在下文中一共展示了ParseContext.externalValueSet方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseCreateField

import org.elasticsearch.index.mapper.ParseContext; //导入方法依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    String value;
    if (context.externalValueSet()) {
        value = context.externalValue().toString();
    } else {
        value = context.parser().textOrNull();
    }
    
    if (value == null) {
        return;
    }

    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        Field field = new Field(fieldType().name(), value, fieldType());
        fields.add(field);
    }
    if (fieldType().hasDocValues()) {
        fields.add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(value)));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:FakeStringFieldMapper.java

示例2: parseCreateField

import org.elasticsearch.index.mapper.ParseContext; //导入方法依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields)
        throws IOException {
    final Object value;
    if (context.externalValueSet()) {
        value = context.externalValue();
    } else {
        value = context.parser().textOrNull();
    }
    if (value != null) {
        final BytesRef bytes = new BytesRef(value.toString());
        final long hash = MurmurHash3.hash128(bytes.bytes, bytes.offset, bytes.length, 0, new MurmurHash3.Hash128()).h1;
        fields.add(new SortedNumericDocValuesField(fieldType().name(), hash));
        if (fieldType().stored()) {
            fields.add(new StoredField(name(), hash));
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:Murmur3FieldMapper.java

示例3: innerParseCreateField

import org.elasticsearch.index.mapper.ParseContext; //导入方法依赖的package包/类
@Override
protected void innerParseCreateField(ParseContext context, List<Field> fields) throws IOException {
    String ipAsString;
    if (context.externalValueSet()) {
        ipAsString = (String) context.externalValue();
        if (ipAsString == null) {
            ipAsString = fieldType().nullValueAsString();
        }
    } else {
        if (context.parser().currentToken() == XContentParser.Token.VALUE_NULL) {
            ipAsString = fieldType().nullValueAsString();
        } else {
            ipAsString = context.parser().text();
        }
    }

    if (ipAsString == null) {
        return;
    }
    if (context.includeInAll(includeInAll, this)) {
        context.allEntries().addText(fieldType().names().fullName(), ipAsString, fieldType().boost());
    }

    final long value = ipToLong(ipAsString);
    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        CustomLongNumericField field = new CustomLongNumericField(value, fieldType());
        field.setBoost(fieldType().boost());
        fields.add(field);
    }
    if (fieldType().hasDocValues()) {
        addDocValue(context, fields, value);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:34,代码来源:IpFieldMapper.java

示例4: parseCreateFieldForString

import org.elasticsearch.index.mapper.ParseContext; //导入方法依赖的package包/类
/**
 * Parse a field as though it were a string.
 * @param context parse context used during parsing
 * @param nullValue value to use for null
 * @param defaultBoost default boost value returned unless overwritten in the field
 * @return the parsed field and the boost either parsed or defaulted
 * @throws IOException if thrown while parsing
 */
public static ValueAndBoost parseCreateFieldForString(ParseContext context, String nullValue, float defaultBoost) throws IOException {
    if (context.externalValueSet()) {
        return new ValueAndBoost(context.externalValue().toString(), defaultBoost);
    }
    XContentParser parser = context.parser();
    if (parser.currentToken() == XContentParser.Token.VALUE_NULL) {
        return new ValueAndBoost(nullValue, defaultBoost);
    }
    if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
        XContentParser.Token token;
        String currentFieldName = null;
        String value = nullValue;
        float boost = defaultBoost;
        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)) {
                    value = parser.textOrNull();
                } else if ("boost".equals(currentFieldName) || "_boost".equals(currentFieldName)) {
                    boost = parser.floatValue();
                } else {
                    throw new IllegalArgumentException("unknown property [" + currentFieldName + "]");
                }
            }
        }
        return new ValueAndBoost(value, boost);
    }
    return new ValueAndBoost(parser.textOrNull(), defaultBoost);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:39,代码来源:StringFieldMapper.java

示例5: innerParseCreateField

import org.elasticsearch.index.mapper.ParseContext; //导入方法依赖的package包/类
@Override
protected void innerParseCreateField(ParseContext context, List<Field> fields) throws IOException {
    String dateAsString = null;
    float boost = fieldType().boost();
    if (context.externalValueSet()) {
        Object externalValue = context.externalValue();
        dateAsString = (String) externalValue;
        if (dateAsString == null) {
            dateAsString = fieldType().nullValueAsString();
        }
    } else {
        XContentParser parser = context.parser();
        XContentParser.Token token = parser.currentToken();
        if (token == XContentParser.Token.VALUE_NULL) {
            dateAsString = fieldType().nullValueAsString();
        } else if (token == XContentParser.Token.VALUE_NUMBER) {
            dateAsString = parser.text();
        } else if (token == XContentParser.Token.START_OBJECT) {
            String currentFieldName = null;
            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 (token == XContentParser.Token.VALUE_NULL) {
                            dateAsString = fieldType().nullValueAsString();
                        } else {
                            dateAsString = parser.text();
                        }
                    } else if ("boost".equals(currentFieldName) || "_boost".equals(currentFieldName)) {
                        boost = parser.floatValue();
                    } else {
                        throw new IllegalArgumentException("unknown property [" + currentFieldName + "]");
                    }
                }
            }
        } else {
            dateAsString = parser.text();
        }
    }

    Long value = null;
    if (dateAsString != null) {
        if (context.includeInAll(includeInAll, this)) {
            context.allEntries().addText(fieldType().names().fullName(), dateAsString, boost);
        }
        value = fieldType().parseStringValue(dateAsString);
    }

    if (value != null) {
        if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
            CustomLongNumericField field = new CustomLongNumericField(value, fieldType());
            field.setBoost(boost);
            fields.add(field);
        }
        if (fieldType().hasDocValues()) {
            addDocValue(context, fields, value);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:61,代码来源:DateFieldMapper.java

示例6: innerParseCreateField

import org.elasticsearch.index.mapper.ParseContext; //导入方法依赖的package包/类
@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().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 (fieldType().nullValue() == null) {
                return;
            }
            value = fieldType().nullValue();
            if (fieldType().nullValueAsString() != null && (context.includeInAll(includeInAll, this))) {
                context.allEntries().addText(fieldType().names().fullName(), fieldType().nullValueAsString(), boost);
            }
        } else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
            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().names().fullName(), parser.text(), boost);
            }
        }
    }
    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        CustomShortNumericField field = new CustomShortNumericField(value, fieldType());
        field.setBoost(boost);
        fields.add(field);
    }
    if (fieldType().hasDocValues()) {
        addDocValue(context, fields, value);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:79,代码来源:ShortFieldMapper.java

示例7: innerParseCreateField

import org.elasticsearch.index.mapper.ParseContext; //导入方法依赖的package包/类
@Override
protected void innerParseCreateField(ParseContext context, List<Field> fields) throws IOException {
    int 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 = Integer.parseInt(sExternalValue);
            }
        } else {
            value = ((Number) externalValue).intValue();
        }
        if (context.includeInAll(includeInAll, this)) {
            context.allEntries().addText(fieldType().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 (fieldType().nullValue() == null) {
                return;
            }
            value = fieldType().nullValue();
            if (fieldType().nullValueAsString() != null && (context.includeInAll(includeInAll, this))) {
                context.allEntries().addText(fieldType().names().fullName(), fieldType().nullValueAsString(), boost);
            }
        } else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
            XContentParser.Token token;
            String currentFieldName = null;
            Integer 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.intValue(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.intValue(coerce.value());
            if (context.includeInAll(includeInAll, this)) {
                context.allEntries().addText(fieldType().names().fullName(), parser.text(), boost);
            }
        }
    }
    addIntegerFields(context, fields, value, boost);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:72,代码来源:IntegerFieldMapper.java

示例8: innerParseCreateField

import org.elasticsearch.index.mapper.ParseContext; //导入方法依赖的package包/类
@Override
protected void innerParseCreateField(ParseContext context, List<Field> fields) throws IOException {
    byte 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 = Byte.parseByte(sExternalValue);
            }
        } else {
            value = ((Number) externalValue).byteValue();
        }
        if (context.includeInAll(includeInAll, this)) {
            context.allEntries().addText(fieldType().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 (fieldType().nullValue() == null) {
                return;
            }
            value = fieldType().nullValue();
            if (fieldType().nullValueAsString() != null && (context.includeInAll(includeInAll, this))) {
                context.allEntries().addText(fieldType().names().fullName(), fieldType().nullValueAsString(), boost);
            }
        } else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
            XContentParser.Token token;
            String currentFieldName = null;
            Byte 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 = (byte) 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 = (byte) parser.shortValue(coerce.value());
            if (context.includeInAll(includeInAll, this)) {
                context.allEntries().addText(fieldType().names().fullName(), parser.text(), boost);
            }
        }
    }
    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        CustomByteNumericField field = new CustomByteNumericField(value, fieldType());
        field.setBoost(boost);
        fields.add(field);
    }
    if (fieldType().hasDocValues()) {
        addDocValue(context, fields, value);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:79,代码来源:ByteFieldMapper.java

示例9: innerParseCreateField

import org.elasticsearch.index.mapper.ParseContext; //导入方法依赖的package包/类
@Override
protected void innerParseCreateField(ParseContext context, List<Field> fields) throws IOException {
    long 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 = Long.parseLong(sExternalValue);
            }
        } else {
            value = ((Number) externalValue).longValue();
        }
        if (context.includeInAll(includeInAll, this)) {
            context.allEntries().addText(fieldType().names().fullName(), Long.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().names().fullName(), fieldType().nullValueAsString(), boost);
            }
        } else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
            XContentParser.Token token;
            String currentFieldName = null;
            Long 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.longValue(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.longValue(coerce.value());
            if (context.includeInAll(includeInAll, this)) {
                context.allEntries().addText(fieldType().names().fullName(), parser.text(), boost);
            }
        }
    }
    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        CustomLongNumericField field = new CustomLongNumericField(value, fieldType());
        field.setBoost(boost);
        fields.add(field);
    }
    if (fieldType().hasDocValues()) {
        addDocValue(context, fields, value);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:79,代码来源:LongFieldMapper.java


注:本文中的org.elasticsearch.index.mapper.ParseContext.externalValueSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。