public ParsedQuery parse(final String query) throws ParseException {
        final TokenCollectingQueryParser parser = new TokenCollectingQueryParser(ParsedTerm.DEFAULT_FIELD, ANALYZER);
        parser.setSplitOnWhitespace(true);
        parser.setAllowLeadingWildcard(allowLeadingWildcard);

        final Query parsed = parser.parse(query);
        final ParsedQuery.Builder builder = ParsedQuery.builder().query(query);

        builder.tokensBuilder().addAll(parser.getTokens());

        final TermCollectingQueryVisitor visitor = new TermCollectingQueryVisitor(ANALYZER, parser.getTokenLookup());
        parsed.visit(visitor);
        builder.termsBuilder().addAll(visitor.getParsedTerms());
        return builder.build();
    }
@Test
    void testRepeatedQuery() throws ParseException {
        final ParsedQuery parsedQuery = parser.parse("foo:bar AND foo:bar AND something:else");
        assertThat(parsedQuery.terms().size()).isEqualTo(3);
        assertThat(parsedQuery.terms())
                .filteredOn(parsedTerm -> parsedTerm.field().equals("foo"))
                .extracting(ParsedTerm::keyToken)
                .extracting(Optional::get)
                .hasSize(2)
                .satisfies(keyTokens -> assertThat(keyTokens.get(0)).isNotEqualTo(keyTokens.get(1)));
    }