News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

How to use Google search instead of smf search

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

Previous topic - Next topic

Utech22

I would like to add Google search to my website.
I am using smf2.0 core theme.

site: http://forum.fashionsjamaica.com

Kill Em All



My Site: KEAGaming.com

Manual Installation of Mods
Prevent Spam and Forum Attacks
Please do not PM or email me for support unless offered, help should be publicly displayed to others.

Utech22

I want it at the top of the forum, also this one does not have a click-able search button showing.

Kill Em All

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.


My Site: KEAGaming.com

Manual Installation of Mods
Prevent Spam and Forum Attacks
Please do not PM or email me for support unless offered, help should be publicly displayed to others.

Mick.

Do you mean google search like in my forum?

www.chevyavalancheclub.com

Utech22


Mick.

Hang on....  let me write what you need to do.

Mick.

#7
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



Mick.

The code for the index.template.php may look slightly different than mine.   I removed the push button since i didnt want it.

kenso

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  ;)
The Farmers and self-sufficiency forum
http://www.ozfarmer.com.au

Mick.

#10
<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.

Mick.

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(); ?>

Mick.

Kenso, what SMF series are you using?   

1.1.x?
RC2?

kenso

The Farmers and self-sufficiency forum
http://www.ozfarmer.com.au

Mick.


kenso

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
The Farmers and self-sufficiency forum
http://www.ozfarmer.com.au

Mick.

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.

kenso

Thanks again BD, I see that my g search is still not active any ideas why this is? :o

Kenso
The Farmers and self-sufficiency forum
http://www.ozfarmer.com.au

Mick.

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.

kenso

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
The Farmers and self-sufficiency forum
http://www.ozfarmer.com.au

allemand1


Aportadordelmix



Mick.

For 1.1.x users, ill write something tonight ;)

Aportadordelmix


Kill Em All

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.


My Site: KEAGaming.com

Manual Installation of Mods
Prevent Spam and Forum Attacks
Please do not PM or email me for support unless offered, help should be publicly displayed to others.

Mick.


Aportadordelmix


opheliagrimm

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

RawDepth

#29
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

amko_sa

#30
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.

DanteOz

does dis method apply to rc4? cos i want it on my forum

Illori

DanteOz please open a separate topic for your issue, this topic is marked solved and will be ignored by support staff.

DanteOz


Mick.


DanteOz


Niell

#36
Bluedevil Hello, this tutorial works for SMF version 2.0 Final?

Translated by Google

Mick.

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.

donjazzy

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

Mick.

Remove this bit in the code google provided you:

    <input type="submit" name="sa" value="Search" />


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: