Tips for Google CSE plugin for Drupal


If you've decided to use the Google Custom Search Engine (CSE) plugin for Drupal, there are a few things you can do to make life easier for your visitors:

  • Add some rewrite rules (to the .htaccess file) to redirect requests for the old search engine to the new one. This can help visitors who know how Drupal works and were typing their search manually, etc.
    • RewriteRule ^search$ /search/google [R=301,NC,L]
    • RewriteRule ^search/node$ /search/google [R=301,NC,L]
    • RewriteRule ^search/node/(.*)$ /search/google?query=$1 [R=301,NC,L]
    • RewriteRule ^search/taxonomy_search$ /search/google [R=301,NC,L]
    • RewriteRule ^search/taxonomy_search/(.*)$ /search/google?query=$1 [R=301,NC,L]
  • Disable the built-in search engine module to reduce memory overhead and speed up page requests.
  • Use some CSS to hide the background image added to the search boxes:
    • input.form-text {
    • background-image: none !important;
    • }
  • If you have custom search boxes replace them with code that calls the Google CSE engine, i.e.:
    • <?php print drupal_get_form('google_cse_searchbox_form');?>

Put together this can make the GoogleCSE almost(*) completely transparent to your visitors.

* Note: I'm not sure if it's a feature or a bug, but I'm going to go with the latter - all search result pages for GoogleCSE append a great deal of information to the URL instead of just submitting these fields transparently via the API call. This is obviously not very user friendly for advanced users who can normally just go to e.g. /search/node/doodlebutt to search for "doodlebutt", or for occasions when you're doing tricks on the search engine, instead when visitors do this they're just putting their search term into the search box and will have to click the Search box to see any results.

How to reply

Care to add your own 2 cents? Let me know via Twitter or my contact page.