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


Java XContentParser.text方法代码示例

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


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

示例1: readMapStrings

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
static Map<String, String> readMapStrings(XContentParser parser, MapStringsFactory mapStringsFactory) throws IOException {
    Map<String, String> map = mapStringsFactory.newMap();
    XContentParser.Token token = parser.currentToken();
    if (token == null) {
        token = parser.nextToken();
    }
    if (token == XContentParser.Token.START_OBJECT) {
        token = parser.nextToken();
    }
    for (; token == XContentParser.Token.FIELD_NAME; token = parser.nextToken()) {
        // Must point to field name
        String fieldName = parser.currentName();
        // And then the value...
        parser.nextToken();
        String value = parser.text();
        map.put(fieldName, value);
    }
    return map;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:AbstractXContentParser.java

示例2: setInline

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
/**
 * Since inline scripts can accept code rather than just an id, they must also be able
 * to handle template parsing, hence the need for custom parsing code.  Templates can
 * consist of either an {@link String} or a JSON object.  If a JSON object is discovered
 * then the content type option must also be saved as a compiler option.
 */
private void setInline(XContentParser parser) {
    try {
        if (type != null) {
            throwOnlyOneOfType();
        }

        type = ScriptType.INLINE;

        if (parser.currentToken() == Token.START_OBJECT) {
            //this is really for search templates, that need to be converted to json format
            XContentBuilder builder = XContentFactory.jsonBuilder();
            idOrCode = builder.copyCurrentStructure(parser).string();
            options.put(CONTENT_TYPE_OPTION, XContentType.JSON.mediaType());
        } else {
            idOrCode = parser.text();
        }
    } catch (IOException exception) {
        throw new UncheckedIOException(exception);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:Script.java

示例3: parseOrder

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
private static InternalOrder parseOrder(XContentParser parser, QueryParseContext context) throws IOException {
    InternalOrder order = null;
    Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            String dir = parser.text();
            boolean asc = "asc".equals(dir);
            if (!asc && !"desc".equals(dir)) {
                throw new ParsingException(parser.getTokenLocation(), "Unknown order direction: [" + dir
                        + "]. Should be either [asc] or [desc]");
            }
            order = resolveOrder(currentFieldName, asc);
        }
    }
    return order;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:DateHistogramAggregationBuilder.java

示例4: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static TermVectorsFetchBuilder fromXContent(XContentParser parser) throws IOException {
    String field;
    XContentParser.Token token = parser.currentToken();
    if (token == XContentParser.Token.VALUE_STRING) {
        field = parser.text();
    } else {
        throw new ParsingException(parser.getTokenLocation(), "Expected a VALUE_STRING but got " + token);
    }
    if (field == null) {
        throw new ParsingException(parser.getTokenLocation(), "no fields specified for " + TermVectorsFetchSubPhase.NAME);
    }
    return new TermVectorsFetchBuilder(field);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:FetchSubPhasePluginIT.java

示例5: fromXContent

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

    String fieldPattern = null;
    String queryName = null;
    float boost = AbstractQueryBuilder.DEFAULT_BOOST;

    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if (FIELD_FIELD.match(currentFieldName)) {
                fieldPattern = parser.text();
            } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
                queryName = parser.text();
            } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
                boost = parser.floatValue();
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[" + ExistsQueryBuilder.NAME +
                        "] query does not support [" + currentFieldName + "]");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "[" + ExistsQueryBuilder.NAME +
                    "] unknown token [" + token + "] after [" + currentFieldName + "]");
        }
    }

    if (fieldPattern == null) {
        throw new ParsingException(parser.getTokenLocation(), "[" + ExistsQueryBuilder.NAME + "] must be provided with a [field]");
    }

    ExistsQueryBuilder builder = new ExistsQueryBuilder(fieldPattern);
    builder.queryName(queryName);
    builder.boost(boost);
    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:39,代码来源:ExistsQueryBuilder.java

示例6: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static NestedAggregationBuilder parse(String aggregationName, QueryParseContext context) throws IOException {
    String path = null;

    XContentParser.Token token;
    String currentFieldName = null;
    XContentParser parser = context.parser();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            if (NestedAggregator.PATH_FIELD.match(currentFieldName)) {
                path = parser.text();
            } else {
                throw new ParsingException(parser.getTokenLocation(),
                        "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + aggregationName + "].");
        }
    }

    if (path == null) {
        // "field" doesn't exist, so we fall back to the context of the ancestors
        throw new ParsingException(parser.getTokenLocation(), "Missing [path] field for nested aggregation [" + aggregationName + "]");
    }

    return new NestedAggregationBuilder(aggregationName, path);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:NestedAggregationBuilder.java

示例7: parseRange

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
private static Range parseRange(XContentParser parser, QueryParseContext context) throws IOException {
    String fromAsStr = null;
    String toAsStr = null;
    double from = 0.0;
    double to = Double.POSITIVE_INFINITY;
    String key = null;
    String toOrFromOrKey = null;
    Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            toOrFromOrKey = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_NUMBER) {
            if (Range.FROM_FIELD.match(toOrFromOrKey)) {
                from = parser.doubleValue();
            } else if (Range.TO_FIELD.match(toOrFromOrKey)) {
                to = parser.doubleValue();
            }
        } else if (token == XContentParser.Token.VALUE_STRING) {
            if (Range.KEY_FIELD.match(toOrFromOrKey)) {
                key = parser.text();
            } else if (Range.FROM_FIELD.match(toOrFromOrKey)) {
                fromAsStr = parser.text();
            } else if (Range.TO_FIELD.match(toOrFromOrKey)) {
                toAsStr = parser.text();
            }
        }
    }
    if (fromAsStr != null || toAsStr != null) {
        return new Range(key, Double.parseDouble(fromAsStr), Double.parseDouble(toAsStr));
    } else {
        return new Range(key, from, to);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:GeoDistanceAggregationBuilder.java

示例8: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
    deprecationLogger.deprecated("The [missing] query is deprecated, please use an [exist] query in a [must_not] clause instead.");

    XContentParser parser = parseContext.parser();

    String fieldPattern = null;
    String queryName = null;
    boolean nullValue = DEFAULT_NULL_VALUE;
    boolean existence = DEFAULT_EXISTENCE_VALUE;

    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if ("field".equals(currentFieldName)) {
                fieldPattern = parser.text();
            } else if ("null_value".equals(currentFieldName)) {
                nullValue = parser.booleanValue();
            } else if ("existence".equals(currentFieldName)) {
                existence = parser.booleanValue();
            } else if ("_name".equals(currentFieldName)) {
                queryName = parser.text();
            } else {
                throw new QueryParsingException(parseContext, "[missing] query does not support [" + currentFieldName + "]");
            }
        }
    }

    if (fieldPattern == null) {
        throw new QueryParsingException(parseContext, "missing must be provided with a [field]");
    }

    return newFilter(parseContext, fieldPattern, existence, nullValue, queryName);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:38,代码来源:MissingQueryParser.java

示例9: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static ChildrenAggregationBuilder parse(String aggregationName, QueryParseContext context) throws IOException {
    String childType = null;

    XContentParser.Token token;
    String currentFieldName = null;
    XContentParser parser = context.parser();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            if ("type".equals(currentFieldName)) {
                childType = parser.text();
            } else {
                throw new ParsingException(parser.getTokenLocation(),
                        "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + aggregationName + "].");
        }
    }

    if (childType == null) {
        throw new ParsingException(parser.getTokenLocation(),
                "Missing [child_type] field for children aggregation [" + aggregationName + "]");
    }


    return new ChildrenAggregationBuilder(aggregationName, childType);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:ChildrenAggregationBuilder.java

示例10: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {
    String childType = null;

    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            if ("type".equals(currentFieldName)) {
                childType = parser.text();
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
                        + currentFieldName + "].", parser.getTokenLocation());
            }
        } else {
            throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
                    parser.getTokenLocation());
        }
    }

    if (childType == null) {
        throw new SearchParseException(context, "Missing [child_type] field for children aggregation [" + aggregationName + "]",
                parser.getTokenLocation());
    }

    ValuesSourceConfig<ValuesSource.Bytes.WithOrdinals.ParentChild> config = new ValuesSourceConfig<>(ValuesSource.Bytes.WithOrdinals.ParentChild.class);
    DocumentMapper childDocMapper = context.mapperService().documentMapper(childType);

    String parentType = null;
    Query parentFilter = null;
    Query childFilter = null;
    if (childDocMapper != null) {
        ParentFieldMapper parentFieldMapper = childDocMapper.parentFieldMapper();
        if (!parentFieldMapper.active()) {
            throw new SearchParseException(context, "[children] no [_parent] field not configured that points to a parent type", parser.getTokenLocation());
        }
        parentType = parentFieldMapper.type();
        DocumentMapper parentDocMapper = context.mapperService().documentMapper(parentType);
        if (parentDocMapper != null) {
            // TODO: use the query API
            parentFilter = parentDocMapper.typeFilter();
            childFilter = childDocMapper.typeFilter();
            ParentChildIndexFieldData parentChildIndexFieldData = context.fieldData().getForField(parentFieldMapper.fieldType());
            config.fieldContext(new FieldContext(parentFieldMapper.fieldType().names().indexName(), parentChildIndexFieldData, parentFieldMapper.fieldType()));
        } else {
            config.unmapped(true);
        }
    } else {
        config.unmapped(true);
    }
    return new ParentToChildrenAggregator.Factory(aggregationName, config, parentType, parentFilter, childFilter);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:55,代码来源:ChildrenParser.java

示例11: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
    XContentParser parser = parseContext.parser();

    boolean queryFound = false;
    float boost = 1.0f;
    String parentType = null;
    boolean score = false;
    String queryName = null;
    InnerHitsSubSearchContext innerHits = null;

    String currentFieldName = null;
    XContentParser.Token token;
    XContentStructure.InnerQuery iq = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.START_OBJECT) {
            // Usually, the query would be parsed here, but the child
            // type may not have been extracted yet, so use the
            // XContentStructure.<type> facade to parse if available,
            // or delay parsing if not.
            if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) {
                iq = new XContentStructure.InnerQuery(parseContext, parentType == null ? null : new String[] {parentType});
                queryFound = true;
            } else if ("inner_hits".equals(currentFieldName)) {
                innerHits = innerHitsQueryParserHelper.parse(parseContext);
            } else {
                throw new QueryParsingException(parseContext, "[has_parent] query does not support [" + currentFieldName + "]");
            }
        } else if (token.isValue()) {
            if ("type".equals(currentFieldName) || "parent_type".equals(currentFieldName) || "parentType".equals(currentFieldName)) {
                parentType = parser.text();
            } else if (parseContext.parseFieldMatcher().match(currentFieldName, SCORE_MODE)) {
                String scoreTypeValue = parser.text();
                if ("score".equals(scoreTypeValue)) {
                    score = true;
                } else if ("none".equals(scoreTypeValue)) {
                    score = false;
                }
            } else if ("boost".equals(currentFieldName)) {
                boost = parser.floatValue();
            } else if ("_name".equals(currentFieldName)) {
                queryName = parser.text();
            } else {
                throw new QueryParsingException(parseContext, "[has_parent] query does not support [" + currentFieldName + "]");
            }
        }
    }
    if (!queryFound) {
        throw new QueryParsingException(parseContext, "[has_parent] query requires 'query' field");
    }
    if (parentType == null) {
        throw new QueryParsingException(parseContext, "[has_parent] query requires 'parent_type' field");
    }

    Query innerQuery = iq.asQuery(parentType);

    if (innerQuery == null) {
        return null;
    }

    innerQuery.setBoost(boost);
    Query query = createParentQuery(innerQuery, parentType, score, parseContext, innerHits);
    if (query == null) {
        return null;
    }

    query.setBoost(boost);
    if (queryName != null) {
        parseContext.addNamedQuery(queryName, query);
    }
    return query;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:75,代码来源:HasParentQueryParser.java

