Search results page

For my search results page, I am using the default search capabilities in my WP site – no plugins. I have included items from the media library to be searchable:

function attachment_search( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array( 'post', 'attachment' ) );
$query->set( 'post_status', array( 'publish', 'inherit' ) );
}

return $query;
}

Is there a way I could exclude media types from the search results? I only want the pdfs in my media library to be searchable e.g. show up in the search results, excluding .png, jpg, gif etc

Thanks