The following sections provide you with examples of using the different feature sets of Services_Yahoo. Currently this includes documentation for the interfaces to Yahoo! Search and Content Analysis.
All public methods in Services_Yahoo have in common that exceptions will be raised when something goes wrong. This is why try { ... } catch { } blocks are wrapped around all examples.
Note: The examples are designed to be run from a command line shell. If you would like to test them in a web browser you should replace \n with <br /> for better readability.
The following examples will communicate with Yahoo! Search.
Example 60-1. Web search: Listing results This snippet issues a search query for the term Steve Fossett to Yahoo! Search. For each result in the returned result set the title is printed.
By default 10 results are returned per request. This number can be modified using the method setResultNumber():
|
Example 60-2. Web search: Result details This code again queries Yahoo! Search for Steve Fossett, but this time the details of the first result in the result set are printed.
|
Note: In order to query the Image, News, Video or Local search, one only needs to replace the argument "web" in the call of the factory() method with one of "image", "news", "video", or "local".
The following examples will show you how to use the Content Analysis Services provided by Yahoo!.
Example 60-4. Term Extraction Service The Term Extraction service provides a list of significant words or phrases extracted from a larger content.
It is possible to skip the call to setQuery(). The parameter set by this method is intended to help the engine with the extraction process, but it is not stricly required. |
Example 60-5. Spelling Suggestion Service The Spelling Suggestion service provides a suggested spelling correction for a given term. The following code queries Yahoo for a spelling suggestion for the term "madnna". The service will return exactly one result, but currently there is no way to avoid looping through the $results.
|