Movable Type Documentation

Back to docs index

Chapter GoogleSearch

In this section:


Movable Type is capable of making Google search queries and inserting the results into site layouts. This built-in functionality is geared toward inserting related links into an entry or a specific topic such as an author's name rather than providing unfettered access to the full power of the Google search engine. This is more a limitation of the Google API than anything related to MT's implementation.

To utilize the GoogleSearch plugin's functionality, simply provide Movable Type with your Google API Key and use the MTGoogleSearchResult template tag.

  1. To obtain a Google API key go to http://www.google.com/apis/ to register for an account. Once registered you will receive a license key from Google that is good for 1000 queries a day.

  2. Insert that license key into the Google API Key field in the GoogleSearch Settings panel in the System-wide Settings Plugins screen, and press Save Changes.

The Google search features of this weblog have been enabled.

You can reuse your Google API key in multiple weblogs. Each weblog's usage will count towards the key's daily quota.

Integrating Google results into Movable Type is achieved through two action packed tags -- MTGoogleSearch and MTGoogleSearchResult.

MTGoogleSearch creates the search context by using the Google API to obtain results for a particular query or for pages that are similar to a particular entry. Once retrieved, the contents of this tag are looped through for each result. The type and parameters of the search are determined by the following supported attributes.

  • query - Issues a specific search to Google.

  • related - Return results that are similar to a certain page. The value of this parameter can be a URL or 1. Passing a value of 1 will cause your Site URL to be used. (You should have set your Site URL in your Weblog configuration -- if not you'll have to do so to make use of this option.)

  • results - An integer between 1 and 10 specifying the number of search results to insert.

  • title - Takes a boolean value. If set to 1 (true), the title of the entry in context will be used as the query.

  • excerpt - Takes a boolean value. If set to 1 (true), the excerpt of the entry in context will be used as the query.

    Is there a limit on words???

  • keywords - Takes a boolean value. If set to 1 (true), the keywords of the entry in context will be used as the query.

NOTE: query, related, title, and excerpt are mutually exclusive of each other.

MTGoogleSearchResult represents a field of an individual Google search result. This tag is used in the context of a MTGoogleSearch tag.

The tag recognizes a single attribute of property that specifies the field of the search result to be displayed. Values for property can be: "summary," "URL," "snippet," and "title." The default property is title.

Tag Usage Examples

To list the top five search results for the query "movable type," insert this template code:

<MTGoogleSearch query="movable type" results="5">
<a href="<$MTGoogleSearchResult property="URL"$>">
<$MTGoogleSearchResult property="title"$></a><br />
</MTGoogleSearch>

Alternatively, to insert a list of related links based on a site's home page, insert this template code:

<MTGoogleSearch related="1">
<a href="<$MTGoogleSearchResult property="URL"$>">
<$MTGoogleSearchResult property="title"$></a><br />
</MTGoogleSearch>

Google search results on a per entry basis can be inserted into an Individual Search Archive template like so:

<MTGoogleSearch title="1" results="3">
<p><a href="<$MTGoogleSearchResult property="URL"$>">
<$MTGoogleSearchResult property="title"$></a><br />
<$MTGoogleSearchResult property="snippet"$></p>
</MTGoogleSearch>

This of course assumes that entry titles are sufficiently descriptive to return relative results from Google.

Impact on Performance and Other Limitations

If you use the Google search tag in your Individual Archive Template, a call will be made to Google for each entry. This will significantly impact the speed of the rebuilding process. Depending on the number of posts in the weblog or how often entries are rebuilt, perhaps to display a new comment, the daily quota of Google permits could be exceeded.

Six Apart
Makers of weblog software and services for individuals, organizations and businesses.
This website is powered by Movable Type.