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


Java XContentParser.isBooleanValue方法代码示例

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


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

示例1: buildFromContent

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
static void buildFromContent(XContentParser parser, AnalyzeRequest analyzeRequest)
        throws IOException {
    if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
        throw new IllegalArgumentException("Malformed content, must start with an object");
    } else {
        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 (Fields.TEXT.match(currentFieldName) && token == XContentParser.Token.VALUE_STRING) {
                analyzeRequest.text(parser.text());
            } else if (Fields.TEXT.match(currentFieldName) && token == XContentParser.Token.START_ARRAY) {
                List<String> texts = new ArrayList<>();
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    if (token.isValue() == false) {
                        throw new IllegalArgumentException(currentFieldName + " array element should only contain text");
                    }
                    texts.add(parser.text());
                }
                analyzeRequest.text(texts.toArray(new String[texts.size()]));
            } else if (Fields.ANALYZER.match(currentFieldName) && token == XContentParser.Token.VALUE_STRING) {
                analyzeRequest.analyzer(parser.text());
            } else if (Fields.FIELD.match(currentFieldName) && token == XContentParser.Token.VALUE_STRING) {
                analyzeRequest.field(parser.text());
            } else if (Fields.TOKENIZER.match(currentFieldName)) {
                if (token == XContentParser.Token.VALUE_STRING) {
                    analyzeRequest.tokenizer(parser.text());
                } else if (token == XContentParser.Token.START_OBJECT) {
                    analyzeRequest.tokenizer(parser.map());
                } else {
                    throw new IllegalArgumentException(currentFieldName + " should be tokenizer's name or setting");
                }
            } else if (Fields.TOKEN_FILTERS.match(currentFieldName)
                    && token == XContentParser.Token.START_ARRAY) {
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    if (token == XContentParser.Token.VALUE_STRING) {
                        analyzeRequest.addTokenFilter(parser.text());
                    } else if (token == XContentParser.Token.START_OBJECT) {
                        analyzeRequest.addTokenFilter(parser.map());
                    } else {
                        throw new IllegalArgumentException(currentFieldName
                                + " array element should contain filter's name or setting");
                    }
                }
            } else if (Fields.CHAR_FILTERS.match(currentFieldName)
                    && token == XContentParser.Token.START_ARRAY) {
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    if (token == XContentParser.Token.VALUE_STRING) {
                        analyzeRequest.addCharFilter(parser.text());
                    } else if (token == XContentParser.Token.START_OBJECT) {
                        analyzeRequest.addCharFilter(parser.map());
                    } else {
                        throw new IllegalArgumentException(currentFieldName
                                + " array element should contain char filter's name or setting");
                    }
                }
            } else if (Fields.EXPLAIN.match(currentFieldName)) {
                if (parser.isBooleanValue()) {
                    analyzeRequest.explain(parser.booleanValue());
                } else {
                    throw new IllegalArgumentException(currentFieldName + " must be either 'true' or 'false'");
                }
            } else if (Fields.ATTRIBUTES.match(currentFieldName) && token == XContentParser.Token.START_ARRAY) {
                List<String> attributes = new ArrayList<>();
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    if (token.isValue() == false) {
                        throw new IllegalArgumentException(currentFieldName + " array element should only contain attribute name");
                    }
                    attributes.add(parser.text());
                }
                analyzeRequest.attributes(attributes.toArray(new String[attributes.size()]));
            } else {
                throw new IllegalArgumentException("Unknown parameter ["
                        + currentFieldName + "] in request body or parameter is of the wrong type[" + token + "] ");
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:80,代码来源:RestAnalyzeAction.java

示例2: parse

import org.elasticsearch.common.xcontent.XContentParser; //导入方法依赖的package包/类
public FetchSourceContext parse(XContentParser parser) throws IOException {
    XContentParser.Token token;

    List<String> includes = null, excludes = null;
    String currentFieldName = null;
    token = parser.currentToken(); // we get it on the value
    if (parser.isBooleanValue()) {
        return new FetchSourceContext(parser.booleanValue());
    } else if (token == XContentParser.Token.VALUE_STRING) {
        return new FetchSourceContext(new String[]{parser.text()});
    } else if (token == XContentParser.Token.START_ARRAY) {
        includes = new ArrayList<>();
        while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
            includes.add(parser.text());
        }
    } else if (token == XContentParser.Token.START_OBJECT) {

        List<String> currentList = null;

        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token == XContentParser.Token.FIELD_NAME) {
                currentFieldName = parser.currentName();
                if ("includes".equals(currentFieldName) || "include".equals(currentFieldName)) {
                    currentList = includes != null ? includes : (includes = new ArrayList<>(2));
                } else if ("excludes".equals(currentFieldName) || "exclude".equals(currentFieldName)) {
                    currentList = excludes != null ? excludes : (excludes = new ArrayList<>(2));
                } else {
                    throw new ElasticsearchParseException("source definition may not contain [{}]", parser.text());
                }
            } else if (token == XContentParser.Token.START_ARRAY) {
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    currentList.add(parser.text());
                }
            } else if (token.isValue()) {
                currentList.add(parser.text());
            } else {
                throw new ElasticsearchParseException("unexpected token while parsing source settings");
            }
        }
    } else {
        throw new ElasticsearchParseException("source element value can be of type [{}]", token.name());
    }

    return new FetchSourceContext(
            includes == null ? Strings.EMPTY_ARRAY : includes.toArray(new String[includes.size()]),
            excludes == null ? Strings.EMPTY_ARRAY : excludes.toArray(new String[excludes.size()]));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:48,代码来源:FetchSourceParseElement.java


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