Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: Utech22 on February 20, 2010, 01:03:57 PM

Title: How to use Google search instead of smf search
Post by: Utech22 on February 20, 2010, 01:03:57 PM
I would like to add Google search to my website.
I am using smf2.0 core theme.

site: http://forum.fashionsjamaica.com
Title: Re: How to use Google search instead of smf search
Post by: Kill Em All on February 20, 2010, 01:15:20 PM
http://custom.simplemachines.org/mods/index.php?mod=1930

That should get you what you need.
Title: Re: How to use Google search instead of smf search
Post by: Utech22 on February 20, 2010, 01:37:16 PM
I want it at the top of the forum, also this one does not have a click-able search button showing.
Title: Re: How to use Google search instead of smf search
Post by: Kill Em All on February 20, 2010, 05:51:43 PM
I'm sorry, but I'm not exactly sure what code you would have to replace it with then in your index.template.php. You will have to ask the mod's author that in its dedicated topic.
Title: Re: How to use Google search instead of smf search
Post by: Mick. on February 20, 2010, 05:56:47 PM
Do you mean google search like in my forum?

www.chevyavalancheclub.com
Title: Re: How to use Google search instead of smf search
Post by: Utech22 on February 20, 2010, 07:00:33 PM
Quote from: BlueDevil on February 20, 2010, 05:56:47 PM
Do you mean google search like in my forum?

www.chevyavalancheclub.com
yes
Title: Re: How to use Google search instead of smf search
Post by: Mick. on February 20, 2010, 07:03:01 PM
Hang on....  let me write what you need to do.
Title: Re: How to use Google search instead of smf search
Post by: 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