示例12: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static NestedQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
    XContentParser parser = parseContext.parser();
    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    ScoreMode scoreMode = ScoreMode.Avg;
    String queryName = null;
    QueryBuilder query = null;
    String path = null;
    String currentFieldName = null;
    InnerHitBuilder innerHitBuilder = null;
    boolean ignoreUnmapped = DEFAULT_IGNORE_UNMAPPED;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.START_OBJECT) {
            if (QUERY_FIELD.match(currentFieldName)) {
                query = parseContext.parseInnerQueryBuilder();
            } else if (INNER_HITS_FIELD.match(currentFieldName)) {
                innerHitBuilder = InnerHitBuilder.fromXContent(parseContext);
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[nested] query does not support [" + currentFieldName + "]");
            }
        } else if (token.isValue()) {
            if (PATH_FIELD.match(currentFieldName)) {
                path = parser.text();
            } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
                boost = parser.floatValue();
            } else if (IGNORE_UNMAPPED_FIELD.match(currentFieldName)) {
                ignoreUnmapped = parser.booleanValue();
            } else if (SCORE_MODE_FIELD.match(currentFieldName)) {
                scoreMode = HasChildQueryBuilder.parseScoreMode(parser.text());
            } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
                queryName = parser.text();
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[nested] query does not support [" + currentFieldName + "]");
            }
        }
    }
    NestedQueryBuilder queryBuilder =  new NestedQueryBuilder(path, query, scoreMode)
            .ignoreUnmapped(ignoreUnmapped)
            .queryName(queryName)
            .boost(boost);
    if (innerHitBuilder != null) {
        queryBuilder.innerHit(innerHitBuilder, ignoreUnmapped);
    }
    return queryBuilder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:48,代码来源:NestedQueryBuilder.java

示例13: fromXContent

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

    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    float tieBreaker = DisMaxQueryBuilder.DEFAULT_TIE_BREAKER;

    final List<QueryBuilder> queries = new ArrayList<>();
    boolean queriesFound = false;
    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 (token == XContentParser.Token.START_OBJECT) {
            if (QUERIES_FIELD.match(currentFieldName)) {
                queriesFound = true;
                queries.add(parseContext.parseInnerQueryBuilder());
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[dis_max] query does not support [" + currentFieldName + "]");
            }
        } else if (token == XContentParser.Token.START_ARRAY) {
            if (QUERIES_FIELD.match(currentFieldName)) {
                queriesFound = true;
                while (token != XContentParser.Token.END_ARRAY) {
                    queries.add(parseContext.parseInnerQueryBuilder());
                    token = parser.nextToken();
                }
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[dis_max] query does not support [" + currentFieldName + "]");
            }
        } else {
            if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
                boost = parser.floatValue();
            } else if (TIE_BREAKER_FIELD.match(currentFieldName)) {
                tieBreaker = parser.floatValue();
            } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
                queryName = parser.text();
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[dis_max] query does not support [" + currentFieldName + "]");
            }
        }
    }

    if (!queriesFound) {
        throw new ParsingException(parser.getTokenLocation(), "[dis_max] requires 'queries' field with at least one clause");
    }

    DisMaxQueryBuilder disMaxQuery = new DisMaxQueryBuilder();
    disMaxQuery.tieBreaker(tieBreaker);
    disMaxQuery.queryName(queryName);
    disMaxQuery.boost(boost);
    for (QueryBuilder query : queries) {
        disMaxQuery.add(query);
    }
    return disMaxQuery;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:59,代码来源:DisMaxQueryBuilder.java

示例14: 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

示例15: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
@Override
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
    deprecationLogger.deprecated("The [filtered] query is deprecated, please use a [bool] query instead with a [must] "
            + "clause for the query part and a [filter] clause for the filter part.");

    XContentParser parser = parseContext.parser();

    Query query = Queries.newMatchAllQuery();
    Query filter = null;
    boolean filterFound = false;
    float boost = 1.0f;
    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) {
            if ("query".equals(currentFieldName)) {
                query = parseContext.parseInnerQuery();
            } else if ("filter".equals(currentFieldName)) {
                filterFound = true;
                filter = parseContext.parseInnerFilter();
            } else {
                throw new QueryParsingException(parseContext, "[filtered] query does not support [" + currentFieldName + "]");
            }
        } else if (token.isValue()) {
            if ("strategy".equals(currentFieldName)) {
                // ignore
            } else if ("_name".equals(currentFieldName)) {
                queryName = parser.text();
            } else if ("boost".equals(currentFieldName)) {
                boost = parser.floatValue();
            } else {
                throw new QueryParsingException(parseContext, "[filtered] query does not support [" + currentFieldName + "]");
            }
        }
    }

    // parsed internally, but returned null during parsing...
    if (query == null) {
        return null;
    }

    BooleanQuery filteredQuery = Queries.filtered(query, filter);
    filteredQuery.setBoost(boost);
    if (queryName != null) {
        parseContext.addNamedQuery(queryName, filteredQuery);
    }
    return filteredQuery;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:56,代码来源:FilteredQueryParser.java


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