int getNumTerms(Item rootNode) {
        int numTerms = 0;

        if (rootNode == null) {
            return 0;
        } else if (rootNode instanceof CompositeItem) {
            CompositeItem composite = (CompositeItem) rootNode;

            for (Iterator<Item> i = composite.getItemIterator(); i.hasNext();) {
                numTerms += getNumTerms(i.next());
            }
        } else if (rootNode instanceof TermItem) {
            return 1;
        } else {
            return 0;
        }
        return numTerms;
    }
Traverse the query tree and return total number of terms
container-search/src/main/java/com/yahoo/prelude/query/ItemHelper.java