Oturum açın

Examples

This page provides an example of a subscribed link. You can copy the code and modify it according to your needs.

Example of Subscribed Links with Gadgets

This section provides an example of a subscribed link that uses gadgets. To learn more about incorporating gadgets in your custom results, see the Designing the Look and Feel page. To learn more about creating gadgets, see the gadgets API Developer Guide.

Subscribed Links Using OpenSearch

This example shows you how you can create custom results with a gadget that uses OpenSearch. OpenSearch is a set of open standards for allowing third-party sites to return search results in various common formats, including RSS feeds. You can put such third-party search results at the top of your subscribers' search results pages when they type relevant queries.

The code for the OpenSearch gadget is available from http://www.google.com/ig/modules/opensearch_json.xml. This gadget uses the feed fetching libraries included in the gadgets API to fetch one or more OpenSearch RSS feeds and combine their results into a uniformly formatted display.

With the OpenSearch gadget, you can create a subscribed link for HubMed, which is an OpenSearch front end to the PubMed medical publication database. The sample Subscribed Links description file tells Google to display HubMed search results whenever the user enters a query that begins with "pubmed" followed by the medical terminology they want to research.

OpenSearch Result: Code

The description file for this subscribed link looks like the following:

<Results>
   <ResultSpec id="hubmed_search">

      <Query>pubmed [RE:(.*)]</Query>

      <Response format="gadget">
       <Output name="title">Hubmed search: [0.gr0]</Output>
       <Output name="more_url">http://www.hubmed.org</Output>

       <Output name="gadget_src">http://nweininger.googlepages.com/opensearch.xml</Output>
       <Output name="gadget_width">600</Output>
       <Output name="gadget_height">140</Output>

       <Output name="up_name1">query</Output>
       <Output name="up_value1">[0.gr0]</Output>

       <Output name="up_name2">url1</Output>
       <Output name="up_value2">http://www.hubmed.org/feeds/rss.cgi?q=[0.gr0]</Output>
      </Response>

   </ResultSpec>
</Results>

Notes about this description file:

  • The query uses a regular expression. [RE:(.*)]tells the Subscribed Links API to accept any search term. So any search query that starts with "pubmed" followed by any word will trigger a Subscribed Links search.
  • The gadget display size is set to have a width of 600 pixels and a height of 140 pixels.
  • Two settings are passed to the UserPrefs of the gadget. The up_name and up_value attributes pass the relevant portion of the query and the OpenSearch URL to the gadget, which fetches results from HubMed.

OpenSearch Result: Preview

A user who types "pubmed gpcr" on the search box will see the a custom result that might look like this: