Adding a Google Custom Search engine in your site

All of you must have seen a search engine toolbox in most of the site. This might have made you want to use one in your site too. This is how you do it.

Go to http://www.google.com/coop/cse/. After that check for

Click Create Button.
You will see a Form. Let's Start with the Basic Configuration.


Some of these steps are less relevant when you're creating a one-site search engine, but nonetheless, a nice search engine name and description are useful, as are some keywords, requested in the next section:


If your site has information in multiple languages, definitely make sure you choose the predominant language here, and if you're just in English, like I am, then the default works just fine.

Next you need to decide if you are going to create a search engine for multiple sites or just one. Since we're doing an on-site engine, let's just stick with one for the results, as you can see:


Since you want to search your entire site, use the notation shown, of www.xyz.com/* (most likely using www.xyz.com will work too, but the "/*" is what Google recommends, so it's best to play by their rules!)


As you can see, I'm opting for the free one, because I'm okay with ads showing up in the search results as long as I make a small slice of the revenue stream generated from those advertisers.

Finally, it's time to click "Next", at which point you can try out a few searches and ensure it's working, then click "Finish" and you're done!

Now the interesting part, customizing the appearance and getting the code you can add to your site so that the search actually works.

Basics | Sites | Refinements | Look and feel | Code | Collaboration | Make money | Business Edition | Advanced | Preview

To get the code you need for the page that'll host the search results, click on Code. There are a couple of choices for what kind of behavior you want for the search: You want the default choice of an iframe, which gives you some simple code you can drop on all your pages for the search box and then lets you create a custom template page with code, also from Google, that incorporates the search results.


Now Google offers up a block of code that implements the search box itself. When I paste it into this blog entry, it results in:

Try it if you want, see what happens...

The other block of code you get from Google is the code to put in the search results page, and that too is a sequence of mysterious HTML and Javascript. But it's easily added. If you tried a search, above, you've already had a chance to see the resultant page in action. To get it to work, all I added was the following code in the "middle" of the page HTML:




<div id="results_013314643351057663050:lozwmpsfbnu"></div> <script type="text/javascript">
var googleSearchIframeName = "results_013314643351057663050:lozwmpsfbnu";
var googleSearchFormName = "searchbox_013314643351057663050:lozwmpsfbnu";
var googleSearchFrameWidth = 600;
var googleSearchFrameborder = 0;
var googleSearchDomain = "www.google.com";
var googleSearchPath = "/cse";
</script>
<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js">
</script>


0 comments:

GosuBlogger