@Override
    public Item setItem(int index, Item item) {
        if (item instanceof WordItem || item instanceof PhraseSegmentItem) {
            return setIndexedItem(index, (IndexedItem) item);
        } else if (item instanceof IntItem) {
            return setIndexedItem(index, convertIntToWord(item));
        } else if (item instanceof PhraseItem phrase) {
            Iterator<Item> i = phrase.getItemIterator();
            // we assume we don't try to add empty phrases
            IndexedItem firstItem = (IndexedItem) i.next();
            Item toReturn = setIndexedItem(index++, firstItem);

            while (i.hasNext()) {
                addIndexedItem(index++, (IndexedItem) i.next());
            }
            return toReturn;
        } else {
            throw new IllegalArgumentException("Can not add " + item + " to a phrase");
        }
    }
Adds subitem. The word will have its index name set to the index name of
this phrase. If the item is a word, it will simply be added, if the item
is a phrase, each of the words of the phrase will be added.

@throws IllegalArgumentException if the given item is not a WordItem or PhraseItem
container-search/src/main/java/com/yahoo/prelude/query/PhraseItem.java