I have an interface that enforces implementing classes to define and implement a function that returns an `org.apache.lucene.search.Query`. These classes create various queries like `TermQuery`, `PhraseQuery`, etc. Is it possible to take the `org.apache.lucene.search.Query` that gets returned and iterate over all of the queries and terms it's comprised of?

```java
public interface BaseQuery {

    public Query getQuery();

    default Query toQuery() {
        Query query = getQuery();
        // iterate through Query and do things to each term
        return query;
    }
}

```

```java
public class ContainsQuery implements BaseQuery {

    @Override
    protected Query getQuery() {
        PhraseQuery.Builder queryBuilder = new PhraseQuery.Builder();
        queryBuilder.add(new Term("field", "value");
        return queryBuilder.build();
    }
}

```