getWebSearcher - official?/documented?

45 views
Skip to first unread message

yotam

unread,
Aug 17, 2011, 7:28:37 PM8/17/11
to google-ajax...@googlegroups.com, yotam....@gmail.com
When using custom search control by say:

   var my_cse_id = '012345678909876543210:qwertytrewq';
   var my_cse = new google.search.CustomSearchControl(my_cse_id);

if in addition one wants to programmatically get results of a user query,
using the 
   setSearchCompleteCallback(...)
method, then one needs to get the searcher handle.
By peeking at the properties of my_cse, I found that it is possible
to successfully use:
   var my_searcher = my_cse.getWebSearcher();
But I could not find whether this
   getWebSearcher()
is documented, or even actually a part of an official API.
Is it?

Jeremy Geerdes

unread,
Aug 19, 2011, 11:46:23 AM8/19/11
to google-ajax...@googlegroups.com
Good question. I don't see it in the official documentation, but it sounds like something that probably won't change. That is, until the control itself is discontinued. Unfortunately, the CustomSearchControl you're trying to use is dependent on Google's Web Search API, which has been deprecated. You can still use the CustomSearchControl for now, but Google has removed the official documentation from their site (I found an archived version on another site) and is directing people to use the Custom Search Web Element, which is essentially the same thing but within an iframe so that, when they change the code, it will continue to work. The downside of the Web Element is that it is not nearly as customizable as doing it with your own JS.

All this to say: I would not hesitate to use the getWebSearcher() method in your script. I WOULD, however, hesitate to use the CustomSearchControl if at all possible.

Jeremy R. Geerdes
Generally Cool Guy
Des Moines, IA

For more information or a project quote:

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

--
You received this message because you are subscribed to the Google
Groups "Google AJAX APIs" group.
To post to this group, send email to
google-ajax...@googlegroups.com
To unsubscribe from this group, send email to
google-ajax-searc...@googlegroups.com
To view this message on the web, visit
https://groups.google.com/d/msg/google-ajax-search-api/-/GAy-zMjs8KoJ
For more options, visit this group at
http://groups.google.com/group/google-ajax-search-api?hl=en?hl=en

omr

unread,
Aug 20, 2011, 3:13:50 AM8/20/11
to Google AJAX APIs
@Jeremy:

IIUC, the CustomSearchControl is still supported, as it remains
fundamental to the current Custom Search Element JS API. Here's some
current documentation:

http://code.google.com/apis/customsearch/docs/js/cselement-devguide.html

http://code.google.com/apis/customsearch/docs/js/cselement-reference.html

But see notes below regarding setSearchCompleteCallback.


__________________________________________________


@yotam:

Currently, IIUC, you can obtain the "searcher" as the 2nd argument to
the callback function that you assign via setSearchCompleteCallback or
setSearchStartingCallback.

NOTE: Usage shown below is NOT consistent with the CS Element JS
Reference's current description of setSearchCompleteCallback. (I
suspect perhaps that documentation may be in error?) Nonetheless, the
usage shown below still works for me at this time.

If you use setSearchCompleteCallback (on a CustomSearchControl) as
shown here, the search-completion callback function takes two
arguments: the search-control and the searcher.

customSearchControl.setSearchCompleteCallback(
this,
function(control, searcher) {
// ... etc. ...
});

If you use setSearchStartingCallback, the search-starting callback
function takes 3 arguments: the search-control, the searcher, and the
query string.

customSearchControl.setSearchStartingCallback(
this,
function(control, searcher, query) {
// ... etc. ...
});


NOTES:

The current CS Element JS Reference (2nd link above) documents the
setSearchStartingCallback and setSearchCompleteCallback methods. As I
mentioned, the usage that I've shown above is NOT consistent with the
CS Element JS Reference's current description of
setSearchCompleteCallback (I suspect a documentation error).

I don't know if the CS Element's implementation of those arguments may
be expected to change in the future (could someone from Google comment
on that)?

YMMV.

-- omr
Reply all
Reply to author
Forward
0 new messages