How to remove notice inside search.php when no results are found?

get_post() returns the post object to the loop. So when you look for its ->ID if no object is there you try to make php to look for ID of nothing, and it gives you the notice. Change post->ID for

    if( ! get_post() )