private static Result insertQuery(Query query, ParserEnvironment env) {
        YqlParser parser = (YqlParser) ParserFactory.newInstance(Query.Type.YQL, env);
        parser.setQueryParser(false);
        parser.setUserQuery(query);
        QueryTree newTree;
        try {
            Parsable parsable = Parsable.fromQueryModel(query.getModel()).setQuery(query.properties().getString(YQL));
            newTree = parser.parse(parsable);
        } catch (RuntimeException e) {
            return new Result(query, ErrorMessage.createInvalidQueryParameter("Could not create query from YQL: " +
                                                                              Exceptions.toMessageString(e),
                                                                              e));
        }
        if (parser.getOffset() != null) {
            int maxHits = query.properties().getInteger(MAX_HITS);
            int maxOffset = query.properties().getInteger(MAX_OFFSET);
            if (parser.getOffset() > maxOffset) {
                return new Result(query,
                                  ErrorMessage.createInvalidQueryParameter("Requested offset " + parser.getOffset() +
                                                                           ", but the max offset allowed is " +
                                                                           maxOffset + "."));
            }
            if (parser.getHits() > maxHits) {
                return new Result(query,
                                  ErrorMessage.createInvalidQueryParameter("Requested " + parser.getHits() +
                                                                           " hits returned, but max hits allowed is " +
                                                                           maxHits + "."));
            }
        }
        query.getModel().getQueryTree(false).setRoot(newTree.getRoot());
        query.getPresentation().getSummaryFields().addAll(parser.getYqlSummaryFields());

        GroupingQueryParser.validate(query);
        for (VespaGroupingStep step : parser.getGroupingSteps())
            GroupingQueryParser.createGroupingRequestIn(query, step.getOperation(), step.continuations());

        if (parser.getYqlSources().isEmpty()) {
            query.getModel().getSources().clear();
        } else {
            query.getModel().getSources().addAll(parser.getYqlSources());
        }
        if (parser.getOffset() != null) {
            query.setOffset(parser.getOffset());
            query.setHits(parser.getHits());
        }
        if (parser.getTimeout() != null) {
            query.setTimeout(parser.getTimeout().longValue());
        }
        if (parser.getSorting() != null) {
            query.getRanking().setSorting(parser.getSorting());
        }
        query.trace("YQL query parsed", true, 2);

        if (query.getModel().getFilter() != null && query.getModel().getQueryString() == null) {
            query.errors().add(ErrorMessage.createInvalidQueryParameter(
                    "Filter can only be combined with query string. " +
                            "See https://docs.vespa.ai/en/reference/query-api-reference.html#model.filter"));
        }
        return null;
    }
Minimal combinator for YQL+ syntax and heuristically parsed user queries.

@author Steinar Knutsen
container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java