The Movable Type User Manual

NOTE: This documentation is for Movable Type 3.2. If you are using a newer version, please see the documentation for Movable type 3.3x or Movable Type Enterprise.

« Adding Alternate Search Templates | Up | Introduction »

Chapter 10: Search

Setting Up Google Enabled Entries

Problem

You want to integrate Google search results into your entry.

Solution

Provide Movable Type with your Google API Key and use the MTGoogleSearchResult template tag.

Discussion

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.

This functionality requires that your system has the SOAP::Lite and LWP::UserAgent modules from CPAN. They also require a Google API key be obtained and configured to activate each weblog. Doing so is relatively straightforward process.

  • 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. Go into the Movable Type CMS and click the Edit Configuration link next to the weblog you want to enable or, within the weblog, click the Settings button in the Weblog Toolbar.
  • 3. Under the General tab of the Settings screen enter your Google API Key and then 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.

Let's look at some example uses of these tags:

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.

Submit Feedback on This Article

Your comments on how we can improve this article are appreciated; but please do not use the feedback form to submit support requests or question. We will not respond to or publish such queries submitted through this form. If you have a technical question or problem, visit Movable Type Support.

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