public static FieldCollection extractFieldNames(Query query) { // first we need to find all composing queries since some query types are just containers Set<Query> composingQueries = new HashSet<>(); collectComposingQueries( query, composingQueries ); FieldCollection fieldCollection = new FieldCollection(); for ( Query composingQuery : composingQueries ) { if ( composingQuery instanceof NumericRangeQuery ) { fieldCollection.addNumericFieldName( ( (NumericRangeQuery) composingQuery ).getField() ); } else if ( composingQuery instanceof MultiTermQuery ) { fieldCollection.addStringFieldName( ( (MultiTermQuery) composingQuery ).getField() ); } else if ( composingQuery instanceof TermQuery ) { TermQuery termQuery = (TermQuery) composingQuery; fieldCollection.addStringFieldName( termQuery.getTerm().field() ); } else if ( composingQuery instanceof PhraseQuery ) { PhraseQuery phraseQuery = (PhraseQuery) composingQuery; // all terms must be against the same field, it's enough to look at the first fieldCollection.addStringFieldName( phraseQuery.getTerms()[0].field() ); } else if ( composingQuery instanceof MultiPhraseQuery ) { MultiPhraseQuery phraseQuery = (MultiPhraseQuery) composingQuery; // all terms must be against the same field, it's enough to look at the first fieldCollection.addStringFieldName( phraseQuery.getTermArrays().get( 0 )[0].field() ); } } return fieldCollection; }
public static FieldCollection extractFieldNames(Query query) { // first we need to find all composing queries since some query types are just containers Set<Query> composingQueries = new HashSet<>(); collectComposingQueries( query, composingQueries ); FieldCollection fieldCollection = new FieldCollection(); for ( Query composingQuery : composingQueries ) { if ( composingQuery instanceof NumericRangeQuery ) { fieldCollection.addNumericFieldName( ( (NumericRangeQuery) composingQuery ).getField() ); } else if ( composingQuery instanceof MultiTermQuery ) { fieldCollection.addStringFieldName( ( (MultiTermQuery) composingQuery ).getField() ); } else if ( composingQuery instanceof TermQuery ) { TermQuery termQuery = (TermQuery) composingQuery; fieldCollection.addStringFieldName( termQuery.getTerm().field() ); } else if ( composingQuery instanceof PhraseQuery ) { PhraseQuery phraseQuery = (PhraseQuery) composingQuery; // all terms must be against the same field, it's enough to look at the first fieldCollection.addStringFieldName( phraseQuery.getTerms()[0].field() ); } else if ( composingQuery instanceof MultiPhraseQuery ) { MultiPhraseQuery phraseQuery = (MultiPhraseQuery) composingQuery; // all terms must be against the same field, it's enough to look at the first fieldCollection.addStringFieldName( phraseQuery.getTermArrays().get( 0 )[0].field() ); } } return fieldCollection; }