Reimers.dk

.NET, AJAX and Google APIs brought together
Welcome to Reimers.dk Sign in | Join | Help
in Search

Jacob Reimers Weblog

Created a Project to Consume Google's AJAX Search API

Yesterday I wrote about Google's translation API and showed how you can build a simple class structure to consume that web service.

I got caught by the other REST services offered by Google in connection with their AJAX Search API, so I wrote up a project to consume the various search services. You can find the C# source files here. The project makes it possible for you to perform Google searches from your web server or, even better, in your Silverlight project (I haven't actually checked Google's cross domain policy, but hopefully they are going to support it).

The core of the project are the various SearchResponse classes. One for each search type since they all have differing data properties. These classes are used in the generic class AjaxSearch which will return a generic ResultSet for the various searches. The ResultSet class not only holds a generic list of the SearchResponses but also a ResponseCursor which holds meta data about the search.

To perform a search all you need to do is call:

C#

ResultSet<WebSearchResult> mySearch = AjaxSearch.WebSearch(
"http://www.mydomain.com",
"Reimers.dk Google API",
SafetyFiltering.Off,
"MyGoogleDeveloperKey",
CultureInfo.CurrentCulture,
ResultSize.Large);

The search method creates the request URL and passes it to the private DoSearch method which performs the actual HttpWebRequest and deserializes the response using a JavaScriptSerializer.

One thing that is missing from the project in its present state is result paging.

You are free to use the source code in your private or commercial projects, but please don't forget to mention where you got the code from.

Published 19. juni 2008 21:12 by jjrdk
Filed under: ,

Comments

 

samtse said:

i wrote the same thing (google ajax web search - very quickly) using the json library it works well enough..  but the results pages seem to return a lot of duplicates so it takes a lot (55 seems to be the max) of 8-url result pages to get  some unique urls...    so to investigate  i was browsing for ajax documentation again when i stumbled across this (your library) i set up a test project to use your code to realise that it only gets a single resultset...   so no answers to my questiopns there (though your code is much more nicely written than my deadline driven short-termist tosh)   if you've done anything with obtaining more than one page of results or have any info on how it works i'd be mucho grateful indeed...   thx...  jerome.

oktober 24, 2008 14:25
 

jjrdk said:

There is a documented start parameter that you could use. All you would need to do was to add that option to the code and change the request urls to use that parameter. This way you can page through your result sets.

oktober 24, 2008 20:35
 

greenlightyears said:

I tried tu run the project but I can't find Reimers.Utils.

Can you tell me where can I find the library?

juni 18, 2009 04:12
 

jjrdk said:

I believe the reimers.utils using statement is an oversight. You should be able to delete it safely.

juni 18, 2009 10:21
 

greenlightyears said:

Thanks.

Just one more question. Now that it's working, even with a Large result size I only get 8 or so results. I wonder if it just happens to me or is "general happening"?

Anyway, nice work.

juni 18, 2009 11:26
 

jjrdk said:

Isn't this the same question as was asked above?

juni 18, 2009 12:39
 

greenlightyears said:

I only read the begining of that comment, and gave up on it at "duplicates".

My apologies.

juni 18, 2009 20:35
Anonymous comments are disabled