private void repeatedTermsInPhraseCheck(PhraseItem phrase) {
        if (phrase.getItemCount() > MAX_REPEATED_TERMS_IN_PHRASE) {
            Map<String, Count> repeatedCount = new HashMap<>();
            for (int i = 0; i < phrase.getItemCount(); ++i) {
                Item item = phrase.getItem(i);
                if (item instanceof TermItem term) {
                    String current = term.getIndexedString();
                    Count count = repeatedCount.get(current);
                    if (count != null) {
                        if (count.get() >= MAX_REPEATED_TERMS_IN_PHRASE) {
                            repeatedTermsInPhraseRejections.add();
                            throw new IllegalInputException("Phrase contains more than " + MAX_REPEATED_TERMS_IN_PHRASE +
                                                            " occurrences of term '" + current + "' in phrase : " + phrase.toString());
                        }
                        count.inc();
                    } else {
                        repeatedCount.put(current, new Count(1));
                    }
                }
            }
        }
    }
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