private Item addAndFilter(Item root, Item item) {
        if (item == null) {
            return root;
        }

        if (root instanceof AndItem) {
            ((AndItem) root).addItem(item);
            return root;
        }

        if (root instanceof RankItem) {
            Item firstChild = ((RankItem) root).getItem(0);

            if (firstChild instanceof AndItem) {
                ((AndItem) firstChild).addItem(item);
                return root;
            } else if (firstChild instanceof NotItem) {
                ((NotItem) firstChild).addPositiveItem(item);
                return root;
            }
        }

        AndItem and = new AndItem();

        and.addItem(root);
        and.addItem(item);
        return and;
    }
Returns the top level item resulting from combining the given top
level item and the new item. This implements most of the weird transformation
rules of the parser.
container-search/src/main/java/com/yahoo/prelude/query/parser/AnyParser.java