Title: Re: How to use Google search instead of smf search
Post by: Mick. on February 20, 2010, 07:42:47 PM
The code for the index.template.php may look slightly different than mine.   I removed the push button since i didnt want it.
Title: Re: How to use Google search instead of smf search
Post by: kenso on February 25, 2010, 04:39:12 PM
Hi Bluedevil, having a few prob with the installation getting: Template Parse Error!
There was a problem loading the /Themes/default/index.template.php template or language file. Please check the syntax and try again - remember, single quotes (') often have to be escaped with a slash (\). To see more specific error information from PHP, try accessing the file directly.

You may want to try to refresh this page or use the default theme.
syntax error, unexpected T_STRING, expecting ',' or ';'
everything seems ok?? my results code:

<?php require("/home/ozfarmer/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(); ?>
and Index.template:


<form action="http://www.ozfarmer.com/forum/results.php" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="partner-pub-83218928916*****:byhx8-jtoyl" />
    <input type="hidden" name="cof" value="FORID:10" />
    <input type="hidden" name="ie" value="ISO-8859-1" />
    <input type="text" name="q" size="21" />
    <input type="submit" name="sa" value="Search" />
  </div>
</form>
<script type="text/javascript" src="http://www.google.com.au/cse/brand?form=cse-search-box&amp;lang=en"></script>
Must be something simple?

Thanks in advance!
Kenso  ;)
Title: Re: How to use Google search instead of smf search
Post by: Mick. on February 25, 2010, 05:08:21 PM
<form action="http:www.ozfarmer.com/forum/results.php" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="partner-pub-83218928916*****:byhx8-jtoyl" />
    <input type="hidden" name="cof" value="FORID:10" />
    <input type="hidden" name="ie" value="ISO-8859-1" />
    <input type="text" name="q" size="21" />
    <input type="submit" name="sa" value="Search" />
  </div>
</form>
<script type="text/javascript" src="http:www.google.com.au/cse/brand?form=cse-search-box&amp;lang=en"></script>


The code needs this at the end
';

Make sure it has it.
Title: Re: How to use Google search instead of smf search
Post by: Mick. on February 25, 2010, 05:11:03 PM
This is fine.  It goes to your results.php

<?php require("/home/ozfarmer/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 = "hxxp:www.google.com";
  var googleSearchPath = "/cse";
</script>
<script type="text/javascript" src="hxxp:www.google.com/afsonline/show_afs_search.js"></script>

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

template_footer(); ?>
Title: Re: How to use Google search instead of smf search
Post by: Mick. on February 25, 2010, 05:27:11 PM
Kenso, what SMF series are you using?   

1.1.x?
RC2?
Title: Re: How to use Google search instead of smf search
Post by: kenso on February 25, 2010, 09:47:38 PM
Hi Blue Devil, 2.0 RC2
Title: Re: How to use Google search instead of smf search
Post by: Mick. on February 25, 2010, 09:57:56 PM
Quote from: kenso on February 25, 2010, 09:47:38 PM
Hi Blue Devil, 2.0 RC2

Ok, reply #7 should set you good.
Title: Re: How to use Google search instead of smf search
Post by: kenso on February 25, 2010, 10:28:25 PM
Hi BD, all working although it would be good to get the box hard right and there isn't anything on the results page could this be because google hasn't set it up yet? (and brilliantly done!)

Kenso
Title: Re: How to use Google search instead of smf search
Post by: Mick. on February 25, 2010, 10:36:49 PM
Quote from: kenso on February 25, 2010, 10:28:25 PM
Hi BD, all working although it would be good to get the box hard right and there isn't anything on the results page could this be because google hasn't set it up yet? (and brilliantly done!)

Kenso

Yea, if google hasn't indexed your threads, then this is useless.  Thats why i dont recommend removing the SMF search button off the nav bar just yet.

If you want to extend the box, if if i remember right,.... think is this...
<input type="text" name="q" size="21" />
change the '21' to a higher a value.   Experiment with it.
Title: Re: How to use Google search instead of smf search
Post by: kenso on February 27, 2010, 01:46:35 AM
Thanks again BD, I see that my g search is still not active any ideas why this is? :o

Kenso
Title: Re: How to use Google search instead of smf search
Post by: Mick. on February 27, 2010, 01:53:06 AM
Quote from: kenso on February 27, 2010, 01:46:35 AM
Thanks again BD, I see that my g search is still not active any ideas why this is? :o

Kenso

you have a link to your site?   pm me if you dont want to post it here.
Title: Re: How to use Google search instead of smf search
Post by: kenso on March 01, 2010, 09:54:46 PM
Hi BD  www.ozfarmer.com/forum it works well now, just need to work out how to move the search box over to the right.

Kenso
Title: Re: How to use Google search instead of smf search
Post by: allemand1 on May 27, 2010, 07:29:11 PM
and how can i do for the SMF 1.1.11?
Title: Re: How to use Google search instead of smf search
Post by: Aportadordelmix on June 02, 2010, 02:33:07 PM
Quote from: allemand1 on May 27, 2010, 07:29:11 PM
and how can i do for the SMF 1.1.11?
Title: Re: How to use Google search instead of smf search
Post by: Aportadordelmix on June 03, 2010, 02:22:26 PM
Quote from: ABM on June 02, 2010, 02:33:07 PM
Quote from: allemand1 on May 27, 2010, 07:29:11 PM
and how can i do for the SMF 1.1.11?
Title: Re: How to use Google search instead of smf search
Post by: Mick. on June 04, 2010, 05:45:38 PM
For 1.1.x users, ill write something tonight ;)
Title: Re: How to use Google search instead of smf search
Post by: Aportadordelmix on June 04, 2010, 06:28:51 PM
I do not understand
Title: Re: How to use Google search instead of smf search
Post by: Kill Em All on June 04, 2010, 09:02:44 PM
Quote from: ABM on June 04, 2010, 06:28:51 PM
I do not understand
It means, there is no way yet, he is writing up the code to do it now though... so you are going have to be patience.
Title: Re: How to use Google search instead of smf search
Post by: Mick. on June 05, 2010, 12:31:42 PM
Reply #7 updated with 1.1.x support ;)
Title: Re: How to use Google search instead of smf search
Post by: Aportadordelmix on June 05, 2010, 03:04:52 PM
thank you very much
Title: Re: How to use Google search instead of smf search
Post by: opheliagrimm on September 30, 2010, 05:21:04 PM
Guys,

Is there anyway to make this work without adsense?

That is, just have a google search box that  replaces the SMF search but does not tie into an adsense account and still shows results using the results.php file?

I applied for the Google Adsense account but it has been about 5 days and no response.

Is there a modification of your code that references the URL "www.yoursite.com" instead of an adsense account?

I already have a google search on the site but it shows the results on an external page and not inline with the forum. It also doesn't replace the default SMF search box.

Appreciate any help
Title: Re: How to use Google search instead of smf search
Post by: RawDepth on January 22, 2011, 01:25:08 PM
I added this code to my site manually. I run version 2.0 RC3 with the default theme.

It seems to be working. It displays results inside my site from the results.php page like I wanted.

Problem...
I have my custom search account set to search within my site and not the web. Now it only displays results if the actual search word appears on my index page, no results from deeper pages. If the search word or phrase does not appear on my index page, then no results are shown.

The site is already heavily indexed at Google.

Here is the site address. http://www.home-recording-studio-forum.com (http://www.home-recording-studio-forum.com)
Title: Re: How to use Google search instead of smf search
Post by: amko_sa on February 21, 2011, 10:25:36 AM
One question, how to make that I choose google search or smf search in to same SMF search window? Best example is search on this SMF forum.
Title: Re: How to use Google search instead of smf search
Post by: DanteOz on March 30, 2011, 05:55:15 PM
does dis method apply to rc4? cos i want it on my forum
Title: Re: How to use Google search instead of smf search
Post by: Illori on March 30, 2011, 06:00:25 PM
DanteOz please open a separate topic for your issue, this topic is marked solved and will be ignored by support staff.
Title: Re: How to use Google search instead of smf search
Post by: DanteOz on March 30, 2011, 06:03:52 PM
Ok, thnx
Title: Re: How to use Google search instead of smf search
Post by: Mick. on March 30, 2011, 06:31:55 PM
Quote from: DanteOz on March 30, 2011, 05:55:15 PM
does dis method apply to rc4? cos i want it on my forum

yes.
Title: Re: How to use Google search instead of smf search
Post by: DanteOz on April 08, 2011, 09:33:16 PM
Thnks, i did it
Title: Re: How to use Google search instead of smf search
Post by: Niell on June 29, 2011, 01:51:42 PM
Bluedevil Hello, this tutorial works for SMF version 2.0 Final?

Translated by Google
Title: Re: How to use Google search instead of smf search
Post by: Mick. on July 03, 2011, 11:23:46 AM
Quote from: Niell on June 29, 2011, 01:51:42 PM
Bluedevil Hello, this tutorial works for SMF version 2.0 Final?

Translated by Google
Yes.
Title: Re: How to use Google search instead of smf search
Post by: donjazzy on August 07, 2011, 02:58:49 PM
Quote from: bluedevil on February 20, 2010, 07:42:47 PM
The code for the index.template.php may look slightly different than mine.   I removed the push button since i didnt want it.
Please how can I remove the push button for mine, I don't need it. Thanks
Title: Re: How to use Google search instead of smf search
Post by: Mick. on August 07, 2011, 05:25:23 PM
Remove this bit in the code google provided you:

    <input type="submit" name="sa" value="Search" />
Title: Re: How to use Google search instead of smf search
Post by: donjazzy on August 08, 2011, 02:28:58 PM
Thank you
Title: Re: How to use Google search instead of smf search
Post by: Mick. on August 08, 2011, 04:31:01 PM
Quote from: donjazzy on August 08, 2011, 02:28:58 PM
Thank you
No problem ;)
Title: Re: How to use Google search instead of smf search
Post by: swordsman1 on February 22, 2012, 03:02:30 PM
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.
Title: Re: How to use Google search instead of smf search
Post by: LexusFTW on August 08, 2012, 03:24:57 PM
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.
Title: Re: How to use Google search instead of smf search
Post by: winsoft on February 20, 2014, 05:19:37 AM
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