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


Java XContentParser.textOrNull方法代码示例

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


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

示例1: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public InnerHitsSubSearchContext parse(QueryParseContext parserContext) throws IOException, QueryParsingException {
    String fieldName = null;
    XContentParser.Token token;
    String innerHitName = null;
    SubSearchContext subSearchContext = new SubSearchContext(SearchContext.current());
    try {
        XContentParser parser = parserContext.parser();
        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token == XContentParser.Token.FIELD_NAME) {
                fieldName = parser.currentName();
            } else if (token.isValue()) {
                if ("name".equals(fieldName)) {
                    innerHitName = parser.textOrNull();
                } else {
                    parseCommonInnerHitOptions(parser, token, fieldName, subSearchContext, sortParseElement, sourceParseElement, highlighterParseElement, scriptFieldsParseElement, fieldDataFieldsParseElement);
                }
            } else {
                parseCommonInnerHitOptions(parser, token, fieldName, subSearchContext, sortParseElement, sourceParseElement, highlighterParseElement, scriptFieldsParseElement, fieldDataFieldsParseElement);
            }
        }
    } catch (Exception e) {
        throw new QueryParsingException(parserContext, "Failed to parse [_inner_hits]", e);
    }
    return new InnerHitsSubSearchContext(innerHitName, subSearchContext);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:26,代码来源:InnerHitsQueryParserHelper.java

示例2: parseTermsLookup

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static TermsLookup parseTermsLookup(XContentParser parser) throws IOException {
    String index = null;
    String type = null;
    String id = null;
    String path = null;
    String routing = null;
    XContentParser.Token token;
    String currentFieldName = "";
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            switch (currentFieldName) {
            case "index":
                index = parser.textOrNull();
                break;
            case "type":
                type = parser.text();
                break;
            case "id":
                id = parser.text();
                break;
            case "routing":
                routing = parser.textOrNull();
                break;
            case "path":
                path = parser.text();
                break;
            default:
                throw new ParsingException(parser.getTokenLocation(), "[" + TermsQueryBuilder.NAME +
                    "] query does not support [" + currentFieldName + "] within lookup element");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "[" + TermsQueryBuilder.NAME + "] unknown token ["
                + token + "] after [" + currentFieldName + "]");
        }
    }
    return new TermsLookup(index, type, id, path).routing(routing);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:TermsLookup.java

示例3: parseRange

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
private static Range parseRange(XContentParser parser, QueryParseContext context) throws IOException {
    String key = null;
    String from = null;
    String to = null;
    String mask = null;

    if (parser.currentToken() != Token.START_OBJECT) {
        throw new ParsingException(parser.getTokenLocation(), "[ranges] must contain objects, but hit a " + parser.currentToken());
    }
    while (parser.nextToken() != Token.END_OBJECT) {
        if (parser.currentToken() == Token.FIELD_NAME) {
            continue;
        }
        if (RangeAggregator.Range.KEY_FIELD.match(parser.currentName())) {
            key = parser.text();
        } else if (RangeAggregator.Range.FROM_FIELD.match(parser.currentName())) {
            from = parser.textOrNull();
        } else if (RangeAggregator.Range.TO_FIELD.match(parser.currentName())) {
            to = parser.textOrNull();
        } else if (MASK_FIELD.match(parser.currentName())) {
            mask = parser.text();
        } else {
            throw new ParsingException(parser.getTokenLocation(), "Unexpected ip range parameter: [" + parser.currentName() + "]");
        }
    }
    if (mask != null) {
        if (key == null) {
            key = mask;
        }
        return new Range(key, mask);
    } else {
        return new Range(key, from, to);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:IpRangeAggregationBuilder.java

示例4: parseExplanation

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
private static Explanation parseExplanation(XContentParser parser) throws IOException {
    ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation);
    XContentParser.Token token;
    Float value = null;
    String description = null;
    List<Explanation> details = new ArrayList<>();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, () -> parser.getTokenLocation());
        String currentFieldName = parser.currentName();
        token = parser.nextToken();
        if (Fields.VALUE.equals(currentFieldName)) {
            value = parser.floatValue();
        } else if (Fields.DESCRIPTION.equals(currentFieldName)) {
            description = parser.textOrNull();
        } else if (Fields.DETAILS.equals(currentFieldName)) {
            ensureExpectedToken(XContentParser.Token.START_ARRAY, token, () -> parser.getTokenLocation());
            while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                details.add(parseExplanation(parser));
            }
        } else {
            throwUnknownField(currentFieldName, parser.getTokenLocation());
        }
    }
    if (value == null) {
        throw new ParsingException(parser.getTokenLocation(), "missing explanation value");
    }
    if (description == null) {
        throw new ParsingException(parser.getTokenLocation(), "missing explanation description");
    }
    return Explanation.match(value, description, details);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:SearchHit.java

示例5: parseCreateFieldForString

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的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

示例6: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static RegexpQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
    XContentParser parser = parseContext.parser();
    String fieldName = null;
    String rewrite = null;
    String value = null;
    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    int flagsValue = RegexpQueryBuilder.DEFAULT_FLAGS_VALUE;
    int maxDeterminizedStates = RegexpQueryBuilder.DEFAULT_MAX_DETERMINIZED_STATES;
    String queryName = null;
    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (parseContext.isDeprecatedSetting(currentFieldName)) {
            // skip
        } else if (token == XContentParser.Token.START_OBJECT) {
            throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, currentFieldName);
            fieldName = currentFieldName;
            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                if (token == XContentParser.Token.FIELD_NAME) {
                    currentFieldName = parser.currentName();
                } else {
                    if (VALUE_FIELD.match(currentFieldName)) {
                        value = parser.textOrNull();
                    } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
                        boost = parser.floatValue();
                    } else if (REWRITE_FIELD.match(currentFieldName)) {
                        rewrite = parser.textOrNull();
                    } else if (FLAGS_FIELD.match(currentFieldName)) {
                        String flags = parser.textOrNull();
                        flagsValue = RegexpFlag.resolveValue(flags);
                    } else if (MAX_DETERMINIZED_STATES_FIELD.match(currentFieldName)) {
                        maxDeterminizedStates = parser.intValue();
                    } else if (FLAGS_VALUE_FIELD.match(currentFieldName)) {
                        flagsValue = parser.intValue();
                    } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
                        queryName = parser.text();
                    } else {
                        throw new ParsingException(parser.getTokenLocation(),
                                "[regexp] query does not support [" + currentFieldName + "]");
                    }
                }
            }
        } else {
            if (NAME_FIELD.match(currentFieldName)) {
                queryName = parser.text();
            } else {
                throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
                fieldName = currentFieldName;
                value = parser.textOrNull();
            }
        }
    }

    return new RegexpQueryBuilder(fieldName, value)
            .flags(flagsValue)
            .maxDeterminizedStates(maxDeterminizedStates)
            .rewrite(rewrite)
            .boost(boost)
            .queryName(queryName);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:63,代码来源:RegexpQueryBuilder.java

示例7: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static PrefixQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
    XContentParser parser = parseContext.parser();

    String fieldName = null;
    String value = null;
    String rewrite = null;

    String queryName = null;
    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (parseContext.isDeprecatedSetting(currentFieldName)) {
            // skip
        } else if (token == XContentParser.Token.START_OBJECT) {
            throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, currentFieldName);
            fieldName = currentFieldName;
            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                if (token == XContentParser.Token.FIELD_NAME) {
                    currentFieldName = parser.currentName();
                } else {
                    if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
                        queryName = parser.text();
                    } else if (PREFIX_FIELD.match(currentFieldName)) {
                        value = parser.textOrNull();
                    } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
                        boost = parser.floatValue();
                    } else if (REWRITE_FIELD.match(currentFieldName)) {
                        rewrite = parser.textOrNull();
                    } else {
                        throw new ParsingException(parser.getTokenLocation(),
                                "[prefix] query does not support [" + currentFieldName + "]");
                    }
                }
            }
        } else {
            throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
            fieldName = currentFieldName;
            value = parser.textOrNull();
        }
    }

    return new PrefixQueryBuilder(fieldName, value)
            .rewrite(rewrite)
            .boost(boost)
            .queryName(queryName);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:50,代码来源:PrefixQueryBuilder.java

