Hello,
this is the function that queries the search for the media, it seems to search for
https://developer.wordpress.org/reference/functions/wp_ajax_query_attachments/
It takes all these things and searches for your query in there, some things in there are probably not interesting to you but I think the labels are what you are looking for:
stdClass Object (
[hierarchical] =>
[update_count_callback] =>
[rewrite] =>
[query_var] =>
[public] =>
[show_ui] =>
[show_tagcloud] =>
[_builtin] =>
[labels] => stdClass Object (
[name] =>
[singular_name] =>
[search_items] =>
[popular_items] =>
[all_items] =>
[parent_item] =>
[parent_item_colon] =>
[edit_item] =>
[view_item] =>
[update_item] =>
[add_new_item] =>
[new_item_name] =>
[separate_items_with_commas] =>
[add_or_remove_items] =>
[choose_from_most_used] =>
[menu_name] =>
[name_admin_bar] => )
[show_in_nav_menus] =>
[cap] => stdClass Object (
[manage_terms] =>
[edit_terms] =>
[delete_terms] =>
[assign_terms] => )
[name] =>
[object_type] => Array ()
[label] )
The relevant WHERE clause from searching for media items with “test” looks like this:
(((wp_posts.post_title LIKE '%test%')
OR (wp_posts.post_excerpt LIKE '%test%')
OR (wp_posts.post_content LIKE '%test%')
OR (sq1.meta_value LIKE '%test%')))
If the search term is not in one of those items, the media item will not be found. Note that sq1.meta_value could possibly cover a lot of information.
So if I understand this correctly, the search function in the Media Library does not search any of the document/image fields like alt text, caption or description?
The field ‘post_content’ noted in the comment above yours corresponds to the ‘description’ field of the document/image, and ‘post_excerpt’ corresponds to caption field