I figured it out. You just need to create a function like this and add it to your functions.php in your child theme.
function attachments_search_the_excerpt( $excerpt ) {
if ( ! is_search() ) {
return $excerpt;
}
$id = get_the_ID();
if ( ! $id ) {
return $excerpt;
}
if(get_post_type($id) != 'attachment') {
return $excerpt;
}
$caption = wptexturize( get_post($id)->post_excerpt );
$image_url = wp_get_attachment_image_src( $id , 'full' );
$thumbnailURL = $image_url[0];
$image = aq_resize($thumbnailURL, 260, false);
if(empty($image)) { $image = $thumbnailURL; }
// compile output with thumbnail image
$output = "<div id='attachment_{$id}' class='wp-caption aligncenter' >";
$output .= "<img src='".esc_url($image)."' class='iconhover' style='display:block;'>";
$output .= "<p class='wp-caption-text'>$caption</p>";
$output .= "</div>";
return $output;
}
// hook our function to the filter
add_filter( 'the_excerpt', 'attachments_search_the_excerpt');
Then you have it ??