views:

265

answers:

2

Hi Folks,

I'm wondering, is it possible to receive google results over their own ajax API in a way like, 100 results per page?

Without a visible search field, I'd like to get the results in the background to create a progression for some search phrases.

My basic question is, what are the restrictions of the google search api ?

--update--

is it possible to change language for a search with google api ? From the start on, it just delivers from .com in english

Kind Regards

--Andy

A: 

http://code.google.com/apis/ajaxsearch/documentation/reference.html#_class_GSearchControl This has information about the main controller class used. It appears that the following answers your question about result size:

.setResultSetSize(switchTo)

This method is called to select the number of results returned by each of the searchers. Note, this is not a scalar. It is an enumeration that indicates either a small number of results, or a large number of results. In the future, this method may be enhanced to support medium and extra large result sets. From the sample applications, you have probably seen the more/less twiddle control at the top of the search control. This method is used by that twiddle control.

switchTo - supplies en enumeration which indicates the desired number of search results to return for each configured searcher. Valid values include: google.search.Search.LARGE_RESULTSET - request a large number of results (typically 8 results) google.search.Search.SMALL_RESULTSET - request a small number of results (typically 4 results) google.search.Search.FILTERED_CSE_RESULTSET - request up to 10 results. This will only work for Web Search queries scoped to a Filter Custom Search engine, otherwise an error will be returned. returns - n/a

Gabriel
+4  A: 

The largest number of results you can get is 64, 8 per page of the searcher.

It is possible to combine all of these into one page, but it involves the searcher making 8 calls to the Google Ajax Search API.

Further, you will need to create your own function to render the results:

var s;
var page = 1;

google.load('search', '1', {'nocss' : true});
google.load('jquery', '1.4.2'); // optional

google.setOnLoadCallback(function() {
    // T&C's state you should display branding, create a <div id="branding"></div>
    google.search.Search.getBranding(document.getElementById('branding'));
    s = new google.search.WebSearch();
    s.setResultSetSize(google.search.Search.LARGE_RESULTSET);
    s.setSearchCompleteCallback(this, searchComplete, null);
    s.setNoHtmlGeneration();
});

function searchComplete() {
    if(s.results && s.results.length > 0) {
        var results = s.results;
        for(var i = 0; i < results.length; i++) {
            var result = results[i];
            // render the results
        }
        if(page < 8) {
            s.gotoPage(page);
            page++;
        }
    }
}

For information about how to render your results see: http://code.google.com/apis/ajaxsearch/documentation/reference.html#_class_GwebResult

To change the language, add the hl argument when including the script in web pages:

<script src="http://www.google.com/jsapi?hl=en" type="text/javascript"></script>

Finbarr
are you sure setting the hl works? I can set it to whatever I want, I receive the resultset always in my country language.
jAndy