diff --git src/wp-includes/class-wp-query.php src/wp-includes/class-wp-query.php
index 9590406..a6cd1c2 100644
--- src/wp-includes/class-wp-query.php
+++ src/wp-includes/class-wp-query.php
@@ -1341,7 +1341,14 @@ class WP_Query {
 			}
 
 			$like = $n . $this->db->esc_like( $term ) . $n;
-			$search .= $this->db->prepare( "{$searchand}(({$this->db->posts}.post_title $like_op %s) $andor_op ({$this->db->posts}.post_excerpt $like_op %s) $andor_op ({$this->db->posts}.post_content $like_op %s))", $like, $like, $like );
+
+			// If this is a search for attachments, inlcude the filename in the search.
+			if ( 'attachment' === $q['post_type'] ) {
+				$search .= $this->db->prepare( "{$searchand}(({$this->db->posts}.post_title $like_op %s) $andor_op ({$this->db->posts}.post_excerpt $like_op %s) $andor_op ({$this->db->posts}.post_content $like_op %s) $andor_op ({$this->db->postmeta}.meta_key = '_wp_attached_file' AND {$this->db->postmeta}.meta_value $like_op %s))", $like, $like, $like, $like );
+			} else {
+				$search .= $this->db->prepare( "{$searchand}(({$this->db->posts}.post_title $like_op %s) $andor_op ({$this->db->posts}.post_excerpt $like_op %s) $andor_op ({$this->db->posts}.post_content $like_op %s))", $like, $like, $like );
+			}
+
 			$searchand = ' AND ';
 		}
 
@@ -2068,7 +2075,7 @@ class WP_Query {
 			}
 		}
 
-		if ( !empty( $this->tax_query->queries ) || !empty( $this->meta_query->queries ) ) {
+		if ( ! empty( $this->tax_query->queries ) || ! empty( $this->meta_query->queries ) || ( $this->is_search && 'attachment' === $q[ 'post_type' ] ) ) {
 			$groupby = "{$this->db->posts}.ID";
 		}
 
@@ -2117,6 +2124,11 @@ class WP_Query {
 		}
 		$where .= $search . $whichauthor . $whichmimetype;
 
+		// Modify the JOIN clause for attachment searches.
+		if ( $this->is_search && 'attachment' === $q[ 'post_type' ] ) {
+			$join .= " INNER JOIN {$this->db->postmeta} ON ( {$this->db->posts}.ID = {$this->db->postmeta}.post_id )";
+		}
+
 		if ( ! empty( $this->meta_query->queries ) ) {
 			$clauses = $this->meta_query->get_sql( 'post', $this->db->posts, 'ID', $this );
 			$join   .= $clauses['join'];
