private Item handleAdvancedOperator(Item topLevelItem, Item item, boolean topLevelIsClosed) {
        if (isTheWord("and", item)) {
            if (topLevelIsClosed || !(topLevelItem instanceof AndItem)) {
                AndItem and = new AndItem();

                and.addItem(topLevelItem);
                return and;
            }
            return topLevelItem;
        } else if (isTheWord("or", item)) {
            if (topLevelIsClosed || !(topLevelItem instanceof OrItem)) {
                OrItem or = new OrItem();

                or.addItem(topLevelItem);
                return or;
            }
            return topLevelItem;
        } else if (isTheWord("equiv", item)) {
            if (topLevelIsClosed || !(topLevelItem instanceof EquivItem)) {
                EquivItem equiv = new EquivItem();

                equiv.addItem(topLevelItem);
                return equiv;
            }
            return topLevelItem;
        } else if (isTheWord("wand", item) || isTheWord("weakand", item)) {
            int n = consumeNumericArgument();
            if (topLevelIsClosed || needWeakAnd(topLevelItem, n)) {
                WeakAndItem wand = new WeakAndItem();
                if (n != 0) {
                    wand.setN(n);
                }
                wand.addItem(topLevelItem);
                return wand;
            }
            return topLevelItem;
        } else if (isTheWord("andnot", item)) {
            if (topLevelIsClosed || !(topLevelItem instanceof NotItem)) {
                NotItem not = new NotItem();

                not.addPositiveItem(topLevelItem);
                return not;
            }
            return topLevelItem;
        } else if (isTheWord("rank", item)) {
            if (topLevelIsClosed || !(topLevelItem instanceof RankItem)) {
                RankItem rank = new RankItem();

                rank.addItem(topLevelItem);
                return rank;
            }
            return topLevelItem;
        } else if (isTheWord("near", item)) {
            int distance = consumeNumericArgument();
            if (distance==0)
                distance=NearItem.defaultDistance;
            if (topLevelIsClosed || !(topLevelItem instanceof NearItem) || distance != ((NearItem)topLevelItem).getDistance()) {
                NearItem near = new NearItem(distance);

                near.addItem(topLevelItem);
                return near;
            }
            return topLevelItem;
        } else if (isTheWord("onear", item)) {
            int distance = consumeNumericArgument();
            if (distance==0)
                distance= ONearItem.defaultDistance;
            if (topLevelIsClosed || !(topLevelItem instanceof ONearItem) || distance!=((ONearItem)topLevelItem).getDistance()) {
                ONearItem oNear = new ONearItem(distance);

                oNear.addItem(topLevelItem);
                return oNear;
            }
            return topLevelItem;
        }

        return null;
    }
Returns the new top level, or null if the current item is not an operator
container-search/src/main/java/com/yahoo/prelude/query/parser/AdvancedParser.java