private Item advancedItemsBody(boolean topLevel) {
        Item topLevelItem = null;
        Item item;
        boolean itemIsComposite;
        boolean topLevelIsClosed = false;
        boolean expectingOperator = false;

        do {
            item = indexableItem("").getFirst();
            if (item == null) {
                item = compositeItem();
                itemIsComposite = true;
            } else {
                itemIsComposite = false;
            }
            if (item != null) {
                Item newTop = null;

                if (expectingOperator) {
                    newTop = handleAdvancedOperator(topLevelItem, item, topLevelIsClosed);
                }
                if (newTop != null) { // Operator found
                    topLevelIsClosed = false;
                    expectingOperator = false;
                    topLevelItem = newTop;
                } else if (topLevelItem == null) {
                    topLevelItem = item;
                    if (itemIsComposite) {
                        topLevelIsClosed = true;
                    }
                    expectingOperator = true;
                } else if (topLevelItem instanceof CompositeItem && !(topLevelItem instanceof SegmentItem)) {
                    ((CompositeItem) topLevelItem).addItem(item);
                    expectingOperator = true;
                } else {
                    AndItem and = new AndItem();

                    and.addItem(topLevelItem);
                    and.addItem(item);
                    topLevelItem = and;
                    topLevelIsClosed = false;
                    expectingOperator = true;
                }
            }

            if (topLevel && item == null) {
                tokens.skip();
            }
        } while (tokens.hasNext() && (topLevel || item != null));

        // Optimize away composites containing one item only
        // (including nots with only a positive)
        if (topLevelItem instanceof CompositeItem
                && ((CompositeItem) topLevelItem).getItemCount() == 1) {
            return ((CompositeItem) topLevelItem).removeItem(0);
        }

        return topLevelItem;
    }
A collection of one or more advanced items.
container-search/src/main/java/com/yahoo/prelude/query/parser/AdvancedParser.java