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


Java XContentParser.floatValue方法代码示例

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


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

示例1: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static SearchHits fromXContent(XContentParser parser) throws IOException {
    if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
        parser.nextToken();
        ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation);
    }
    XContentParser.Token token = parser.currentToken();
    String currentFieldName = null;
    List<SearchHit> hits = new ArrayList<>();
    long totalHits = 0;
    float maxScore = 0f;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if (Fields.TOTAL.equals(currentFieldName)) {
                totalHits = parser.longValue();
            } else if (Fields.MAX_SCORE.equals(currentFieldName)) {
                maxScore = parser.floatValue();
            } else {
                throwUnknownField(currentFieldName, parser.getTokenLocation());
            }
        } else if (token == XContentParser.Token.VALUE_NULL) {
            if (Fields.MAX_SCORE.equals(currentFieldName)) {
                maxScore = Float.NaN; // NaN gets rendered as null-field
            } else {
                throwUnknownField(currentFieldName, parser.getTokenLocation());
            }
        } else if (token == XContentParser.Token.START_ARRAY) {
            while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                hits.add(SearchHit.fromXContent(parser));
            }
        }
    }
    SearchHits searchHits = new SearchHits(hits.toArray(new SearchHit[hits.size()]), totalHits,
            maxScore);
    return searchHits;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:SearchHits.java

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

示例3: fromXContent

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

    String currentFieldName = null;
    XContentParser.Token token;
    String queryName = null;
    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    while (((token = parser.nextToken()) != XContentParser.Token.END_OBJECT && token != XContentParser.Token.END_ARRAY)) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            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(), "["+MatchNoneQueryBuilder.NAME +
                        "] query does not support [" + currentFieldName + "]");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "[" + MatchNoneQueryBuilder.NAME +
                    "] unknown token [" + token + "] after [" + currentFieldName + "]");
        }
    }

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

示例4: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static SpanMultiTermQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
    XContentParser parser = parseContext.parser();
    String currentFieldName = null;
    MultiTermQueryBuilder subQuery = null;
    String queryName = null;
    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    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 (MATCH_FIELD.match(currentFieldName)) {
                QueryBuilder query = parseContext.parseInnerQueryBuilder();
                if (query instanceof MultiTermQueryBuilder == false) {
                    throw new ParsingException(parser.getTokenLocation(),
                            "[span_multi] [" + MATCH_FIELD.getPreferredName() + "] must be of type multi term query");
                }
                subQuery = (MultiTermQueryBuilder) query;
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[span_multi] query does not support [" + currentFieldName + "]");
            }
        } else if (token.isValue()) {
            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(), "[span_multi] query does not support [" + currentFieldName + "]");
            }
        }
    }

    if (subQuery == null) {
        throw new ParsingException(parser.getTokenLocation(),
                "[span_multi] must have [" + MATCH_FIELD.getPreferredName() + "] multi term query clause");
    }

    return new SpanMultiTermQueryBuilder(subQuery).queryName(queryName).boost(boost);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:SpanMultiTermQueryBuilder.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包/类
@Override
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
    XContentParser parser = parseContext.parser();

    float boost = 1.0f;
    String currentFieldName = null;

    XContentParser.Token token;
    while (((token = parser.nextToken()) != XContentParser.Token.END_OBJECT && token != XContentParser.Token.END_ARRAY)) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if ("boost".equals(currentFieldName)) {
                boost = parser.floatValue();
            } else {
                throw new QueryParsingException(parseContext, "[match_all] query does not support [" + currentFieldName + "]");
            }
        }
    }

    if (boost == 1.0f) {
        return Queries.newMatchAllQuery();
    }

    MatchAllDocsQuery query = new MatchAllDocsQuery();
    query.setBoost(boost);
    return query;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:29,代码来源:MatchAllQueryParser.java

