How to use Google search instead of smf search

Started by Utech22, February 20, 2010, 01:03:57 PM

Previous topic - Next topic

Mick.


swordsman1

Got this working fine on my forum...eventually. Great work bluedevil!

Search was hurting my server's performance but this solves the problem in one swoop. Zero server resources! Better even than the fabled 'Sphinx' search mechanism that the performance experts here recommend.

It should really be made into a mod to make it more idiot proof.

LexusFTW

I'm trying to install google adsense search on my forum.  I can't find the main content line in my index.template.php file.  I've attached it.

winsoft

Hi,

Is this code still working for 2.0.7?

Thanks

Quote from: Mick. on February 20, 2010, 07:29:50 PM
SMF 2.0 Only

Assuming you have access to the server...

First off...... create a file named:   results.php  (where SMF is installed).


Go to Google.com and create an account with webmasters, http://www.google.com/webmasters/

Once you've done that, go to settings and click on "adsense", sign-in, click on "adsense setup", then select: "adsense for search".


On that page follow thru to create the "search code".  It will ask you where do you want the results to appear.  Select "within".
Just type the URL of your site with results.php at the end. i.e. yoursite.com/results.php

Once done, it will provide 2 codes.   One for the index.template.php and the other for the results.php you created.


The codes:

In your newly created page (results.php) insert:

<?php require("/home/*******/public_html/SSI.php");
$context['page_title_html_safe'] = 'Results';
template_header();
echo
'
<br />


<center><div id="cse-search-results"></div>
<script type="text/javascript">
 var googleSearchIframeName = "cse-search-results";
 var googleSearchFormName = "cse-search-box";
 var googleSearchFrameWidth = 800;
 var googleSearchDomain = "www.google.com";
 var googleSearchPath = "/cse";
</script>
<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>

</center></td>
       </tr>
   </tbody>
</table>'
;

template_footer(); ?>


Remember to add the full path of your forum in line 1.   I omitted it with asterisks.



.....and the custom search button:

In your default theme index.template.php find:


<div class="news normaltext">
<form id="search_form" style="margin: 0;" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
<input type="text" name="search" value="" class="input_text" />&nbsp;
<input type="submit" name="submit" value="', $txt['search'], '" class="button_submit" />
<input type="hidden" name="advanced" value="0" />';


and replace with the code google provided you.

Should look like this:


<div class="news normaltext">
<form action="http://www.chevyavalancheclub.com/results.php" id="cse-search-box">
  <div>
<input type="hidden" name="cx" value="partner-pub-0022808160619558:cah4ko-n5ph" />
<input type="hidden" name="cof" value="FORID:10" />
<input type="hidden" name="ie" value="ISO-8859-1" />
<input type="text" name="q" size="31" />
  </div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script>';


Remember these are my codes.  Just replace the codes with what google provided you.

Also,.... i wouldnt remove the SMF search button simply because you only have less than a 200 posts.  Meaning that chances are, not all your posts are indexed yet.   Google search results only works if threads are indexed.  If not, the page results will show zero results.




SMF 1.1.11 and all SMF 1.1.x

Create a file called results.php in your root directory. (same directory where ssi.php is located).

Add the following to results.php
<?php

require_once(dirname(__FILE__) . '/SSI.php');

$context['page_title'] = 'Results';

obExit(true);

function
template_main()
{
echo
'<center><div id="cse-search-results"></div>
<script type="text/javascript">
 var googleSearchIframeName = "cse-search-results";
 var googleSearchFormName = "cse-search-box";
 var googleSearchFrameWidth = 800;
 var googleSearchDomain = "www.google.com";
 var googleSearchPath = "/cse";
</script>
<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>

</center>'
;
}

?>



Now lets replace smf's search box for the google custom search box....

Open: Themes/default/index.template.php

Find:
<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '" style="margin: 0;">
<a href="', $scripturl, '?action=search;advanced"><img src="'.$settings['images_url'].'/filter.gif" align="middle" style="margin: 0 1ex;" alt="" /></a>
<input type="text" name="search" value="" style="width: 190px;" />&nbsp;
<input type="submit" name="submit" value="', $txt[182], '" style="width: 11ex;" />
<input type="hidden" name="advanced" value="0" />


Replace with:
<form action="http://www.bluedevilcustoms.com/11.1.x%20SMF/results.php" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="partner-pub-0022808160619558:y2qyrg48s4v" />
    <input type="hidden" name="cof" value="FORID:10" />
    <input type="hidden" name="ie" value="ISO-8859-1" />
    <input type="text" name="q" size="31" />
    <input type="submit" name="sa" value="Search" />
  </div>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script>


Replace above:
http://www.bluedevilcustoms.com/11.1.x%20SMF/results.php
with the full URL of your newly created results.php


Have fun;)

Demos:

1.1.x http://www.bluedevilcustoms.com/11.1.x%20SMF/index.php
RC3 http://www.bluedevilcustoms.com/index.php

Advertisement: