private void repeatedConsecutiveTermsInPhraseCheck(PhraseItem phrase) {
        if (phrase.getItemCount() > MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE) {
            String prev = null;
            int repeatedCount = 0;
            for (int i = 0; i < phrase.getItemCount(); ++i) {
                Item item = phrase.getItem(i);
                if (item instanceof TermItem term) {
                    String current = term.getIndexedString();
                    if (prev != null) {
                        if (prev.equals(current)) {
                            repeatedCount++;
                            if (repeatedCount >= MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE) {
                                repeatedConsecutiveTermsInPhraseRejections.add();
                                throw new IllegalInputException("More than " + MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE +
                                                                " occurrences of term '" + current +
                                                                "' in a row detected in phrase : " + phrase.toString());
                            }
                        } else {
                            repeatedCount = 0;
                        }
                    }
                    prev = current;
                } else {
                    prev = null;
                    repeatedCount = 0;
                }
            }
        }
    }
Check whether the query tree seems to be "well formed". In other words, run heuristics against
the input data to see whether the query should sent to the search backend.

@author Steinar Knutsen
container-search/src/main/java/com/yahoo/search/searchers/InputCheckingSearcher.java