private int findPhrasesAtStartpoint(int startIndex,CompositeItem owner,MatchedPhrases phrases) {
        FSA.State state = phraseFSA.getState();
        int currentIndex=startIndex;
        Phrase phrase=null;
        List<String> replaceList=null;

        String index=null;
        state.start();

        while (currentIndex<owner.getItemCount()) { // Loop until the largest possible phrase is passed
            Item current=owner.getItem(currentIndex);
            if (! (current instanceof TermItem) ) break;

            TermItem termItem=(TermItem)current;

            if (state.isStartState())
                index=termItem.getIndexName();
            else
                if (!termItem.getIndexName().equals(index)) break;

            String lowercased = toLowerCase(termItem.stringValue());
            boolean matched=state.tryDeltaWord(lowercased);
            if (!matched && ignorePluralForm) {
                String invertedWord=switchForm(lowercased);
                matched=state.tryDeltaWord(invertedWord);
                if (matched)
                    replaceList=setReplace(replaceList,currentIndex-startIndex,invertedWord);
            }
            if (!matched) break;

            if (state.isFinal()) // Legal return point reached, but we'll look for longer ones too
                phrase=new Phrase(owner,replaceList,startIndex,currentIndex-startIndex+1,state.dataString());
            if (matchAll)
                phrases.add(phrase);
            currentIndex++;
        }

        if (phrase==null) return 0;
        if (!matchAll)
            phrases.add(phrase);
        return phrase.getLength();
    }
If (!matchAll), finds longest possible phrase starting at the
given index in the owner and adds it to phrases.

If (matchAll), finds all possible phrases starting at the given index

@return the length of the largest phrase found at this starting point, or 0 if none
container-search/src/main/java/com/yahoo/prelude/querytransform/PhraseMatcher.java