Using the drupal_set_message to give user feedback on a bad search is undesirable because of the way drupal handles these messages.
When using the following -
drupal_set_message( [message] , 'error');
Drupal sets that error message in $_SESSION['messages'] variable, so that it can be 'popped', and displayed the next time that user renders any page.
Consider the following scenario:
- The user clicks the search icon with no search query
- The user then clicks the 'about' page, before the search results page has loaded
Since the search results page did not render, Drupal prints the error message on the about page.
This has some potentially negative implications:
- The error message is now out of context and may cause confusion
- If Akamai caching is enabled, and no-one has visited the about us page, the error message is cached as part of that page
Because my setup is using akamai, the "Please enter some keywords" error is getting cached on numerous pages.
To temporarily get around this, I have had to add a checkbox to the search setting page to allow me to "Suppress errors on empty search".