Search results empty and cursor null

21 views
Skip to first unread message

Shaoxuan Zhang

unread,
Nov 6, 2009, 1:57:47 AM11/6/09
to Google AJAX APIs
Hi all,

I am trying to use Google search API to get the estimated result of
some term in my application. The js code looks like:

<script type="text/javascript">
var webSearch;
function getQueryReturnCount(query) {
webSearch = new google.search.WebSearch();
webSearch.execute(query);
return webSearch.cursor.estimatedResultCount;
}
</script>

Then in the page

<script type="text/javascript">
document.write("(" + getQueryReturnCount(<?php echo('"'.
$topissue.'"');?>) + ")");
</script>

to show the result.

But this code it always gives an error saying the cursor object is
null. I also check the results array, and it is always empty.

Can you please help me find out why the searcher always fail to
retrieve the search results?

BTW: There is also a search div in the same page, using the example
code after getting the API key, and that searcher works fine.

Jeremy Geerdes

unread,
Nov 6, 2009, 6:48:28 AM11/6/09
to google-ajax...@googlegroups.com
You can't access the cursor property immediately after running
execute. You have to use the searcher's setSearchCompleteCallback
method to set up a callback which will be run when the search has
returned from Google.

One thing that you should note is that the estimatedResultCount
property is notoriously inaccurate and variable. It should not be used
for anything mission-critical.

Jeremy R. Geerdes
Effective website design & development
Des Moines, IA

For more information or a project quote:
http://jgeerdes.home.mchsi.com
http://jgeerdes.blogspot.com
http://jgeerdes.wordpress.com
jgee...@mchsi.com

Unless otherwise noted, any price quotes contained within this
communication are given in US dollars.

If you're in the Des Moines, IA, area, check out Debra Heights
Wesleyan Church!

And check out my blog, Adventures in Web Development, at http://jgeerdes.blogspot.com
!

Shaoxuan Zhang

unread,
Nov 6, 2009, 9:27:07 PM11/6/09
to Google AJAX APIs
When I set a function (assume it call funcA) using the
setSearchCompleteCallback method how should I return the result?
Should it be returned in funcA? Then will the result be returned to
the point where getQueryReturnCount() method is called?

Thanks,
Shaoxuan

On Nov 6, 1:48 am, Jeremy Geerdes <jrgeer...@gmail.com> wrote:
> You can't access the cursor property immediately after running  
> execute. You have to use the searcher's setSearchCompleteCallback  
> method to set up a callback which will be run when the search has  
> returned from Google.
>
> One thing that you should note is that the estimatedResultCount  
> property is notoriously inaccurate and variable. It should not be used  
> for anything mission-critical.
>
> Jeremy R. Geerdes
> Effective website design & development
> Des Moines, IA
>
> For more information or a project quote:http://jgeerdes.home.mchsi.comhttp://jgeerdes.blogspot.comhttp://jgeerdes.wordpress.com
> jgeer...@mchsi.com
>
> Unless otherwise noted, any price quotes contained within this  
> communication are given in US dollars.
>
> If you're in the Des Moines, IA, area, check out Debra Heights  
> Wesleyan Church!
>
> And check out my blog, Adventures in Web Development, athttp://jgeerdes.blogspot.com
>   !

Jeremy Geerdes

unread,
Nov 6, 2009, 9:29:44 PM11/6/09
to google-ajax...@googlegroups.com
No, it won't be returned to the same point. This is an inherent part
of AJAX technologies. Everything that depends on that count will have
to be called after the callback.

Jeremy R. Geerdes
Effective website design & development
Des Moines, IA

For more information or a project quote:
Unless otherwise noted, any price quotes contained within this
communication are given in US dollars.

If you're in the Des Moines, IA, area, check out Debra Heights
Wesleyan Church!

And check out my blog, Adventures in Web Development, at http://jgeerdes.blogspot.com
!

Shaoxuan Zhang

unread,
Nov 6, 2009, 9:43:54 PM11/6/09
to google-ajax...@googlegroups.com
Then how to make that value displayed on the page?

I also want to sort the terms according to that count.
Reply all
Reply to author
Forward
0 new messages