My favorites | English | Sign in

Faster apps faster - GWT 2.0 with Speed Tracer New!

Google AJAX Search API

AJAX Search API - Frequently Asked Questions

General Questions

What is the Google AJAX Search API?
 
How do I know if I'm violating the AJAX APIs Terms of Use?
 
Where can I find the Developer Guide?
 
What countries are supported in AJAX Search's "Local Search" feature?
 
How do I start using the Google AJAX Search API on my site?
 
What can I do with this API?
 
What is "clipping"?
 
Once a user "clips" a search result from the AJAX Search API onto my site, is it connected to Google in some way? Does it ever get updated?
 
It looks like the AJAX Search API is in "Version 1.0." What does that mean?
 
Am I allowed to use the Google AJAX Search API on my site?
 
Is the AJAX Search API available for commercial websites?
 
Can I use the AJAX Search API in my non-Web application?
 
Can I scrape the search results from the Google AJAX Search API if the API doesn't meet my needs?
 
How does the API key system work?
 
Which web browsers does the Google AJAX Search API support?
 
What do I do if someone complains about AJAX Search API content on my site?
 
I have a different question/problem. Whom should I contact?
 
What is the Google AJAX API loader and how does it relate to AJAX Search?
 
How is the Google AJAX API loader used?
 
With the AJAX API loader, do I have to change my code if I'm already using AJAX Search, AJAX Feed and/or Maps?
 

Developer Questions

Where do I start?
 
How do I retrieve results from a search?
 
How do I see what users query?
 
My SearchControl is displaying only one result, even if I set the result set size to large. What's wrong?
 

Licensing

What license is the sample code released under?
 
What are the restrictions on using sample code?
 
If there are no restrictions, why do you have a license?
 
Why not a simpler license then, why use the Apache license?
 


General Questions

What is the Google AJAX Search API?

The Google AJAX Search API is designed to make it easier for webmasters and developers to do two things:

  1. Add a dynamic search box to your site that includes Google Web, Image, Video, News, Maps, Blog, Book, and Patent search results.
  2. Build powerful web apps on top of Google search. See some samples.

Check out the API Documentation for more details.

How do I know if I'm violating the AJAX APIs Terms of Use?

In most cases it should be clear whether your usage of the AJAX APIs complies with the posted Terms of Use. However if you are still unclear, and have a strong vested interest in resolving any confusion, it is best to consult a lawyer who can give professional legal advice on this. Google engineers can only offer technical advice in the forum and are not qualified to offer legal advice.

Where can I find the Developer Guide?

The Developer Guide can be found at http://code.google.com/apis/ajaxsearch/documentation/.

What countries are supported in AJAX Search's "Local Search" feature?

The AJAX Local Search API supports all of the countries which have local business information indexed. That is, any local listing results found on Google's Local Search will also be available via the API.

How do I start using the Google AJAX Search API on my site?

Simply sign up for an API key and you can add a Google AJAX Search module to your site. See the AJAX Search API documentation for examples and details.

What can I do with this API?

Check out our usage samples to get a sense for what you can do with the AJAX Search API. That page includes things like Map Search, Video Search, and Video Bar solutions, which are snippets of code you can copy-and-paste into your site for some powerful functionality. We often announce new samples and solutions in our blog.

What is "clipping"?

The AJAX Search API includes "clipping" functionality that makes it easy for users to insert Google search result content into your site. This means you could give your users a way to:

Once a user "clips" a search result from the AJAX Search API onto my site, is it connected to Google in some way? Does it ever get updated?

No, once Google search results are clipped and added to your site, they are mostly static -- Google won't control or update the text on your site, although the content that Google hosts such as video thumbnail images may disappears from your site if they are removed from Google's index.

It looks like the AJAX Search API is in "Version 1.0." What does that mean?

The AJAX Search API is still in its early stages, hence the "1.0" version number. It won't likely change as dramatically as its first few months (when it was a v0.1), but you can expect that we'll continue to add features and make significant changes based on developer feedback.

Am I allowed to use the Google AJAX Search API on my site?

The AJAX Search API is available for sites that are accessible to their end users without charge. You can use the API on both commercial and non-profit websites as long as your site meets the terms of use.

Please bear in mind that Google can't officially "sign off" on every website that uses this API, so it's your responsibility to make sure your site meets the terms of use before you develop and launch it. Google reserves the right to suspend or terminate your use of the service at any time, so please read the terms of use carefully.

Is the AJAX Search API available for commercial websites?

Yes, it is, as long your site is accessible to your end users without charge. For example, if your website is supported by advertising, it likely falls within the terms of the AJAX Search API.

However, not all commercial uses are allowed. For example:

  • Premium websites – If your site is only available to paying customers, you cannot use the AJAX Search API.

Remember, Google reserves the right to suspend or terminate the use of the service at any time, so please read the terms of use carefully.

Can I use the AJAX Search API in my non-Web application?

Yes! We want to make it clear that you can use these APIs in the context of websites, gadgets, mobile apps, desktop client apps, etc.

Can I scrape the search results from the Google AJAX Search API if the API doesn't meet my needs?

Sorry, but no; the AJAX Search API is the only permissible way to publish Google AJAX Search API results on your site. We'll block your application if it accesses search results outside of the API.

How does the API key system work?

You may optionally use an API key which you’ll include in the URL with which you access the API. We’ll use that key to track API usage.

The key you receive in the signup process is valid for a directory, and any subdirectories below that directory, on your website. If you sign up for the directory http://www.mygooglesearchsite.com/mysite, your key is valid for these URLs:

  • http://www.mygooglesearchssite.com/mysite/
  • http://www.mygooglesearchsite.com/mysite/mypage.html
  • http://www.mygooglesearchsite.com/mysite/page?arg=foo
  • http://www.mygooglesearchsite.com/mysite/subdir/page.html

The key will not be valid for these URLs:

  • http://differenthost.mygooglesearchsite.com/mysite
  • http://www.mygooglesearchsite.com/

Which web browsers does the Google AJAX Search API support?

The Google AJAX Search API is currently available on Firefox 1.5+, Safari, Opera 9+, and IE 6+.

What do I do if someone complains about AJAX Search API content on my site?

If you make use of the AJAX Search API's "clipping" functionality, which enables users to insert Google search result content into your site, it is your responsibility to respond to user concerns about that content. You must provide users with a way to contact you and let you know about problems, and remove the clipped search result content from your page if appropriate. For example, a business should be able to reach you if a local search result clipped from Google onto your site shows the wrong phone number. You should know that for copyright complaints, US law provides a specific process that you can use for removing content. Information about Google's own process, which may be a helpful reference, is in our DMCA policy

I have a different question/problem. Whom should I contact?

Please post your question in the Google AJAX Search API discussion group to get help from the Google AJAX Search API developer community. The AJAX Search API team also participates in this group to answer questions.

What is the Google AJAX API loader and how does it relate to AJAX Search?

The Google AJAX API loader makes it easier to use multiple Google AJAX APIs on the same page and unifies the namespaces across them. Instead of adding a separate script tag for each API, this loader gives you a common way to load multiple APIs at once.

How is the Google AJAX API loader used?

With the Google AJAX API loader, you can use a single script tag, whether you're using a single AJAX API or several. The loader is loaded using a script tag of:

<script type="text/javascript" src="http://www.google.com/jsapi?key=YOUR-KEY"></script>

Once you have the loader available, you can request additional modules using the google.load() method:

<script type="text/javascript"> 
google.load("feeds", "1");
google.load("search", "1");
</script>
            

With the AJAX API loader, do I have to change my code if I'm already using AJAX Search, AJAX Feed and/or Maps?

No. If you prefer to leave your working code alone, that's fine. We'll continue to update and maintain the G* naming scheme alongside the google.* naming scheme. For more information on the AJAX API loader, please see the documentation.


Developer Questions

Where do I start?
There are three general ways to use our Search API:
  1. Use the Search Control to manage your searchers, perform the query, and draw your results.
  2. Use a customized wizard that we provide, such as the Video Bar, Image Search, News Bar, or Blog Bar.
  3. Use "Raw Searchers" and write all of the code for the user interface, the search, the handling of results, and the display of results. Examples are Raw Search and Raw Patent Search.