示例8: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static WildcardQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
    XContentParser parser = parseContext.parser();
    String fieldName = null;
    String rewrite = null;
    String value = null;
    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    String queryName = null;
    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (parseContext.isDeprecatedSetting(currentFieldName)) {
            // skip
        } else if (token == XContentParser.Token.START_OBJECT) {
            throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, currentFieldName);
            fieldName = currentFieldName;
            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                if (token == XContentParser.Token.FIELD_NAME) {
                    currentFieldName = parser.currentName();
                } else {
                    if (WILDCARD_FIELD.match(currentFieldName)) {
                        value = parser.text();
                    } else if (VALUE_FIELD.match(currentFieldName)) {
                        value = parser.text();
                    } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
                        boost = parser.floatValue();
                    } else if (REWRITE_FIELD.match(currentFieldName)) {
                        rewrite = parser.textOrNull();
                    } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
                        queryName = parser.text();
                    } else {
                        throw new ParsingException(parser.getTokenLocation(),
                                "[wildcard] query does not support [" + currentFieldName + "]");
                    }
                }
            }
        } else {
            throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
            fieldName = parser.currentName();
            value = parser.text();
        }
    }

    return new WildcardQueryBuilder(fieldName, value)
            .rewrite(rewrite)
            .boost(boost)
            .queryName(queryName);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:50,代码来源:WildcardQueryBuilder.java

示例9: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static FuzzyQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
    XContentParser parser = parseContext.parser();
    String fieldName = null;
    Object value = null;
    Fuzziness fuzziness = FuzzyQueryBuilder.DEFAULT_FUZZINESS;
    int prefixLength = FuzzyQueryBuilder.DEFAULT_PREFIX_LENGTH;
    int maxExpansions = FuzzyQueryBuilder.DEFAULT_MAX_EXPANSIONS;
    boolean transpositions = FuzzyQueryBuilder.DEFAULT_TRANSPOSITIONS;
    String rewrite = null;
    String queryName = null;
    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (parseContext.isDeprecatedSetting(currentFieldName)) {
            // skip
        } else if (token == XContentParser.Token.START_OBJECT) {
            throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, currentFieldName);
            fieldName = currentFieldName;
            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                if (token == XContentParser.Token.FIELD_NAME) {
                    currentFieldName = parser.currentName();
                } else {
                    if (TERM_FIELD.match(currentFieldName)) {
                        value = parser.objectBytes();
                    } else if (VALUE_FIELD.match(currentFieldName)) {
                        value = parser.objectBytes();
                    } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
                        boost = parser.floatValue();
                    } else if (Fuzziness.FIELD.match(currentFieldName)) {
                        fuzziness = Fuzziness.parse(parser);
                    } else if (PREFIX_LENGTH_FIELD.match(currentFieldName)) {
                        prefixLength = parser.intValue();
                    } else if (MAX_EXPANSIONS_FIELD.match(currentFieldName)) {
                        maxExpansions = parser.intValue();
                    } else if (TRANSPOSITIONS_FIELD.match(currentFieldName)) {
                        transpositions = parser.booleanValue();
                    } else if (REWRITE_FIELD.match(currentFieldName)) {
                        rewrite = parser.textOrNull();
                    } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
                        queryName = parser.text();
                    } else {
                        throw new ParsingException(parser.getTokenLocation(),
                                "[fuzzy] query does not support [" + currentFieldName + "]");
                    }
                }
            }
        } else {
            throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
            fieldName = parser.currentName();
            value = parser.objectBytes();
        }
    }
    return new FuzzyQueryBuilder(fieldName, value)
            .fuzziness(fuzziness)
            .prefixLength(prefixLength)
            .maxExpansions(maxExpansions)
            .transpositions(transpositions)
            .rewrite(rewrite)
            .boost(boost)
            .queryName(queryName);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:65,代码来源:FuzzyQueryBuilder.java

示例10: parseCreateField

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    final boolean includeInAll = context.includeInAll(this.includeInAll, this);

    XContentParser parser = context.parser();
    Object value;
    Number numericValue = null;
    if (context.externalValueSet()) {
        value = context.externalValue();
    } else if (parser.currentToken() == Token.VALUE_NULL) {
        value = null;
    } else if (coerce.value()
            && parser.currentToken() == Token.VALUE_STRING
            && parser.textLength() == 0) {
        value = null;
    } else {
        try {
            numericValue = fieldType().type.parse(parser, coerce.value());
        } catch (IllegalArgumentException e) {
            if (ignoreMalformed.value()) {
                return;
            } else {
                throw e;
            }
        }
        if (includeInAll) {
            value = parser.textOrNull(); // preserve formatting
        } else {
            value = numericValue;
        }
    }

    if (value == null) {
        value = fieldType().nullValue();
    }

    if (value == null) {
        return;
    }

    if (numericValue == null) {
        numericValue = fieldType().type.parse(value, coerce.value());
    }

    if (includeInAll) {
        context.allEntries().addText(fieldType().name(), value.toString(), fieldType().boost());
    }

    boolean indexed = fieldType().indexOptions() != IndexOptions.NONE;
    boolean docValued = fieldType().hasDocValues();
    boolean stored = fieldType().stored();
    fields.addAll(fieldType().type.createFields(fieldType().name(), numericValue, indexed, docValued, stored));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:54,代码来源:NumberFieldMapper.java

示例11: parseCreateField

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    final boolean includeInAll = context.includeInAll(this.includeInAll, this);

    XContentParser parser = context.parser();
    Object value;
    Number numericValue = null;
    if (context.externalValueSet()) {
        value = context.externalValue();
    } else if (parser.currentToken() == Token.VALUE_NULL) {
        value = null;
    } else if (coerce.value()
            && parser.currentToken() == Token.VALUE_STRING
            && parser.textLength() == 0) {
        value = null;
    } else {
        try {
            numericValue = NumberFieldMapper.NumberType.DOUBLE.parse(parser, coerce.value());
        } catch (IllegalArgumentException e) {
            if (ignoreMalformed.value()) {
                return;
            } else {
                throw e;
            }
        }
        if (includeInAll) {
            value = parser.textOrNull(); // preserve formatting
        } else {
            value = numericValue;
        }
    }

    if (value == null) {
        value = fieldType().nullValue();
    }

    if (value == null) {
        return;
    }

    if (numericValue == null) {
        numericValue = NumberFieldMapper.NumberType.DOUBLE.parse(value, false);
    }

    if (includeInAll) {
        context.allEntries().addText(fieldType().name(), value.toString(), fieldType().boost());
    }

    double doubleValue = numericValue.doubleValue();
    if (Double.isFinite(doubleValue) == false) {
        // since we encode to a long, we have no way to carry NaNs and infinities
        throw new IllegalArgumentException("[scaled_float] only supports finite values, but got [" + doubleValue + "]");
    }
    long scaledValue = Math.round(doubleValue * fieldType().getScalingFactor());

    boolean indexed = fieldType().indexOptions() != IndexOptions.NONE;
    boolean docValued = fieldType().hasDocValues();
    boolean stored = fieldType().stored();
    fields.addAll(NumberFieldMapper.NumberType.LONG.createFields(fieldType().name(), scaledValue, indexed, docValued, stored));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:61,代码来源:ScaledFloatFieldMapper.java

