Expanding the Search Results

Figure 1 through Figure 5 have only shown you, by default, partial search results (one result per searcher). You have some options in terms of how the results are displayed: partial for showing one search result; open for more results; and closed for showing no results. To get an idea of what this looks like, see Figure 6.

Figure 6 shows the web, local, and video searchers closed, and the news searcher open, with four results. The blog searcher is open partially be default, but you can set this concretely, as with the others.

sample.html with searchers open, closed, and partially open

Figure 6. sample.html with searchers open, closed, and partially open

Example 5 shows how to do this in code. The changes are highlighted.

Example 5. doSearch showing how to use searcher options

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

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

  // Change local search center point
  local.setCenterPoint( "Jackson Hole, Wyoming" );

  // Set searcher options for open/closed
  var closed = new GsearcherOptions();
  var opened = new GsearcherOptions();
  closed.setExpandMode( GSearchControl.EXPAND_MODE_CLOSED );
  opened.setExpandMode( GSearchControl.EXPAND_MODE_OPEN );

  // Add a web search
  search.addSearcher( new GwebSearch(), closed );
  search.addSearcher( local, closed ); search.addSearcher( new GblogSearch() ); search.addSearcher( ...

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.