The benefit of techniques #1 and #2 is that all of the user interface is pre-designed for you and they are very easy to integrate into your page. They also have a fair amount of customizable options.

The upside to option #3 is that you have full control over your search and results. This means you can create your own user interface then design how the results are displayed.

Choosing which option to use should depend on the requirements of your application. Simply put, if you just want a quick search box on your page then options #1 and #2 are the way to go. But if you are looking to have a customized experience or to make custom modifications to the Search Control or Wizards then you might save time by writing your own "Raw Searcher".

How do I retrieve results from a search?

Use the setSearchCompleteCallback method. It lets you set a function to be called when the search has completed.

If you are using the Search Control, here is how you would use the setSearchCompleteCallback:

function searchComplete(searchControl, searcher) {
  for (var i=0; i < searcher.results.length; i++) {
    // Do whatever you want with the results
  }
}

function OnLoad() {
  var searchControl = new google.search.SearchControl();
  var webSearch = new google.search.WebSearch();

  searchControl.addSearcher(webSearch);
  searchControl.draw(document.getElementById("searchcontrol"));
  searchControl.setSearchCompleteCallback(this, searchComplete);

  searchControl.execute('Google')
}
google.setOnLoadCallback(OnLoad);
Notice that the SearchControl and searcher are automatically passed to the searchComplete function. When a search is complete, the searcher contains the results.

Using setSearchCompleteCallback on a single searcher (a.k.a. Raw Searcher) is slightly different. It looks like this:

function searchComplete(searcher) {
  for (var i=0; i < searcher.results.length; i++) {
    // Do whatever you want with the results
  }
}

function OnLoad() {
  var webSearch = new google.search.WebSearch();
  webSearch.setSearchCompleteCallback(this, searchComplete, [webSearch]);
  webSearch.execute('Google')
}
google.setOnLoadCallback(OnLoad);
In order to get the searcher object (and results) into the searchComplete function we have to pass it as a parameter in the setSearchCompleteCallback method. Each parameter in the array will be passed as an argument to the callback function.

If you are using one of the wizards (Blog Bar, News Bar etc.) then you will have to edit its Javascript file in order to get access to these results.

How do I see what users query?

Use the setSearchStartingCallback method if you are using a SearchControl. If you are using Raw Searchers you should create the input form with the google.search.SearchForm which has a setOnSubmitCallback method. These methods allow you to specify a function that will be called when a query is made -- then you can store what that query was. You can access the query in a Search Control with the third parameter that is passed into the callback and from the SearchForm with searchForm.input.value.

Here is some sample code for doing it with a Search Control:

function searchComplete(searchControl, searcher, query) {
  alert(query);
}
function OnLoad() {
  var searchControl = new google.search.SearchControl();
  var webSearch = new google.search.WebSearch();
  
  searchControl.addSearcher(webSearch);
  searchControl.draw(document.getElementById("searchcontrol"));
  searchControl.setSearchStartingCallback(this, searchComplete);
  searchControl.execute('Google')
}
google.setOnLoadCallback(OnLoad);

My SearchControl is displaying only one result, even if I set the result set size to large. What's wrong?

In stacked mode, the SearchControl offers what's called ExpandMode, which can be set to open or closed on a per-searcher basis. By default, ExpandMode is set to closed when a searcher is added to the control, resulting in only one result being displayed. To override this behavior, use a SearcherOptions object, as below:

var searchControl = new google.search.SearchControl();
var searcher = new google.search.WebSearch();
var options = new google.search.SearcherOptions();
options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
searchControl.addSearcher(searcher,options);
searchControl.draw(document.getElementById('my_element');


Licensing

What license is the sample code released under?

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

What are the restrictions on using sample code?

There are no restrictions on using it. You can use it to do whatever you like. Copy and paste it, use it whole, whatever you like. The only requirement is that you maintain the copyright notice that is there now.

If there are no restrictions, why do you have a license?

The default state of things in the world of copyright is that "if nobody has given you permission, you generally have no right to use it" (there are exceptions, this is just the general rule). In order to make it clear that we want people to reuse and share this sample code, we explicitly use a license that lets you do this.

Why not a simpler license then, why use the Apache license?

We use the Apache license over the BSD/MIT/etc for a simple reason: It grants you patent rights.