if ( !Collections.disjoint( stringEncodedFieldNames, fieldCollection.getNumericFieldNames() ) ) { Set<String> invalidFields = new HashSet<>(); for ( String numericField : fieldCollection.getNumericFieldNames() ) { if ( stringEncodedFieldNames.contains( numericField ) ) { invalidFields.add( numericField ); if ( !Collections.disjoint( numericEncodedFieldNames, fieldCollection.getStringFieldNames() ) ) { Set<String> invalidFields = new HashSet<>(); for ( String stringField : fieldCollection.getStringFieldNames() ) { if ( numericEncodedFieldNames.contains( stringField ) ) { invalidFields.add( stringField );
if ( !Collections.disjoint( stringEncodedFieldNames, fieldCollection.getNumericFieldNames() ) ) { Set<String> invalidFields = new HashSet<>(); for ( String numericField : fieldCollection.getNumericFieldNames() ) { if ( stringEncodedFieldNames.contains( numericField ) ) { invalidFields.add( numericField ); if ( !Collections.disjoint( numericEncodedFieldNames, fieldCollection.getStringFieldNames() ) ) { Set<String> invalidFields = new HashSet<>(); for ( String stringField : fieldCollection.getStringFieldNames() ) { if ( numericEncodedFieldNames.contains( stringField ) ) { invalidFields.add( stringField );
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; }
private void assertFieldNames(Query query, FieldType fieldType, String... expectedFields) { FieldNameCollector.FieldCollection fieldCollection = FieldNameCollector.extractFieldNames( query ); Set<String> actualFieldNames = new HashSet<>(); if ( FieldType.STRING.equals( fieldType ) ) { actualFieldNames.addAll( fieldCollection.getStringFieldNames() ); } else { actualFieldNames.addAll( fieldCollection.getNumericFieldNames() ); } for ( String expectedFieldName : expectedFields ) { if ( !actualFieldNames.contains( expectedFieldName ) ) { fail( "The expected field name " + expectedFieldName + " was not found in the actual field names: " + actualFieldNames ); } actualFieldNames.remove( expectedFieldName ); } if ( !actualFieldNames.isEmpty() ) { fail( "There were field names which were unexpected: " + actualFieldNames ); } }