Searching Beyond the Web

So far, We’ve only shown you one search object: GwebSearch. You can also use search services for local, blog, video, and news searches. Figure 4 shows some of these.

Search results for web, local, blog, and video on the “peanut butter”

Figure 4. Search results for web, local, blog, and video on the “peanut butter”

So how do you do that? All you need to do is add five new searchers for a total of six, one each for local (GlocalSearch), image (GimageSearch) blog (GblogSearch), video (GvideoSearch), and news (GnewsSearch). These objects are all considered child objects of GSearchControl.

Note that for the example above we changed the argument of execute to something yummier, its now “peanut butter.” You’ll also discover in Figure 4 another twiddle (). Click on one of these, and you’ll find different options for a search service, such as sorting results by date for blog and news.

Refer to Example 3 to see the changes to the code in context (note bold).

Example 3. doSearch with added searchers and a new search term

<script language="Javascript" type="text/javascript">
function doSearch() {

  // Instantiate control, web search service
  var search = new GSearchControl();

  // Add a web search
  search.addSearcher( new GwebSearch() );
  search.addSearcher( new GlocalSearch() );
  search.addSearcher( new GimageSearch() );
 search.addSearcher( new GblogSearch() ...

Get Google Ajax Search API now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.