Prevent searches less than 4 characters

You can use the pattern attribute to ask for at least 3 characters:

<input pattern=".{3,}">

But if your database dies just because someone searches for a three letter word … you have other problems than search. Optimize your database instead, or find another solution. A simple search, even dozens per minute should not be a problem.

To catch empty searches, see my article on WPEngineer: Fix Empty Searches