Re: Google Search

Chirag Bhavsar replied to touseef ahmed at 12-May-08 01:16

Hi! ahmed

Below is the procedure to include the google in the asp.net application for search.

 

Procedure

Now that we've looked at what the form does, let's take a look at the steps involved in coding it. There are four main steps:

  • Reference the Web service
  • Create the function for doing the search
  • Create the function for doing the cache size check
  • Create the function for calling the spell check

Referencing the Google Web Service

Here are the steps to reference the Google Web service:

  1. Create a new Windows Forms project.
  2. Right-click on the project.
  3. Select Add Web Reference.
    Note   The Add Web Reference option is just like the Visual Basic 6 Add Reference, with the exception that instead of having access to all the methods of a COM component, you now have access to an XML Web service that is sitting on a different network. Better yet, this access is fully typed, and Intellisense is triggered just like any local object.
  4. Type the location of the web service description (http://api.google.com/GoogleSearch.wsdl) in the Address text box.
  5. Click on the Add Reference button to import the Web service definition.
  6. Once it is imported, go to the Solution Explorer and open the Web References node on the tree.
  7. Rename the reference to Google by right-clicking on it and picking Rename.
  8. Draw the form shown above.

Add the code to each button. Double-clicking on each button (just like Visual Basic 6) provides access to the method that is run when the click event fires. Let's take a look at each of these in turn.

Performing a Google Search

Looking at the code of the btnSearch_Click method in Listing 1, we can see that a new GoogleSearchService object was created. In the next line, a new GoogleSearchResult object was created and the new Visual Basic .NET capability of declaring and creating the object in one line was used. In Visual Basic .NET, the two following snippets are equivalent:

Dim x As String = "Hello"

and

Dim x As String
x = "Hello"

After the result object (created by passing a Google license key, search text, and other parameters to the search object) is created, the estimatedTotalResultsCount property is used to fill the label. In four lines of code, a procedure across the web was called, a Google search was performed, and the number of results was posted.

This example is a simple use of the search service. To learn more about the parameters to the search request and the data returned, see the reference documentation from Google.

' Create a Google Search object.
Dim s As New Google.GoogleSearchService()
' Invoke the search method.
Dim r As Google.GoogleSearchResult = 
   s.doGoogleSearch(txtLicenseKey.Text, txtSearchTerm.Text, 0, 1, _
   False, "", False, "", "", "")
' Extract the estimated number of results for the search and display it
Dim estResults As Integer = r.estimatedTotalResultsCount
lblSearchResults.Text = CStr(estResults)

 

for the detailed information on this you may refer following links:

http://msdn.microsoft.com/en-us/library/aa289493(VS.71).aspx

http://code.google.com/apis/soapsearch/api_faq.html

the second link contains everything related to using and trouble shooting related to GOOGLE APIs


Click here to sign in and reply. You could earn money via our $500 contest just for being helpful.
  Google search code.. - touseef ahmed  11-May-08 02:07 2:07:01 AM
      using google web service - santhosh kapa  11-May-08 02:26 2:26:39 AM
      Google API - sundar k  11-May-08 02:41 2:41:58 AM
      Sample Coding - Aravind Kumar  12-May-08 12:01 12:01:45 AM
      Re: Google Search - Chirag Bhavsar  12-May-08 01:16 1:16:30 AM
View Posts