Tuesday 11 January 2011

Google Custom Search 2

Tuesday 11th January 2011


All the following is the text from the webpage www.RichsWebArchive.com/aboutthissite/googlesearch/index.php and it reads as though you are viewing the actual page:
I wanted to add a search facility for the site and decided to use Google's custom search facility.
It sound simple doesn't it. It wasn't. The best part of a day later I've got it almost as I want it thanks to Google employee Jeff S and his elegant solution which renders your search results onto a separate page.
Jeffs solution uses a fair bit of JAVA code. I don't know much about JAVA right now, maybe just enough to understand how the code used works but I'd never have worked it out on my own.
The fist task was to set up the custom search at Google. This is pretty straightforward and they walk you right through it. Don't worry about setting the colours up or grabbing the code there. The only thing you really need is the search identifier string which will look something like this:
006661011771658008210:qwwbhda4b_m
The next job was to get the search box and button into the title bar on every page. A new XHTML file called titlebar.htm was created in the root directory/folder of the site which contains the title text and a php include of googlesearch4.htm - the code for the search box and button. I then edited the id=titlebar section in every page replacing the existing code with a php include for titlebar.htm.
The code in googlesearch4.htm calls a separate page results.php to display the search results. Both of these files are largely chunks of code from Jeff's solution, edited to work on my site with the right formatting. The search identifier string in Jeff's code was replaced with my own one.
I'm not going to get into explaining the JAVA in these files yet as it's probably slightly beyond me right now. It's enough for the moment that it just works.
There is one slight problem which is that if you do subsequent searches from the results page and then hit the back button in your browser you go straight back to the page which originally called the results page, rather than stepping back through your additional searches. Instead of trying to sort this out myself, which would mean fiddling with the JAVA code, I've posted a question back to Jeff S of Google in the hope that he'll offer me a nice simple solution. I think Jeff might come up with the solution in 5 minutes whereas it might take me the rest of today.
Once again, all the preceding text is from the webpage www.RichsWebArchive.com/aboutthissite/googlesearch/index.php and it reads as though you are viewing the actual page:

No comments:

Post a Comment

keep it nice now