First, introduction
The Google search engine provides SOAP-based Web Service. This means that different development languages can use this service. In addition, Google provides a set of Java API interfaces for accessing Web Serivce, which makes the development of Web Serivce. The process of Google Searching features is very easy. Developers can embed Google's search capabilities into their applications. This article will show how to use these Java APIs, and how to use Google's Web Service.
At present, Google's API is still in a beta test phase, so there are some restrictions on the API. For example, using these APIs need to apply for an account. For free applications, in order to prevent improper use of developers, limit each account, you can only query 1000 times a day. At present, Google has not yet proposed formal operational models and charging methods.
Google API currently provides three services, as follows:
1) Search service. The user submits a search content request. The Google server will find more than 2 billion web content, and will return to the user to the user's demand. Generally, this processing only takes a few seconds.
2) Cache Service (Cache). The user submits a URL, and the Google server will return the searcher to the latest record of the URL. In this way, users can easily reuse Google's search results.
3) Spell check. This feature is used to check if the user's query request is valid. The user submits an inspection content, the Google server will return a valid, closest to the query request returned, and the query request will comply with Google's query rules.
Second, the relevant preparation work
In order to develop Java-based programs, we need to work as follows.
1) Establish a Java development environment, Java SDK 1.3.1 or updated version. Related address http: .// java.sun.com/j2se
2) Download the Google API's JAR file, Googleapi.jar. Developers can download at http://www.google.com/apis.
3) Apply for Google access account, current Google supports free application, users need to use an Email account to get new accounts. Note that the current free account supports 1000 maximum queries per day. Application Address: http://www.google.com/apis.
4) (Optional) If the user needs to send SOAP requests directly through the Java program, the developer needs to download the relevant Java package, JAXM. Download address: http://java.sun.com/xml
Third, SOAP use
Google provides SOAP-based Web Service, so users can submit SOAP query requests to Google Server, and then the Google server will process these requests and return the results of the SOAP format. Here is a query request and query results.
Query: For example, there is a query request, the request type is a search, the query is "World Cup", the account is "123456789", as follows for the query.
XML Version = '1.0' encoding = 'UTF-8'?>
XMLns: soap-env = "http://schemas.xmlsoap.org/soap/envelop/" XMLns: xsi = "http://www.w3.org/1999/xmlschema-instance" XMLns: xsd = "http://www.w3.org/1999/xmlschema"> SOAP-ENV: EncodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"> ns1: dogooglesearch> Soap-env: body> Soap-env: envelope> Query results: If we perform the above query, you can get the following query results. Among them, the results of the query have a total of about 266,000 records, and the usage time is 0.125012 seconds. The ITEM mark represents a result of a query, in the first query result, the website's URL is http://www.fifaworldcup.com. This example only lists a query result. XML Version = "1.0" encoding = "UTF-8"?> XMLns: xsi = "http://www.w3.org/1999/xmlschema-instance" XMLns: xsd = "http://www.w3.org/1999/xmlschema"> XMLns: ns1 = "URN: Googlesearch" SOAP-ENV: EncodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"> 2660000 EstimatedTotalResultscount> XMLns: ns2 = "http://schemas.xmlsoap.org/soap/encoding/" XSI: Type = "NS2: Array" NS2: ArrayType = "NS1: DirectoryCategory [0]"> DirectoryCategories> XMLns: ns3 = "http://schemas.xmlsoap.org/soap/encoding/" XSI: Type = "NS3: Array" NS3: ArrayType = "NS1: ResulTelement [10]"> DirectoryCategory> True relatedInformationPresent> The Official Site from FIFA, Made by Yahoo. Daily News Updates and Loads of Relevant Information. summary> http://www.fifaworldcup.com Url> 2002 FIFA World b> b> CUP b> (tm) title> item> ... resultelements> Science fiction searchQuery> returnide> ns1: DogoogleSearchResponse> Soap-env: body> Soap-env: envelope> Fourth, use Google API Google provides a Java-based API to directly access the Google Server directly to improve the development efficiency of developers. The API wraps Google's Web Service, which is more convenient than Web Service. The API package mainly includes the following classes: Googlesearch: This class encapsulates access to Google Servers, supports search and cache (cache) features. GooglesearchDirectoryCategory: Represents a classification directory in Google Googlesearch Fault: This class is an Exception of an subclass for indicating an error used by the API. GooglesearchResult: This class encapsulates the results of the search. GooglesearchResulTelement: This class represents each record in the search results. The following is an example source code for a simple query, the query request is "World Cup", the query account is "123456789". This example will print the query results. If the user needs to parse the query result, you can use GooglesearchResult and GooglesearchResulTelement classes. Import com.google.soap.Search. *; Import java.io. *; Public class googleapitest { Public static void main (String [] args) { String ClientKey = "123456789"; String query = "Word Cup"; // Create a Google Search Object, Setur Authorization Key Googlesearch s = new googlesearch (); S.SetKey (ClientKey); Try { S.SetQueryString (Query); GooglesearchResult r = s.dosearch (); System.out.Println ("Google Search Results) T.toString ()); } catch (goglesearchfault f) { System.out.println ("THE CALL TO The Google Web Apis Failed:" f.toString ()); } } } Five, summary The Google search engine provides simple features of search, cache, and spelling, can be used in different platforms, different languages through Web Service, to simplify SOAP development, Google also provides Java API packaging SOAP services, which is greatly improved. Java programmer development efficiency. With the search content, the form of form is rich, more developers can use this technology to extend the application of the application in their own application. -------------------------------------------------- ------------------------------------- reproduced "World CUP" q>