This post originated from an RSS feed registered with Java Buzz
by dion.
Original Post: Installing the Ajax Search API on this blog
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
This allowed me to get rid of the poor search that was in the blog software itself, and just let Google to the work.
The search happens inline, with results showing up on the left hand bar itself. I could have used a different model to put the results in a div on the right hand side, which is many cases is probably better.
I used the tabbed search control that enables results to be shown for the web in general, and across blogs, as well as the default... pinned to this site.
The bulk of the work is this JavaScript function, that shows the API at work:
function OnLoad() {
// Create a search control
var searchControl = new GSearchControl();
// Setup a search for this site
var siteSearch = new GwebSearch();
siteSearch.setUserDefinedLabel("This Site");
siteSearch.setUserDefinedClassSuffix("siteSearch");
siteSearch.setSiteRestriction("almaer.com");
searchControl.addSearcher(siteSearch);
// Setup a search for the entire web
var webSearch = new GwebSearch();
webSearch.setUserDefinedLabel("Entire Web");
searchControl.addSearcher(webSearch);
// Setup a search for blogs
var blogSearch = new GblogSearch();
blogSearch.setUserDefinedLabel("Blogs");
searchControl.addSearcher(blogSearch);
// Setup the tabbed view
var drawOptions = new GdrawOptions();
drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
// Tell the searcher to draw itself and tell it where to attach
searchControl.draw(document.getElementById("searchcontrol"), drawOptions);
}
GSearch.setOnLoadCallback(OnLoad);