示例7: parse

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

    float boost = 1.0f;
    ScoreMode scoreMode = ScoreMode.Avg;
    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 ("query".equals(currentFieldName)) {
                builder.query();
            } else if (parseContext.parseFieldMatcher().match(currentFieldName, FILTER_FIELD)) {
                builder.filter();
            } else if ("inner_hits".equals(currentFieldName)) {
                builder.setInnerHits(innerHitsQueryParserHelper.parse(parseContext));
            } else {
                throw new QueryParsingException(parseContext, "[nested] query does not support [" + currentFieldName + "]");
            }
        } else if (token.isValue()) {
            if ("path".equals(currentFieldName)) {
                builder.setPath(parser.text());
            } else if ("boost".equals(currentFieldName)) {
                boost = parser.floatValue();
            } else if ("score_mode".equals(currentFieldName) || "scoreMode".equals(currentFieldName)) {
                String sScoreMode = parser.text();
                if ("avg".equals(sScoreMode)) {
                    scoreMode = ScoreMode.Avg;
                } else if ("min".equals(sScoreMode)) {
                    scoreMode = ScoreMode.Min;
                } else if ("max".equals(sScoreMode)) {
                    scoreMode = ScoreMode.Max;
                } else if ("total".equals(sScoreMode) || "sum".equals(sScoreMode)) {
                    scoreMode = ScoreMode.Total;
                } else if ("none".equals(sScoreMode)) {
                    scoreMode = ScoreMode.None;
                } else {
                    throw new QueryParsingException(parseContext, "illegal score_mode for nested query [" + sScoreMode + "]");
                }
            } else if ("_name".equals(currentFieldName)) {
                queryName = parser.text();
            } else {
                throw new QueryParsingException(parseContext, "[nested] query does not support [" + currentFieldName + "]");
            }
        }
    }

    builder.setScoreMode(scoreMode);
    ToParentBlockJoinQuery joinQuery = builder.build();
    if (joinQuery != null) {
        joinQuery.setBoost(boost);
        if (queryName != null) {
            parseContext.addNamedQuery(queryName, joinQuery);
        }
    }
    return joinQuery;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:63,代码来源:NestedQueryParser.java

示例8: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static ParentIdQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
    XContentParser parser = parseContext.parser();
    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    String type = null;
    String id = null;
    String queryName = null;
    String currentFieldName = 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.isValue()) {
            if (TYPE_FIELD.match(currentFieldName)) {
                type = parser.text();
            } else if (ID_FIELD.match(currentFieldName)) {
                id = parser.text();
            } else if (IGNORE_UNMAPPED_FIELD.match(currentFieldName)) {
                ignoreUnmapped = parser.booleanValue();
            } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
                boost = parser.floatValue();
            } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
                queryName = parser.text();
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[parent_id] query does not support [" + currentFieldName + "]");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "[parent_id] query does not support [" + currentFieldName + "]");
        }
    }
    ParentIdQueryBuilder queryBuilder = new ParentIdQueryBuilder(type, id);
    queryBuilder.queryName(queryName);
    queryBuilder.boost(boost);
    queryBuilder.ignoreUnmapped(ignoreUnmapped);
    return queryBuilder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:ParentIdQueryBuilder.java

