Google Powered Search

Google Web

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Integrate Google Search on Drupal sites and generate revenue

Below is what I have done to integrate the adsense google search with the Drupal CMS.

  1. Add the rewrite rule to ".htaccess" file so the search query gets directed to the search page:
      RewriteCond %{QUERY_STRING} ^[^&]+)&.*$
      RewriteRule ^.*$ index.php?q=search&keys=%1 [L]

    This should come before any other rules, so put it just after the "RewriteEngine on" line. Don't forget to replace with your own.

  2. Add a "google_search()" function in the "search.module" file to return the Search box and the results. The code can be generated from your adsense account. Here is what I have -- note the query text is pre-filled into the search box:
    function google_search() {
            $keys = isset($_GET['keys']) ? $_GET['keys'] : $_POST['keys'];
            return t("
                    <p><hr /></p>
                    <h2>Google Powered Search Results</h2>
                    ", array('%google_search' => '
                    <div align="center">
                    <!-- SiteSearch Google -->
                    <form method="get" action="" target="_top">
                    <table border="0" bgcolor="#ffffff">
                    <tr><td nowrap="nowrap" valign="top" align="left" height="32">
                    <a href="">
                    <img src="" border="0" alt="Google" 
                    <td nowrap="nowrap">
                    <input type="hidden" name="domains" value=""></input>
                    <input type="text" name="q" size="31" maxlength="255" value="' . $keys . '"></input>
                    <input type="submit" name="sa" value="Search"></input>
                    <td> </td>
                    <td nowrap="nowrap">
                    <input type="radio" name="sitesearch" value="" checked="checked"></input>
                    <font size="-1" color="#000000"></font>
                    <input type="radio" name="sitesearch" value=""></input>
                    <font size="-1" color="#000000">Web</font>
                    <input type="hidden" name="client" value="pub-3520033732422687"></input>
                    <input type="hidden" name="forid" value="1"></input>
                    <input type="hidden" name="channel" value="9732135083"></input>
                    <input type="hidden" name="ie" value="ISO-8859-1"></input>
                    <input type="hidden" name="oe" value="ISO-8859-1"></input>
                    <input type="hidden" name="cof" 
                    <input type="hidden" name="hl" value="en"></input>
                    <!-- SiteSearch Google -->
                    <!-- Google Search Result Snippet Begins -->
                    <div id="googleSearchUnitIframe"></div>
                    <script type="text/javascript">
                    var googleSearchIframeName = "googleSearchUnitIframe";
                    var googleSearchFrameWidth = 600;
                    var googleSearchFrameborder = 0 ;
                    var googleSearchDomain = "";
                    <script type="text/javascript" src="">
                    <!-- Google Search Result Snippet Ends -->
  3. Now in the "search_view()" function concatenate the search results just before printing the page:
        $output .= google_search();
        print theme('page', $output, t('Search'));

That's it. Test it out and see how it works!!