Use Google Search on vBulletin to reduce CPU

Status
Not open for further replies.

Mr Happy

Active Member
4,093
2009
2,572
0
I wrote this tutorial for CyberWarez as their search has being disabled for ages due to the server going crazy. It's not really useful for small sites but big sites like USAwarez, KatzForums all use a more basic version of this and w-bb has a huge flood limit to reduce the search load. For the vB4 tutorial PM me but if their's a demand I'll make another post.

Demo vb3
http://linkzbot.com/vb/
http://realwarez.org/forum/

Demo vb4
http://linkzbot.com/vb4/

Instructions for vBulletin 3.x

Step 1

This below bit is edited from vb and is for making new pages. Copy the below and name it find.php and upload it to your server where you installed vBulletin.
PHP:
<?php 

// ####################### SET PHP ENVIRONMENT ########################### 
error_reporting(E_ALL & ~E_NOTICE); 

// #################### DEFINE IMPORTANT CONSTANTS ####################### 
define('NO_REGISTER_GLOBALS', 1); 
define('THIS_SCRIPT', 'test'); // change this depending on your filename 

// ################### PRE-CACHE TEMPLATES AND DATA ###################### 
// get special phrase groups 
$phrasegroups = array( 

); 

// get special data templates from the datastore 
$specialtemplates = array( 
     
); 

// pre-cache templates used by all actions 
$globaltemplates = array( 
    'Search Site', 
); 

// pre-cache templates used by specific actions 
$actiontemplates = array( 

); 

// ######################### REQUIRE BACK-END ############################ 
require_once('./global.php'); 

// ####################################################################### 
// ######################## START MAIN SCRIPT ############################ 
// ####################################################################### 

$navbits = array(); 
$navbits[$parent] = 'Search Results'; 

$navbits = construct_navbits($navbits); 
eval('$navbar = "' . fetch_template('navbar') . '";'); 
eval('print_output("' . fetch_template('Search Site') . '");'); 

?>

Step 2

We have to create a custom search for the site you want. Go to http://www.google.com/cse/ and select Create A Custom Search. Enter the details; name, description, site(s) you want to search. Don't worry too much as this can be edited later. Paying the $100 will remove the Google Adds if you don't want them.

Click Finish and then click on the control panel for the Search engines I've created.

Edit any details you want and then click on look and feel on the left.

Select iFrame and then you can change the look and feel to match your sites template.

Then click Save and Get code.

For the url make it point to where you have find.php so it should be something like http://sitename.com/find.php or http://sitename.com/forum/find.php

It's the Search box code code part we want. Don't worry about the Search results code

You should have something like this which we'll return to in a minute.
PHP:
<form action="http://linkzbot.nagds" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="009729591642794172819:aeozcdubiek" />
    <input type="hidden" name="cof" value="FORID:10" />
    <input type="hidden" name="ie" value="UTF-8" />
    <input type="text" name="q" size="31" />
    <input type="submit" name="sa" value="Search" />
  </div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>

Step 3

Next we'll create the template in the ACP for the Search Results Page.
In Style Manager select Add new Template and for a name use Search Site
In the template box paste the below and click save. If you want you can change the with of the resutls by changing the 700 I've set it to.
PHP:
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>$vboptions[bbtitle]</title>
$headinclude
</head>
<body>
$header

$navbar

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
	<td class="tcat">Search Site</td>
</tr>
<tr>
	<td class="alt1"><div id="cse-search-results" align="center"></div>
<script type="text/javascript">
  var googleSearchIframeName = "cse-search-results";
  var googleSearchFormName = "cse-search-box";
  var googleSearchFrameWidth = 700;
  var googleSearchDomain = "www.google.com";
  var googleSearchPath = "/cse";
</script>
<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
      </div></td>
</tr>
</table>

$footer
</body>
</html>

You should now be able to go to http://sitename/find.php or http://sitename/forum/find.php and see an empty page.

Step 4

This next step will add the search Box to the navbar to the left of the Login Box/Members Details. If you know your shit and templates you can place it anywhere. This is for vb default template.

In Style Manager in the ACP Edit the Template Navigation/Breadcrumb Templates >> navbar
Find:
PHP:
<if condition="$show['member']">
	<td class="alt2" nowrap="nowrap">
	<div class="smallfont">

The bit we add ABOVE is different for everyone. Remember the code we got off Google in Step 2, well we need the three lines starting with <input type="hidden" to be added and the location of the find.php in your site.
PHP:
<td class="alt2" nowrap="nowrap" style="padding:0px">
<div>Search <br />
<form action="http://sitename/find.php" id="cse-search-box" class="navbar_search">
    <input type="hidden"  YOUR CODE HERE  />
    <input type="hidden"  YOUR CODE HERE  />
    <input type="hidden"  YOUR CODE HERE  />
    <span class="textboxcontainer"><span><input type="text" name="q" value="" class="textbox" /></span></span>
    <input type="submit" class="button" value="$vbphrase[go]" tabindex="1004" />
</form>
</div>	
</td>

That should be all installed and working now. You'll be able to track what members are searching in the control panel in Google. Of course if your feeling techie and confident edit this as you please. Any questions just ask.

Katzforums should add this as their current search isn't great looking.
 
29 comments
I guess this will help u as Google would rank ur pages higher (as users would be searching on ur site through Google.)
 
trying this out thanks so much MrHappy
No problem your welcome :)

This is what you used on our forum Mr. Happy????

Nice one though...
It was the original thing done to CyberWarez. The topics got a bit of a bump and a custom search has being built since.
Mr Happy,can you explain us the same one for vB 4.x ? :)
Thnx.
Sorry for not replying to your PM. I'll add it this evening.
I guess this will help u as Google would rank ur pages higher (as users would be searching on ur site through Google.)
Correct. I never though of that but your Organic traffic will go up which will look great on your stats and alexa and will really help you selling text links, adverts etc here on WJ. The other huge advantage is Google will track your searches for you and let you know exactly and accurately what people are searching for on your site allowing you to fix topics which can't be found or sticky topics people are looking for etc. Information is key :)
Woha!!
Great job man!
Any such tut for phpbb3?
It's definately possible but unfountionately I don't know PHPBB well enough to incorporate the Google search like I've done above. Sorry :(
Great, thanks for this. Like your work as usual. :)
Cheers thank you :)
 
wht if google nt index all page then wht ??

As I said it's only really practical for large sites. Most large sites have several thousand pages indexed. If your a small site with very few pages indexed then your unlikely (or at least shouldn't be) suffering from high server loads.

Anyway thanks for the feedback. Was a while since I did this so the demo's don't work any more but the tutorial still does.
 
Status
Not open for further replies.
Back
Top