.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "WWW::Search 3pm" .TH WWW::Search 3pm "2018-11-25" "perl v5.28.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" WWW::Search \- Virtual base class for WWW searches .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use WWW::Search; \& my $sEngine = \*(AqAltaVista\*(Aq; \& my $oSearch = new WWW::Search($sEngine); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This class is the parent for all access methods supported by the \&\f(CW\*(C`WWW::Search\*(C'\fR library. This library implements a Perl \s-1API\s0 to web-based search engines. .PP See \s-1README\s0 for a list of search engines currently supported, and for a lot of interesting high-level information about this distribution. .PP Search results can be limited, and there is a pause between each request to avoid overloading either the client or the server. .SS "Sample program" .IX Subsection "Sample program" Here is a sample program: .PP .Vb 9 \& my $sQuery = \*(AqColumbus Ohio sushi restaurant\*(Aq; \& my $oSearch = new WWW::Search(\*(AqAltaVista\*(Aq); \& $oSearch\->native_query(WWW::Search::escape_query($sQuery)); \& $oSearch\->login($sUser, $sPassword); \& while (my $oResult = $oSearch\->next_result()) \& { \& print $oResult\->url, "\en"; \& } # while \& $oSearch\->logout; .Ve .PP Results are objects of type \f(CW\*(C`WWW::SearchResult\*(C'\fR (see WWW::SearchResult for details). Note that different backends support different result fields. All backends are required to support title and url. .SH "SEE ALSO" .IX Header "SEE ALSO" For specific search engines, see WWW::Search::TheEngineName (replacing TheEngineName with a particular search engine). .PP For details about the results of a search, see WWW::SearchResult. .SH "METHODS AND FUNCTIONS FOR SEARCHERS" .IX Header "METHODS AND FUNCTIONS FOR SEARCHERS" .IP "new" 4 .IX Item "new" To create a new WWW::Search, call .Sp .Vb 1 \& $oSearch = new WWW::Search(\*(AqSearchEngineName\*(Aq); .Ve .Sp where SearchEngineName is replaced with a particular search engine. For example: .Sp .Vb 1 \& $oSearch = new WWW::Search(\*(AqYahoo\*(Aq); .Ve .Sp If no search engine is specified, a default (currently 'Null::Empty') will be chosen for you. .IP "version" 4 .IX Item "version" Returns the value of the \f(CW$VERSION\fR variable of the backend engine, or \&\f(CW$WWW::Search::VERSION\fR if the backend does not contain \f(CW$VERSION\fR. .IP "maintainer" 4 .IX Item "maintainer" Returns the value of the \f(CW$MAINTAINER\fR variable of the backend engine, or \f(CW$WWW::Search::MAINTAINER\fR if the backend does not contain \&\f(CW$MAINTAINER\fR. .IP "installed_engines" 4 .IX Item "installed_engines" Returns a list of the names of all installed backends. We can not tell if they are up-to-date or working, though. .Sp .Vb 6 \& use WWW::Search; \& my @asEngines = sort &WWW::Search::installed_engines(); \& local $" = \*(Aq, \*(Aq; \& print (" + These WWW::Search backends are installed: @asEngines\en"); \& # Choose a backend at random (yes, this is rather silly): \& my $oSearch = WWW::Search\->new($asEngines[rand(scalar(@asEngines))]); .Ve .IP "native_query" 4 .IX Item "native_query" Specify a query (and optional options) to the current search object. Previous query (if any) and its cached results (if any) will be thrown away. The option values and the query must be escaped; call \fBWWW::Search::escape_query()\fR to escape a string. The search process is not actually begun until \f(CW\*(C`results()\*(C'\fR or \&\f(CW\*(C`next_result()\*(C'\fR is called (lazy!), so native_query does not return anything. .Sp Example: .Sp .Vb 2 \& $oSearch\->native_query(\*(Aqsearch\-engine\-specific+escaped+query+string\*(Aq, \& { option1 => \*(Aqable\*(Aq, option2 => \*(Aqbaker\*(Aq } ); .Ve .Sp The hash of options following the query string is optional. The query string is backend-specific. There are two kinds of options: options specific to the backend, and generic options applicable to multiple backends. .Sp Generic options all begin with 'search_'. Currently a few are supported: .RS 4 .IP "search_url" 4 .IX Item "search_url" Specifies the base \s-1URL\s0 for the search engine. .IP "search_debug" 4 .IX Item "search_debug" Enables backend debugging. The default is 0 (no debugging). .IP "search_parse_debug" 4 .IX Item "search_parse_debug" Enables backend parser debugging. The default is 0 (no debugging). .IP "search_to_file \s-1FILE\s0" 4 .IX Item "search_to_file FILE" Causes the search results to be saved in a set of files prefixed by \s-1FILE.\s0 (Used internally by the test-suite, not intended for general use.) .IP "search_from_file \s-1FILE\s0" 4 .IX Item "search_from_file FILE" Reads a search from a set of files prefixed by \s-1FILE.\s0 (Used internally by the test-suite, not intended for general use.) .RE .RS 4 .Sp Some backends may not implement these generic options, but any which do implement them must provide these semantics. .Sp Backend-specific options are described in the documentation for each backend. In most cases the options and their values are packed together to create the query portion of the final \s-1URL.\s0 .Sp Details about how the search string and option hash are interpreted might be found in the search-engine-specific manual pages (WWW::Search::SearchEngineName). .RE .IP "gui_query" 4 .IX Item "gui_query" Specify a query to the current search object; the query will be performed with the engine's default options, as if it were typed by a user in a browser window. .Sp Same arguments as \f(CW\*(C`native_query()\*(C'\fR above. .Sp Currently, this feature is supported by only a few backends; consult the documentation for each backend to see if it is implemented. .IP "cookie_jar" 4 .IX Item "cookie_jar" Call this method (anytime before asking for results) if you want to communicate cookie data with the search engine. Takes one argument, either a filename or an HTTP::Cookies object. If you give a filename, WWW::Search will attempt to read/store cookies there (by passing the filename to HTTP::Cookies::new). .Sp .Vb 1 \& $oSearch\->cookie_jar(\*(Aq/tmp/my_cookies\*(Aq); .Ve .Sp If you give an HTTP::Cookies object, it is up to you to save the cookies if/when you wish. .Sp .Vb 3 \& use HTTP::Cookies; \& my $oJar = HTTP::Cookies\->new(...); \& $oSearch\->cookie_jar($oJar); .Ve .Sp If you pass in no arguments, the cookie jar (if any) is returned. .Sp .Vb 2 \& my $oJar = $oSearch\->cookie_jar; \& unless (ref $oJar) { print "No jar" }; .Ve .IP "date_from" 4 .IX Item "date_from" Set/get the start date for limiting the query by a date range. See the documentation for each backend to find out if date ranges are supported. .IP "date_to" 4 .IX Item "date_to" Set/get the end date for limiting the query by a date range. See the documentation for each backend to find out if date ranges are supported. .IP "env_proxy" 4 .IX Item "env_proxy" Enable loading proxy settings from environment variables. The proxy \s-1URL\s0 will be read from \f(CW$ENV\fR{http_proxy}. The username for authentication will be read from \f(CW$ENV\fR{http_proxy_user}. The password for authentication will be read from \f(CW$ENV\fR{http_proxy_pwd}. .Sp If you don't want to put passwords in the environment, one solution would be to subclass LWP::UserAgent and use \f(CW$ENV\fR{\s-1WWW_SEARCH_USERAGENT\s0} instead (see user_agent below). .Sp \&\fBenv_proxy()\fR must be called before the first retrieval is attempted. .Sp Example: .Sp .Vb 8 \& $ENV{http_proxy } = \*(Aqhttp://my.proxy.com:80\*(Aq; \& $ENV{http_proxy_user} = \*(Aqbugsbun\*(Aq; \& $ENV{http_proxy_pwd } = \*(Aqc4rr0t5\*(Aq; \& $oSearch\->env_proxy(\*(Aqyes\*(Aq); # Turn on with any true value \& ... \& $oSearch\->env_proxy(0); # Turn off with zero \& ... \& if ($oSearch\->env_proxy) # Test .Ve .IP "http_proxy" 4 .IX Item "http_proxy" Set up an \s-1HTTP\s0 proxy (for connections from behind a firewall). .Sp Takes the same arguments as \fBLWP::UserAgent::proxy()\fR. .Sp This routine should be called before calling any of the result functions (any method with \*(L"result\*(R" in its name). .Sp Example: .Sp .Vb 4 \& # Turn on and set address: \& $oSearch\->http_proxy([\*(Aqhttp\*(Aq,\*(Aqftp\*(Aq] => \*(Aqhttp://proxy:8080\*(Aq); \& # Turn off: \& $oSearch\->http_proxy(\*(Aq\*(Aq); .Ve .IP "http_proxy_user, http_proxy_pwd" 4 .IX Item "http_proxy_user, http_proxy_pwd" Set/get \s-1HTTP\s0 proxy authentication data. .Sp These routines set/get username and password used in proxy authentication. Authentication is attempted only if all three items (proxy \s-1URL,\s0 username and password) have been set. .Sp Example: .Sp .Vb 3 \& $oSearch\->http_proxy_user("myuser"); \& $oSearch\->http_proxy_pwd("mypassword"); \& $oSearch\->http_proxy_user(undef); # Example for no authentication \& \& $username = $oSearch\->http_proxy_user(); .Ve .IP "maximum_to_retrieve" 4 .IX Item "maximum_to_retrieve" Set the maximum number of hits to return. Queries resulting in more than this many hits will return the first hits, up to this limit. Although this specifies a maximum limit, search engines might return less than this number. .Sp Defaults to 500. .Sp Example: \f(CW$max\fR = \f(CW$oSearch\fR\->maximum_to_retrieve(100); .Sp You can also spell this method \*(L"maximum_to_return\*(R". .IP "maximum_to_return" 4 .IX Item "maximum_to_return" Synonym for maximum_to_retrieve .IP "timeout" 4 .IX Item "timeout" The maximum length of time any portion of the query should take, in seconds. .Sp Defaults to 60. .Sp Example: \f(CW$oSearch\fR\->timeout(120); .IP "login" 4 .IX Item "login" Backends which need to login to the search engine should implement this function. Takes two arguments, user and password. Return nonzero if login was successful. Return undef or 0 if login failed. .IP "logout" 4 .IX Item "logout" Backends which need to logout from the search engine should implement this function. .IP "approximate_result_count" 4 .IX Item "approximate_result_count" Some backends indicate how many results they have found. Typically this is an approximate value. .IP "approximate_hit_count" 4 .IX Item "approximate_hit_count" This is an alias for \fBapproximate_result_count()\fR. .IP "results" 4 .IX Item "results" Return all the results of a query as an array of WWW::SearchResult objects. .Sp Note: This might take a while, because a web backend will keep asking the search engine for \*(L"next page of results\*(R" over and over until there are no more next pages, and \s-1THEN\s0 return from this function. .Sp If an error occurs at any time during query processing, it will be indicated in the \fBresponse()\fR. .Sp Example: .Sp .Vb 6 \& @results = $oSearch\->results(); \& # Go have a cup of coffee while the previous line executes... \& foreach $oResult (@results) \& { \& print $oResult\->url(), "\en"; \& } # foreach .Ve .IP "next_result" 4 .IX Item "next_result" Call this method repeatedly to return each result of a query as a WWW::SearchResult object. Example: .Sp .Vb 4 \& while ($oResult = $oSearch\->next_result()) \& { \& print $oResult\->url(), "\en"; \& } # while .Ve .Sp When there are no more results, or if an error occurs, \fBnext_result()\fR will return undef. .Sp If an error occurs at any time during query processing, it will be indicated in the \fBresponse()\fR. .IP "seek_result($offset)" 4 .IX Item "seek_result($offset)" Set which result should be returned next time \&\f(CW\*(C`next_result()\*(C'\fR is called. Results are zero-indexed. .Sp The only guaranteed valid offset is 0, which will replay the results from the beginning. In particular, seeking past the end of the current cached results probably will not do what you might think it should. .Sp Results are cached, so this does not re-issue the query or cause \s-1IO\s0 (unless you go off the end of the results). To re-do the query, create a new search object. .Sp Example: .Sp .Vb 1 \& $oSearch\->seek_result(0); .Ve .IP "response" 4 .IX Item "response" Returns an HTTP::Response object which resulted from the most-recently-sent query. Errors can be detected like this: .Sp .Vb 4 \& if (! $oSearch\->response\->is_success) \& { \& print STDERR "Error: " . $oSearch\->response\->as_string() . "\en"; \& } # if .Ve .Sp Note to backend authors: even if the backend does not involve the web, it should return an HTTP::Response object. .IP "submit" 4 .IX Item "submit" This method can be used to submit URLs to the search engines for indexing. Consult the documentation for each backend to find out if it is implemented there, and if so what the arguments are. .Sp Returns an HTTP::Response object describing the result of the submission request. Consult the documentation for each backend to find out the meaning of the response. .IP "opaque" 4 .IX Item "opaque" This function provides an application a place to store one opaque data element (or many, via a Perl reference). This facility is useful to (for example), maintain client-specific information in each active query when you have multiple concurrent queries. .IP "escape_query" 4 .IX Item "escape_query" Escape a query. Before queries are sent to the internet, special characters must be escaped so that a proper \s-1URL\s0 can be formed. This is like escaping a \s-1URL,\s0 but all non-alphanumeric characters are escaped and and spaces are converted to \*(L"+\*(R"s. .Sp Example: .Sp .Vb 2 \& $escaped = WWW::Search::escape_query(\*(Aq+hi +mom\*(Aq); \& # $escaped is now \*(Aq%2Bhi+%2Bmom\*(Aq .Ve .Sp See also \f(CW\*(C`unescape_query()\*(C'\fR. \&\s-1NOTE\s0 that this is not a method, it is a plain function. .IP "unescape_query" 4 .IX Item "unescape_query" Unescape a query. See \f(CW\*(C`escape_query()\*(C'\fR for details. .Sp Example: .Sp .Vb 2 \& $unescaped = WWW::Search::unescape_query(\*(Aq%22hi+mom%22\*(Aq); \& # $unescaped eq q{"hi mom"} .Ve .Sp \&\s-1NOTE\s0 that this is not a method, it is a plain function. .IP "strip_tags" 4 .IX Item "strip_tags" Given a string, returns a copy of that string with \s-1HTML\s0 tags removed. This should be used by each backend as they insert the title and description values into the search results objects. .Sp \&\s-1NOTE\s0 that this is not a method, it is a plain function. .IP "is_http_proxy" 4 .IX Item "is_http_proxy" Returns true if proxy information is available. .SH "METHODS AND FUNCTIONS FOR BACKEND PROGRAMMERS" .IX Header "METHODS AND FUNCTIONS FOR BACKEND PROGRAMMERS" .IP "reset_search" 4 .IX Item "reset_search" Resets internal data structures to start over with a new search (on the same engine). .IP "is_http_proxy_auth_data" 4 .IX Item "is_http_proxy_auth_data" Returns true if all authentication data (proxy \s-1URL,\s0 username, and password) are available. .IP "agent_name($sName)" 4 .IX Item "agent_name($sName)" If your search engine rejects certain browser, you can trick it into thinking you're any browser type you want. See below under \fBuser_agent()\fR. .IP "agent_email($sName)" 4 .IX Item "agent_email($sName)" .PD 0 .IP "user_agent($NON_ROBOT)" 4 .IX Item "user_agent($NON_ROBOT)" .PD This internal routine creates a user-agent for derived classes that query the web. If any non-false argument is given, a normal LWP::UserAgent (rather than a LWP::RobotUA) is used. .Sp Returns the user-agent object. .Sp If a backend needs the low-level LWP::UserAgent or LWP::RobotUA to have a particular name, \f(CW$oSearch\fR\->\fBagent_name()\fR and possibly \&\f(CW$oSearch\fR\->\fBagent_email()\fR should be called to set the desired values *before* calling \f(CW$oSearch\fR\->\fBuser_agent()\fR. .Sp If the environment variable \s-1WWW_SEARCH_USERAGENT\s0 has a value, it will be used as the class for a new user agent object. This class should be a subclass of LWP::UserAgent. For example, .Sp .Vb 10 \& $ENV{WWW_SEARCH_USERAGENT} = \*(AqMy::Own::UserAgent\*(Aq; \& # If this env.var. has no value, \& # LWP::UserAgent or LWP::RobotUA will be used. \& $oSearch = new WWW::Search(\*(AqMyBackend\*(Aq); \& $oSearch\->agent_name(\*(AqMySpider\*(Aq); \& if ($iBackendWebsiteRequiresNonRobot) \& { \& $oSearch\->user_agent(\*(Aqnon\-robot\*(Aq); \& } \& else \& { \& $oSearch\->agent_email(\*(Aqme@here.com\*(Aq); \& $oSearch\->user_agent(); \& } .Ve .Sp Backends should use robot-style user-agents whenever possible. .IP "http_referer" 4 .IX Item "http_referer" Get / set the value of the \s-1HTTP_REFERER\s0 variable for this search object. Some search engines might only accept requests that originated at some specific previous page. This method lets backend authors \*(L"fake\*(R" the previous page. Call this method before calling http_request. .Sp .Vb 2 \& $oSearch\->http_referer(\*(Aqhttp://prev.engine.com/wherever/setup.html\*(Aq); \& $oResponse = $oSearch\->http_request(\*(AqGET\*(Aq, $url); .Ve .IP "http_method" 4 .IX Item "http_method" Get / set the method to be used for the \s-1HTTP\s0 request. Must be either '\s-1GET\s0' or '\s-1POST\s0'. Call this method before calling http_request. (Normally you would set this during \fB_native_setup_search()\fR.) The default is '\s-1GET\s0'. .Sp .Vb 1 \& $oSearch\->http_method(\*(AqPOST\*(Aq); .Ve .ie n .IP "http_request($method, $url)" 4 .el .IP "http_request($method, \f(CW$url\fR)" 4 .IX Item "http_request($method, $url)" Submit the \s-1HTTP\s0 request to the world, and return the response. Similar to LWP::UserAgent::request. Handles cookies, follows redirects, etc. Requires that http_referer already be set up, if needed. .IP "next_url" 4 .IX Item "next_url" Get or set the \s-1URL\s0 for the next backend request. This can be used to save the WWW::Search state between sessions (e.g. if you are showing pages of results to the user in a web browser). Before closing down a session, save the value of next_url: .Sp .Vb 4 \& ... \& $oSearch\->maximum_to_return(10); \& while ($oSearch\->next_result) { ... } \& my $urlSave = $oSearch\->next_url; .Ve .Sp Then, when you start up the next session (e.g. after the user clicks your \*(L"next\*(R" button), restore this value before calling for the results: .Sp .Vb 4 \& $oSearch\->native_query(...); \& $oSearch\->next_url($urlSave); \& $oSearch\->maximum_to_return(20); \& while ($oSearch\->next_result) { ... } .Ve .Sp \&\s-1WARNING:\s0 It is entirely up to you to keep your interface in sync with the number of hits per page being returned from the backend. And, we make no guarantees whether this method will work for any given backend. (Their caching scheme might not enable you to jump into the middle of a list of search results, for example.) .IP "split_lines" 4 .IX Item "split_lines" This internal routine splits data (typically the result of the web page retrieval) into lines in a way that is \s-1OS\s0 independent. If the first argument is a reference to an array, that array is taken to be a list of possible delimiters for this split. For example, Yahoo.pm uses

and

  • as \*(L"line\*(R" delimiters for convenience. .IP "generic_option" 4 .IX Item "generic_option" This internal routine checks if an option is generic or backend specific. Currently all generic options begin with 'search_'. This routine is not a method. .IP "_native_setup_search" 4 .IX Item "_native_setup_search" Do some backend-specific initialization. It will be called with the same arguments as \fBnative_query()\fR. .IP "setup_search" 4 .IX Item "setup_search" This internal routine does generic Search setup. It calls \f(CW\*(C`_native_setup_search()\*(C'\fR to do backend-specific setup. .IP "need_to_delay" 4 .IX Item "need_to_delay" A backend should override this method in order to dictate whether \&\fBuser_agent_delay()\fR needs to be called before the next \s-1HTTP\s0 request is sent. Return any perlish true or zero value. .IP "user_agent_delay" 4 .IX Item "user_agent_delay" According to what \fBneed_to_delay()\fR returns, \&\fBuser_agent_delay()\fR will be called between requests to remote servers to avoid overloading them with many back-to-back requests. .IP "absurl" 4 .IX Item "absurl" An internal routine to convert a relative \s-1URL\s0 into a absolute \s-1URL.\s0 It takes two arguments, the 'base' url (usually the search engine \s-1CGI URL\s0) and the \s-1URL\s0 to be converted. Returns a \s-1URI\s0 object. .IP "retrieve_some" 4 .IX Item "retrieve_some" An internal routine to interface with \f(CW\*(C`_native_retrieve_some()\*(C'\fR. Checks for overflow. .IP "_native_retrieve_some" 4 .IX Item "_native_retrieve_some" Fetch the next page of results from the web engine, parse the results, and prepare for the next page of results. .Sp If a backend defines this method, it is in total control of the \s-1WWW\s0 fetch, parsing, and preparing for the next page of results. See the WWW::Search::AltaVista module for example usage of the _native_retrieve_some method. .Sp An easier way to achieve this in a backend is to inherit _native_retrieve_some from WWW::Search, and do only the \s-1HTML\s0 parsing. Simply define a method _parse_tree which takes one argument, an HTML::TreeBuilder object, and returns an integer, the number of results found on this page. See the WWW::Search::Yahoo module for example usage of the _parse_tree method. .Sp A backend should, in general, define either \fB_parse_tree()\fR or \&\fB_native_retrieve_some()\fR, but not both. .Sp Additional features of the default _native_retrieve_some method: .Sp Sets \f(CW$self\fR\->{_prev_url} to the \s-1URL\s0 of the page just retrieved. .Sp Calls \f(CW$self\fR\->\fBpreprocess_results_page()\fR on the raw \s-1HTML\s0 of the page. .Sp Then, parses the page with an HTML::TreeBuilder object and passes that populated object to \f(CW$self\fR\->\fB_parse_tree()\fR. .Sp Additional notes on using the _parse_tree method: .Sp The built-in HTML::TreeBuilder object used to parse the page has store_comments turned \s-1ON.\s0 If a backend needs to use a subclassed or modified HTML::TreeBuilder object, the backend should set \&\f(CW$self\fR\->{'_treebuilder'} to that object before any results are retrieved. The best place to do this is at the end of _native_setup_search. .Sp .Vb 3 \& my $oTree = new myTreeBuilder; \& $oTree\->store_pis(1); # for example \& $self\->{\*(Aq_treebuilder\*(Aq} = $oTree; .Ve .Sp When \fB_parse_tree()\fR is called, the \f(CW$self\fR\->next_url is cleared. During parsing, the backend should set \f(CW$self\fR\->next_url to the appropriate \s-1URL\s0 for the next page of results. (If \fB_parse_tree()\fR does not set the value, the search will end after parsing this page of results.) .Sp When \fB_parse_tree()\fR is called, the \s-1URL\s0 for the page being parsed can be found in \f(CW$self\fR\->{_prev_url}. .IP "result_as_HTML" 4 .IX Item "result_as_HTML" Given a WWW::SearchResult object, formats it human-readable with \s-1HTML.\s0 .IP "preprocess_results_page" 4 .IX Item "preprocess_results_page" A filter on the raw \s-1HTML\s0 of the results page. This allows the backend to alter the \s-1HTML\s0 before it is parsed, such as to correct for known problems, \s-1HTML\s0 that can not be parsed correctly, etc. .Sp Takes one argument, a string (the \s-1HTML\s0 webpage); returns one string (the same \s-1HTML,\s0 modified). .Sp This method is called from within _native_retrieve_some (above) before the \s-1HTML\s0 of the page is parsed. .Sp See the WWW::Search::Ebay distribution 2.07 or higher for example usage. .IP "test_cases (\s-1DEPRECATED\s0)" 4 .IX Item "test_cases (DEPRECATED)" Deprecated. .Sp Returns the value of the \f(CW$TEST_CASES\fR variable of the backend engine. .IP "hash_to_cgi_string (\s-1DEPRECATED\s0)" 4 .IX Item "hash_to_cgi_string (DEPRECATED)" Given a reference to a hash of string => string, constructs a \s-1CGI\s0 parameter string that looks like 'key1=value1&key2=value2'. .Sp If the value is undef, the key will not be added to the string. .Sp At one time, for testing purposes, we asked backends to use this function rather than piecing the \s-1URL\s0 together by hand, to ensure that URLs are identical across platforms and software versions. But this is no longer necessary. .Sp Example: .Sp .Vb 9 \& $self\->{_options} = { \& \*(Aqopt3\*(Aq => \*(Aqval3\*(Aq, \& \*(Aqsearch_url\*(Aq => \*(Aqhttp://www.deja.com/dnquery.xp\*(Aq, \& \*(Aqopt1\*(Aq => \*(Aqval1\*(Aq, \& \*(AqQRY\*(Aq => $native_query, \& \*(Aqopt2\*(Aq => \*(Aqval2\*(Aq, \& }; \& $self\->{_next_url} = $self\->{_options}{\*(Aqsearch_url\*(Aq} .\*(Aq?\*(Aq. \& $self\->hash_to_cgi_string($self\->{_options}); .Ve .SH "IMPLEMENTING NEW BACKENDS" .IX Header "IMPLEMENTING NEW BACKENDS" \&\f(CW\*(C`WWW::Search\*(C'\fR supports backends to separate search engines. Each backend is implemented as a subclass of \f(CW\*(C`WWW::Search\*(C'\fR. WWW::Search::Yahoo provides a good sample backend. .PP A backend must have the routine \f(CW\*(C`_native_setup_search()\*(C'\fR. A backend must have the routine \f(CW\*(C`_native_retrieve_some()\*(C'\fR or \f(CW\*(C`_parse_tree()\*(C'\fR. .PP \&\f(CW\*(C`_native_setup_search()\*(C'\fR is invoked before the search. It is passed a single argument: the escaped, native version of the query. .PP \&\f(CW\*(C`_native_retrieve_some()\*(C'\fR is the core of a backend. It will be called periodically to fetch URLs. It should retrieve several hits from the search service and add them to the cache. It should return the number of hits found, or undef when there are no more hits. .PP Internally, \f(CW\*(C`_native_retrieve_some()\*(C'\fR typically sends an \s-1HTTP\s0 request to the search service, parses the \s-1HTML,\s0 extracts the links and descriptions, then saves the \s-1URL\s0 for the next page of results. See the code for the \f(CW\*(C`WWW::Search::AltaVista\*(C'\fR module for an example. .PP Alternatively, a backend can define the method \f(CW\*(C`_parse_tree()\*(C'\fR instead of \f(CW\*(C`_native_retrieve_some()\*(C'\fR. See the \f(CW\*(C`WWW::Search::Ebay\*(C'\fR module for a good example. .PP If you implement a new backend, please let the authors know. .SH "BUGS AND DESIRED FEATURES" .IX Header "BUGS AND DESIRED FEATURES" The bugs are there for you to find (some people call them Easter Eggs). .PP Desired features: .IP "A portable query language." 4 .IX Item "A portable query language." A portable language would easily allow you to move queries easily between different search engines. A query abstraction is non-trivial and unfortunately will not be done any time soon by the current maintainer. If you want to take a shot at it, please let me know. .SH "AUTHOR" .IX Header "AUTHOR" John Heidemann Maintained by Martin Thurn, \f(CW\*(C`mthurn@cpan.org\*(C'\fR, . .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 1996 University of Southern California. All rights reserved. .PP Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, advertising materials, and other materials related to such distribution and use acknowledge that the software was developed by the University of Southern California, Information Sciences Institute. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. .PP \&\s-1THIS SOFTWARE IS PROVIDED \*(L"AS IS\*(R" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\s0