Yahoo::Search::Result -- class representing a single result (single web page, image, video file, etc) from a Yahoo! search-engine query. (This package is included in, and automatically loaded by, the Yahoo::Search package.)
You never need to use this package directly -- it is loaded automatically by Yahoo::Search.
use
Result objects are created automatically when a Response object is created (when a Request object's Fetch method is called, either directly, or indirectly via a shortcut such as Yahoo::Search->Query().
Result
Response
Request
Fetch
Yahoo::Search->Query()
This table shows the methods available on a per-search-space basis:
Terms Related | Spell | | Local | | | News | | | | Video | | | | | Image | | | | | | Doc | | | | | | | | | | | | | | | Next [X] [X] [X] [X] [X] [X] [X] [X] Prev [X] [X] [X] [X] [X] [X] [X] [X] Response [X] [X] [X] [X] [X] [X] [X] [X] Request [X] [X] [X] [X] [X] [X] [X] [X] SearchSpace [X] [X] [X] [X] [X] [X] [X] [X] * I [X] [X] [X] [X] [X] [X] [X] . * i [X] [X] [X] [X] [X] [X] [X] . as_html [X] [X] [X] [X] [X] [X] [X] . as_string [X] [X] [X] [X] [X] [X] [X] . Data [X] [X] [X] [X] [X] [X] [X] . * Url [X] [X] [X] [X] [X] . . . * ClickUrl [X] [X] [X] [X] [X] . . . * Title [X] [X] [X] [X] [X] . . . TitleAsHtml [X] [X] [X] [X] [X] . . . Link [X] [X] [X] [X] [X] . . . * Summary [X] [X] [X] [X] . . . . SummaryAsHtml [X] [X] [X] [X] . . . . * CacheUrl [X] . . . . . . . * CacheSize [X] . . . . . . . * ModTimestamp [X] . . [X] . . . . * Width . [X] [X] . . . . . * Height . [X] [X] . . . . . * ThumbUrl . [X] [X] [X] . . . . * ThumbWidth . [X] [X] [X] . . . . * ThumbHeight . [X] [X] [X] . . . . ThumbImg . [X] [X] [X] . . . . ThumbLink . [X] [X] [X] . . . . * HostUrl . [X] [X] . . . . . * Copyright . [X] [X] . . . . . * Publisher . [X] [X] . . . . . * Restrictions . [X] [X] . . . . . * Type [X] [X] [X] . . . . . * Bytes . [X] [X] . . . . . * Channels . . [X] . . . . . * Seconds . . [X] . . . . . * Duration . . [X] . . . . . * Streaming . . [X] . . . . . * SourceName . . . [X] . . . . SourceNameAsHtml . . . [X] . . . . * SourceUrl . . . [X] . . . . * Language . . . [X] . . . . * PublishTime . . . [X] . . . . * PublishWhen . . . [X] . . . . * Address . . . . [X] . . . * City . . . . [X] . . . * State . . . . [X] . . . * Phone . . . . [X] . . . * Miles . . . . [X] . . . * Kilometers . . . . [X] . . . * Rating . . . . [X] . . . * MapUrl . . . . [X] . . . * BusinessUrl . . . . [X] . . . * BusinessClickUrl . . . . [X] . . . * AllMapUrl . . . . [X] . . . * Term . . . . . [X] [X] [X] TermAsHtml . . . . . [X] [X] [X] | | | | | | | | Doc | | | | | | | Image | | | | | | Video | | | | | News | | | | Local | | | Spell | | Related | Terms
Those items marked with a '*' are also available via the Data method
Data
Returns the next Result object from among the list of result objects that are part of one Response object.
Returns nothing when called on the last result in a response, unless auto-continuation is turned on, in which case the next set is automatically fetched and the first Result from that set's Response is returned.
An optional defined boolean argument turns auto-continuation on (true) or off (false). If the argument is not defined, or not provided, the value for the original request's AutoContinue option (default off) is used.
AutoContinue
Note that using auto-continuation can be dangerous. See the docs for NextResult in Yahoo::Search::Response.
NextResult
The opposite of Next. No auto-continuation feature.
Next
Returns the Response object of which this Result object is a part.
Returns the original Request object from which this Result object's Response was derived.
Returns a string which indicates the search space of the original query that this result was part of. (That is, it returns Doc, Image, News, Local, or Video.)
Doc
Image
News
Local
Video
It's the same as
$Result->Request->SearchSpace;
The first (lower-case letter "i") returns the zero-based ordinal of the result from among those in the current Response.
The latter (upper-case letter "I") returns the zero-based ordinal of the result from among all search results that might be returned by Yahoo! for the given query.
For example, after
my @Results = Yahoo::Search->Results(Image => "Briteny", AppId => "my app id", Start => 45, Count => 15);
the $Results[0] result object has an I of 45 (the 45th result of all "Briteny" image results) and an i of 0 (the 0th result among those returned this time.)
$Results[0]
I
i
In either case, if an optional argument is given and is true, it is used as a separator every three digits. In the US, one would use
$Result->I(',')
to return "1,234" where
$Result->I()
would return "1234".
Returns a string of HTML that represents the result, as appropriate to the result's query search space.
There are many ways one may wish to display query results -- this method returns one display that the author finds useful. It may come in useful for quick prototyping of web applications, e.g.
sub ShowRelated { print join "<hr>", map { $_->as_html } Yahoo::Search->Results(@_); }
(Also see Yahoo::Search->HtmlResults)
Yahoo::Search->HtmlResults
The HTML returned by as_html contains class references, thereby allowing the look-and-feel to be easily adjusted. Here's a style sheet that makes Image search results look palatable.
as_html
<style> .yResult { display: block; border: #CCF 3px solid ; padding:10px } .yLink { } .yTitle { display:none } .yImg { border: solid 1px } .yUrl { display:none } .yMeta { font-size: 80% } .ySrcUrl { } .ySum { font-family: arial; font-size: 90% } </style>
Bugs: English-centric
Returns a textual representation of the Result, which may be useful for quick prototyping or debugging.
Returns a list of key/value pairs containing the fundamental data for the result (those items marked with '*' in the table at the start of this document).
my %Data = $Result->Data;
Url returns the raw url of the item (web page, image, etc.), appropriate for display to the user.
Url
ClickUrl returns a url appropriate for the href attribute of a link.
ClickUrl
In some cases, the two return the same url.
As with all Result-object methods which return a url of some sort, you can provide a single argument such as href and receive a string such as href="..." appropriate to be used directly in html. For example,
href
my $HREF = $Result->ClickUrl('href'); print "<a $HREF>click</a>";
is preferable to
my $url = $Result->ClickUrl; print "<a href='$url'>click</a>";
since the latter would break if $url contains a singlequote.
$url
Title returns the raw title text associated with the result. If an optional argument is provided and is true, the title text is returned as html.
Title
TitleAsHtml is the same as
TitleAsHtml
$Result->Title(1)
Returns a link made from the ClickUrl and the Title, with class "yLink", e.g.
<a class=yLink href='$URL'>$TITLE</a>
Like Title and TitleAsHtml, but for the summary associated with the result.
(Appropriate for Doc search results)
CacheUrl returns the url of the document in the Yahoo! cache. See the documentation for the Url method for information on the one-argument version of this method.
CacheUrl
CacheSize returns the size (as a string like "22k").
CacheSize
(Appropriate for Doc and News search results)
The Unix timestamp of the Last-Modified time associated with the the url when it was last checked by Yahoo!'s backend crawlers.
(Appropriate for Image and Video search results)
The width and height (in pixels) of the image or video.
(Appropriate for Image, Video, and News search results)
The url of a thumbnail image, and its width and height.
(Note: few News results have a thumbnail, but some do.)
See the documentation for the Url method for information on the one-argument version of ThumbUrl.
ThumbUrl
Returns a <img> tag representing the thumbnail image, e.g.
<img>
<img class=yImg src='$IMGURL' width=$WIDTH height=$HEIGHT>
Returns a link from the thumbnail to the ClickUrl of the result, e.g.
<a class=yLink href='$CLICKURL'> <img class=yImg src='$IMGURL' width=$WIDTH height=$HEIGHT> </a>
Returns the url of the web page containing a link to the image/video item that the Result represents.
See the documentation for the Url method for information on the one-argument version of this method.
(<Appropriate for Doc, Image, and Video search results>)
Returns a string representing the file type of the item to which $Result->Url points. For Doc searches, the MIME type (e.g. "text/html") is returned.
$Result->Url
For other search spaces, here are the possible return values:
Video: avi flash mpeg msmedia quicktime realmedia Image: bmp gif jpg png.
Yahoo! Search derives these Video/Image Type value by actually inspecting the file contents, and as such it is more reliable than looking at the file extension.
Type
(<Appropriate for Image and Video search results>)
Returns any copyright notice associated with the result. If an optional argument is provided and is true, the copyright text is returned as html.
(<Appropriate for Image, and Video search results>)
Returns any publisher information (as a string) associated with the result. If an optional argument is provided and is true, the publisher information is returned as html.
A (possibly zero-length) string containing zero or more of the following space-separated words:
noframe noinline
See Yahoo!'s web site (http://developer.yahoo.net/) for information on them.
(Appropriate for Image, and Video search results)
The size of the image/video item, in bytes.
(Appropriate for Video search results)
Returns the number of channels in the audio, if known. Examples are "1", "2", "4.1", "5.1", etc....
Returns the duration of the video clip, if known, in (possibly fractional) seconds.
Returns a string representing the duration of the video clip, if known, in the form of "37 sec", "1:23", or "4:56:23", as appropriate.
Returns "1" if the multimedia is streaming, "0" if not. If not known, an empty list is returned.
(Appropriate for News search results)
The main url of the news provider hosting the article that the Result refers to.
Similar to Title and TitleAsHtml, but the name of the organization associated with the news article (and, by extension, with SourceUrl).
SourceUrl
A code representing the language in which the article is written (e.g. "en" for English, "ja" for Japanese, etc.). See the list of language codes at perldoc Yahoo::Search.
perldoc
PublishTime is the Unix time associated with the article, e.g.
PublishTime
print "Published ", scalar(localtime $Result->PublishTime), "\n";
PublishWhen gives a string along the lines of
PublishWhen
3h 25m ago (if less than 12 hours ago) Tue 9:47am (if less than 5 days ago) Sat, Dec 25 (if less than 100 days ago) Sat, Dec 25, 2004 (if >= 100 days ago)
Bug: PublishWhen is English-centric.
(Appropriate for Local search results)
Location and Phone number for the business that the Result refers to.
The distance (in miles and kilometers) from the location used to make the query to the location of this result.
Returns the rating associated with the result, if there is one. If there is a rating, it is from 1 (lowest) to 5 (highest) in 0.5-sized steps. If not, nothing is returned.
MapUrl is a url to a Yahoo! Maps map showing the business' location.
MapUrl
AllMapUrl is a url to a Yahoo! Maps map showing all the businesses found in the same result-set that the current Result was part of.
AllMapUrl
See the documentation for the Url method for information on the one-argument versions of these methods.
The business' home page, if available. BusinessUrl is appropriate for display, while BusinessClickUrl is appropriate for the href of a link.
BusinessUrl
BusinessClickUrl
(Appropriate for Spell, Related, and Terms search results)
Term returns the term associated with the result. If an optional argument is provided and is true, the term text is returned as html.
Term
TermAsHtml is the same as
TermAsHtml
$Result->Term(1)
Copyright 2007 Yahoo! Inc.
Jeffrey Friedl (jfriedl@yahoo.com)
1 POD Error
The following errors were encountered while parsing the POD:
=cut found outside a pod block. Skipping to next block.
To install Yahoo::Search, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Yahoo::Search
CPAN shell
perl -MCPAN -e shell install Yahoo::Search
For more information on module installation, please visit the detailed CPAN module installation guide.