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.
Замечание: 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.
Пример 62-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():
|
Пример 62-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.
|
Замечание: 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!.
Пример 62-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. |
Пример 62-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.
|
Пред. | Начало | След. |
Introduction | Уровень выше | Design |
HIVE: All information for read only. Please respect copyright! |