Google web search API not returning more than 4 results

387 views Asked by At

I am trying to implement a meta search engine which requires google web search api. I am trying to implement Google web search API in java script. But I am not getting more than 4 results.

Following is code:

<HTML>
    <HEAD>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
        <script src="http://www.google.com/jsapi? type="text/javascript"></script>
        <script type="text/javascript">google.load('search','1');</script>
        <TITLE>Quick Data Search</TITLE>

    </HEAD>
    <body>
        <div id="page-wrap">
        <div style="height:30px"></div>

        <center>

            <input type="text" title="Quick Data Search" id="searchbox" name="searchbox"/>
         </center>


        <br/><br/>
        <div id="search-content">
        <div class="content" style="width:400px; display:inline">
    <div class="header">Web</div>
    <div class="data" id="web-content"></div>
    </div>
</div>

</body>
<SCRIPT>

    var webSearch;
    var lastSearch=0;
    $(function()
    {
    webSearch=new google.search.WebSearch();
    webSearch.setSearchCompleteCallback(this,webSearchComplete,[webSearch,lastSearch]);
    var hash=window.location.hash;
    if(hash!=""&&hash.length>0){

    if(hash.substr(0,3)=='#q='){
        var query=hash.substr(3,hash.length-3);
        $('#searchbox').removeClass('text-label').val(query);
        search(query);
    }
}
$('#searchbox').focus();});

function webSearchComplete(searcher,searchNum){
    var contentDiv=document.getElementById('web-content');
    contentDiv.innerHTML='';
    var results=searcher.results;
    var newResultsDiv=document.createElement('div');
    newResultsDiv.id='web-content';
    for(var i=0;i<results.length;i++){
        var result=results[i];
        var resultHTML='<div style="height:70px; margin-top:5px;">';
        resultHTML+='<a href="'+result.unescapedUrl+'" target="_blank">
        <b>'+result.titleNoFormatting+'</b></a><br/>'+result.content+'<div/>';
        newResultsDiv.innerHTML+=resultHTML;
    }
    contentDiv.appendChild(newResultsDiv);
}

$('#searchbox').keyup(function(){
    var query=$(this).val();search(query);
});
function search(query){
    if(query.length>0){
        $("#search-content").show();
        document.title=query+" | Quick Data Search";
        window.location.hash="q="+query;
}
else{
    document.title="Quick Data Search ";$("#search-content").hide();
}
webSearch.execute(query);newsSearch.execute(query);
}
$('#searchbox').each(function(){
$(this).addClass('text-label');
$(this).keyup(function(){
    if(this.value.length==1){
        $(this).removeClass('text-label');
    }
    if(this.value==''){
        $(this).addClass('text-label');
    }
});
});

</SCRIPT>

Please Help.......

1

There are 1 answers

0
anonman On

try the code below

<script src="//www.google.com/jsapi?rsz=[results]"></script>

[results] - number ranging from 1 to 8 - number of results to return