示例9: parse

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

    String currentFieldName = null;
    String field = null;
    float boostFactor = 1;
    FieldValueFactorFunction.Modifier modifier = FieldValueFactorFunction.Modifier.NONE;
    Double missing = null;
    XContentParser.Token token;
    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)) {
                field = parser.text();
            } else if ("factor".equals(currentFieldName)) {
                boostFactor = parser.floatValue();
            } else if ("modifier".equals(currentFieldName)) {
                modifier = FieldValueFactorFunction.Modifier.valueOf(parser.text().toUpperCase(Locale.ROOT));
            } else if ("missing".equals(currentFieldName)) {
                missing = parser.doubleValue();
            } else {
                throw new QueryParsingException(parseContext, NAMES[0] + " query does not support [" + currentFieldName + "]");
            }
        } else if("factor".equals(currentFieldName) && (token == XContentParser.Token.START_ARRAY || token == XContentParser.Token.START_OBJECT)) {
            throw new QueryParsingException(parseContext, "[" + NAMES[0] + "] field 'factor' does not support lists or objects");
        }
    }

    if (field == null) {
        throw new QueryParsingException(parseContext, "[" + NAMES[0] + "] required field 'field' missing");
    }

    SearchContext searchContext = SearchContext.current();
    MappedFieldType fieldType = searchContext.mapperService().smartNameFieldType(field);
    IndexNumericFieldData fieldData = null;
    if (fieldType == null) {
        if(missing == null) {
            throw new ElasticsearchException("Unable to find a field mapper for field [" + field + "]. No 'missing' value defined.");
        }
    } else {
        fieldData = searchContext.fieldData().getForField(fieldType);
    }
    return new FieldValueFactorFunction(field, boostFactor, modifier, missing, fieldData);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:46,代码来源:FieldValueFactorFunctionParser.java

示例10: fromXContent

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

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

    List<SpanQueryBuilder> clauses = new ArrayList<>();

    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_ARRAY) {
            if (CLAUSES_FIELD.match(currentFieldName)) {
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    QueryBuilder query = parseContext.parseInnerQueryBuilder();
                    if (query instanceof SpanQueryBuilder == false) {
                        throw new ParsingException(parser.getTokenLocation(), "spanOr [clauses] must be of type span query");
                    }
                    clauses.add((SpanQueryBuilder) query);
                }
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[span_or] query does not support [" + currentFieldName + "]");
            }
        } else {
            if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
                boost = parser.floatValue();
            } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
                queryName = parser.text();
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[span_or] query does not support [" + currentFieldName + "]");
            }
        }
    }

    if (clauses.isEmpty()) {
        throw new ParsingException(parser.getTokenLocation(), "spanOr must include [clauses]");
    }

    SpanOrQueryBuilder queryBuilder = new SpanOrQueryBuilder(clauses.get(0));
    for (int i = 1; i < clauses.size(); i++) {
        queryBuilder.addClause(clauses.get(i));
    }
    queryBuilder.boost(boost);
    queryBuilder.queryName(queryName);
    return queryBuilder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:49,代码来源:SpanOrQueryBuilder.java

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

示例12: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static MatchPhrasePrefixQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException {
    XContentParser parser = parseContext.parser();
    String fieldName = null;
    Object value = null;
    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    String analyzer = null;
    int slop = MatchQuery.DEFAULT_PHRASE_SLOP;
    int maxExpansion = FuzzyQuery.defaultMaxExpansions;
    String queryName = 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 (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 (token.isValue()) {
                    if (MatchQueryBuilder.QUERY_FIELD.match(currentFieldName)) {
                        value = parser.objectText();
                    } else if (MatchQueryBuilder.ANALYZER_FIELD.match(currentFieldName)) {
                        analyzer = parser.text();
                    } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
                        boost = parser.floatValue();
                    } else if (MatchPhraseQueryBuilder.SLOP_FIELD.match(currentFieldName)) {
                        slop = parser.intValue();
                    } else if (MAX_EXPANSIONS_FIELD.match(currentFieldName)) {
                        maxExpansion = parser.intValue();
                    } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
                        queryName = parser.text();
                    } else {
                        throw new ParsingException(parser.getTokenLocation(),
                                "[" + NAME + "] query does not support [" + currentFieldName + "]");
                    }
                } else {
                    throw new ParsingException(parser.getTokenLocation(),
                            "[" + NAME + "] unknown token [" + token + "] after [" + currentFieldName + "]");
                }
            }
        } else {
            throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
            fieldName = parser.currentName();
            value = parser.objectText();
        }
    }

    MatchPhrasePrefixQueryBuilder matchQuery = new MatchPhrasePrefixQueryBuilder(fieldName, value);
    matchQuery.analyzer(analyzer);
    matchQuery.slop(slop);
    matchQuery.maxExpansions(maxExpansion);
    matchQuery.queryName(queryName);
    matchQuery.boost(boost);
    return matchQuery;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:60,代码来源:MatchPhrasePrefixQueryBuilder.java

