You can add a filter to your functions.php file that sets parameters before posts are requested from the database. However, setting posts to -1 is generally not a good idea, especially for search for results. If you have a significant amount of posts, you could crash your site. Ideally you should set a high number (500?) and paginate from there.
You can read more about that here:
https://10up.github.io/Engineering-Best-Practices/php/#performance
If you’re using a free or purchased theme, make sure you create a child theme.
function search_filter($query) {
// make sure we're not on the admin and we are in the main query
if ( !is_admin() && $query->is_main_query() ) {
// only set the post parameter if we're searching for posts
if ($query->is_search) {
$query->set('posts_per_page', -1);
}
}
}
add_action('pre_get_posts','search_filter');