private static void doFind()

in mr/src/main/java/org/elasticsearch/hadoop/serialization/ParsingUtils.java [161:228]


    private static void doFind(Parser parser, List<Matcher> currentMatchers, int level, int maxNesting) {
        Token token = parser.currentToken();
        if (token == null) {
            // advance to the initial START_OBJECT token
            parser.nextToken();
        }

        while ((token = parser.nextToken()) != null && token != Token.END_OBJECT) {
            if (token == Token.FIELD_NAME) {
                String currentName = parser.currentName();
                Object value = null;
                boolean valueRead = false;
                List<Matcher> nextLevel = null;

                for (Matcher matcher : currentMatchers) {
                    if (matcher.matches(currentName, level)) {
                        // found a match
                        if (matcher.nesting() == level) {
                            if (!valueRead) {
                                valueRead = true;
                                switch (parser.nextToken()) {
                                case VALUE_NUMBER:
                                    value = parser.numberValue();
                                    break;
                                case VALUE_BOOLEAN:
                                    value = Boolean.valueOf(parser.booleanValue());
                                    break;
                                case VALUE_NULL:
                                    value = null;
                                    break;
                                case VALUE_STRING:
                                    value = parser.text();
                                    break;
                                default:
                                    value = new RawJson(readValueAsString(parser));
                                }
                            }
                            matcher.value(value);
                        }
                        // partial match - keep it for the next level
                        else {
                            if (nextLevel == null) {
                                nextLevel = new ArrayList<Matcher>(currentMatchers.size());
                            }
                            nextLevel.add(matcher);
                        }
                    }
                }

                if (!valueRead) {
                    // must parse or skip the value
                    switch (parser.nextToken()) {
                        case START_OBJECT:
                            if (level < maxNesting && nextLevel != null) {
                                doFind(parser, nextLevel, level + 1, maxNesting);
                            } else {
                                parser.skipChildren();
                            }
                            break;
                        case START_ARRAY:
                            // arrays are not handled; simply ignore
                            parser.skipChildren();
                            break;
                    }
                }
            }
        }
    }