Yeh this a common problem I've run into as well.
The issue is the entry variable only gets set when Craft is routing to an entry that's created in the CMS. Since you're routing directly to a template, Craft can't populate the variable.
I can think of a couple workarounds:
If your search form page is defined in the CMS, just grab that (or another page):