1

I've implemented Google site search / Custom search for my website and it is all working and results are formatted and paging fine. But it never returns a count of how many results it found like it does when you search on Google About 1,660,000 results (0.16 seconds)

I was wondering if anyone had found anything to do this i can't find anything in there documentation.

<div id="cse" style="width: 100%;">Loading</div>
        <script src="http://www.google.com/jsapi" type="text/javascript"></script>
        <script type="text/javascript">
            google.load('search', '1', {language : 'en'});
            google.setOnLoadCallback(function() {
                var customSearchControl = new google.search.CustomSearchControl('GOOGLEIDGOESHERE');
                customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
                customSearchControl.setNoResultsString("No results found.")
                customSearchControl.draw('cse');   
            }, true);
</script>
<link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" />

1 Answer 1

2

You will need to use the SearchCompleteCallback and buried deep within the obfuscated javascript library, you will find the estimatedResultCount property. Here's a quick example that pops up an alert with the count. You can tailor this to meet your needs by using jquery to insert some html with the count in any format you like.

<div id="cse" style="width: 100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">

google.load('search', '1', {language : 'en'});
google.setOnLoadCallback(function() {
    var customSearchControl = new google.search.CustomSearchControl('GOOGLEIDGOESHERE');
    customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
    customSearchControl.setNoResultsString("No results  found.")
    customSearchControl.setSearchCompleteCallback(null, 
        function() { searchCompleteCallback(customSearchControl) });

    customSearchControl.draw('cse');   
}, true);


function searchCompleteCallback(customSearchControl) {

  alert(customSearchControl.e[0].g.cursor.estimatedResultCount);

}
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

wow thanks that was hidden nicely by them. Which documentation did you read to find this out?
this doesn't seem to work now, I wonder if they have hidden it again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.