示例13: fromXContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public static SpanTermQueryBuilder fromXContent(QueryParseContext parseContext) throws IOException, ParsingException {
    XContentParser parser = parseContext.parser();
    String fieldName = null;
    Object 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 (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 (BaseTermQueryBuilder.VALUE_FIELD.match(currentFieldName)) {
                        value = parser.objectBytes();
                    } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
                        boost = parser.floatValue();
                    } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
                        queryName = parser.text();
                    } else {
                        throw new ParsingException(parser.getTokenLocation(),
                                "[span_term] query does not support [" + currentFieldName + "]");
                    }
                }
            }
        } else {
            throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
            fieldName = parser.currentName();
            value = parser.objectBytes();
        }
    }

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

示例14: fromXContent

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

    String fieldName = null;
    List<Object> values = null;
    TermsLookup termsLookup = 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 (parseContext.isDeprecatedSetting(currentFieldName)) {
            // skip
        } else if (token == XContentParser.Token.START_ARRAY) {
            if  (fieldName != null) {
                throw new ParsingException(parser.getTokenLocation(),
                        "[" + TermsQueryBuilder.NAME + "] query does not support multiple fields");
            }
            fieldName = currentFieldName;
            values = parseValues(parser);
        } else if (token == XContentParser.Token.START_OBJECT) {
            if  (fieldName != null) {
                throw new ParsingException(parser.getTokenLocation(),
                        "[" + TermsQueryBuilder.NAME + "] query does not support more than one field. "
                        + "Already got: [" + fieldName + "] but also found [" + currentFieldName +"]");
            }
            fieldName = currentFieldName;
            termsLookup = TermsLookup.parseTermsLookup(parser);
        } else if (token.isValue()) {
            if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
                boost = parser.floatValue();
            } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
                queryName = parser.text();
            } else {
                throw new ParsingException(parser.getTokenLocation(),
                        "[" + TermsQueryBuilder.NAME + "] query does not support [" + currentFieldName + "]");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(),
                    "[" + TermsQueryBuilder.NAME + "] unknown token [" + token + "] after [" + currentFieldName + "]");
        }
    }

    if (fieldName == null) {
        throw new ParsingException(parser.getTokenLocation(), "[" + TermsQueryBuilder.NAME + "] query requires a field name, " +
                "followed by array of terms or a document lookup specification");
    }
    return new TermsQueryBuilder(fieldName, values, termsLookup)
            .boost(boost)
            .queryName(queryName);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:56,代码来源:TermsQueryBuilder.java

示例15: fromXContent

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

    QueryBuilder query = null;
    boolean queryFound = false;
    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) {
            if (INNER_QUERY_FIELD.match(currentFieldName)) {
                if (queryFound) {
                    throw new ParsingException(parser.getTokenLocation(), "[" + ConstantScoreQueryBuilder.NAME + "]"
                            + " accepts only one 'filter' element.");
                }
                query = parseContext.parseInnerQueryBuilder();
                queryFound = true;
            } else {
                throw new ParsingException(parser.getTokenLocation(),
                        "[constant_score] query does not support [" + currentFieldName + "]");
            }
        } else if (token.isValue()) {
            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(),
                        "[constant_score] query does not support [" + currentFieldName + "]");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "unexpected token [" + token + "]");
        }
    }
    if (!queryFound) {
        throw new ParsingException(parser.getTokenLocation(), "[constant_score] requires a 'filter' element");
    }

    ConstantScoreQueryBuilder constantScoreBuilder = new ConstantScoreQueryBuilder(query);
    constantScoreBuilder.boost(boost);
    constantScoreBuilder.queryName(queryName);
    return constantScoreBuilder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:50,代码来源:ConstantScoreQueryBuilder.java


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