示例12: parseCreateField

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    String value;
    if (context.externalValueSet()) {
        value = context.externalValue().toString();
    } else {
        XContentParser parser = context.parser();
        if (parser.currentToken() == XContentParser.Token.VALUE_NULL) {
            value = fieldType().nullValueAsString();
        } else {
            value =  parser.textOrNull();
        }
    }

    if (value == null || value.length() > ignoreAbove) {
        return;
    }

    final NamedAnalyzer normalizer = fieldType().normalizer();
    if (normalizer != null) {
        try (TokenStream ts = normalizer.tokenStream(name(), value)) {
            final CharTermAttribute termAtt = ts.addAttribute(CharTermAttribute.class);
            ts.reset();
            if (ts.incrementToken() == false) {
              throw new IllegalStateException("The normalization token stream is "
                  + "expected to produce exactly 1 token, but got 0 for analyzer "
                  + normalizer + " and input \"" + value + "\"");
            }
            final String newValue = termAtt.toString();
            if (ts.incrementToken()) {
              throw new IllegalStateException("The normalization token stream is "
                  + "expected to produce exactly 1 token, but got 2+ for analyzer "
                  + normalizer + " and input \"" + value + "\"");
            }
            ts.end();
            value = newValue;
        }
    }

    if (context.includeInAll(includeInAll, this)) {
        context.allEntries().addText(fieldType().name(), value, fieldType().boost());
    }

    // convert to utf8 only once before feeding postings/dv/stored fields
    final BytesRef binaryValue = new BytesRef(value);
    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        Field field = new Field(fieldType().name(), binaryValue, fieldType());
        fields.add(field);
    }
    if (fieldType().hasDocValues()) {
        fields.add(new SortedSetDocValuesField(fieldType().name(), binaryValue));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:54,代码来源:KeywordFieldMapper.java

示例13: addCompoundSortField

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
private void addCompoundSortField(XContentParser parser, SearchContext context, List<SortField> sortFields) throws Exception {
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            String fieldName = parser.currentName();
            boolean reverse = false;
            String missing = null;
            String innerJsonName = null;
            String unmappedType = null;
            MultiValueMode sortMode = null;
            NestedInnerQueryParseSupport nestedFilterParseHelper = null;
            token = parser.nextToken();
            if (token == XContentParser.Token.VALUE_STRING) {
                String direction = parser.text();
                if (direction.equals("asc")) {
                    reverse = SCORE_FIELD_NAME.equals(fieldName);
                } else if (direction.equals("desc")) {
                    reverse = !SCORE_FIELD_NAME.equals(fieldName);
                } else {
                    throw new IllegalArgumentException("sort direction [" + fieldName + "] not supported");
                }
                addSortField(context, sortFields, fieldName, reverse, unmappedType, missing, sortMode, nestedFilterParseHelper);
            } else {
                if (parsers.containsKey(fieldName)) {
                    sortFields.add(parsers.get(fieldName).parse(parser, context));
                } else {
                    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                        if (token == XContentParser.Token.FIELD_NAME) {
                            innerJsonName = parser.currentName();
                        } else if (token.isValue()) {
                            if (context.parseFieldMatcher().match(innerJsonName, REVERSE_FIELD)) {
                                reverse = parser.booleanValue();
                            } else if ("order".equals(innerJsonName)) {
                                if ("asc".equals(parser.text())) {
                                    reverse = SCORE_FIELD_NAME.equals(fieldName);
                                } else if ("desc".equals(parser.text())) {
                                    reverse = !SCORE_FIELD_NAME.equals(fieldName);
                                }
                            } else if ("missing".equals(innerJsonName)) {
                                missing = parser.textOrNull();
                            } else if (context.parseFieldMatcher().match(innerJsonName, IGNORE_UNMAPPED)) {
                                // backward compatibility: ignore_unmapped has been replaced with unmapped_type
                                if (unmappedType == null // don't override if unmapped_type has been provided too
                                        && parser.booleanValue()) {
                                    unmappedType = LongFieldMapper.CONTENT_TYPE;
                                }
                            } else if (context.parseFieldMatcher().match(innerJsonName, UNMAPPED_TYPE)) {
                                unmappedType = parser.textOrNull();
                            } else if ("mode".equals(innerJsonName)) {
                                sortMode = MultiValueMode.fromString(parser.text());
                            } else if ("nested_path".equals(innerJsonName) || "nestedPath".equals(innerJsonName)) {
                                if (nestedFilterParseHelper == null) {
                                    nestedFilterParseHelper = new NestedInnerQueryParseSupport(parser, context);
                                }
                                nestedFilterParseHelper.setPath(parser.text());
                            } else {
                                throw new IllegalArgumentException("sort option [" + innerJsonName + "] not supported");
                            }
                        } else if (token == XContentParser.Token.START_OBJECT) {
                            if ("nested_filter".equals(innerJsonName) || "nestedFilter".equals(innerJsonName)) {
                                if (nestedFilterParseHelper == null) {
                                    nestedFilterParseHelper = new NestedInnerQueryParseSupport(parser, context);
                                }
                                nestedFilterParseHelper.filter();
                            } else {
                                throw new IllegalArgumentException("sort option [" + innerJsonName + "] not supported");
                            }
                        }
                    }
                    addSortField(context, sortFields, fieldName, reverse, unmappedType, missing, sortMode, nestedFilterParseHelper);
                }
            }
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:76,代码来源:SortParseElement.java


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