📄 ch10.htm
字号:
<BR>
<BR>
To search using GlimpseHTTP, view the ghindex.html file that has been generated in
each directory. The ghindex.html page has a search form which you can use search
that particular subdirectory of the archive.</P>
<P>GlimpseHTTP allows you to integrate search with browsing. If you have several
nested directories which the user may browse, you can include the Glimpse interface
in each document such that only the relevant directories will be included in the
search. More details are given below.</P>
<P>The current version of GlimpseHTTP was tested under httpd 1.2 HTML server from
NCSA, and works on Apache and other Web servers.</P>
<P>Some features of GlimpseHTTP include:
<UL>
<LI>Combined browsing and searching; first, you locate the directory where the relevant
information might be located, then you can use search to locate specific files. The
result of a search is nicely formatted hypertext with hyperlinks to matching documents.
<P>
<LI>Easy generation of search pages
<P>
<LI>Configurable search pages
<P>
<LI>Well-documented scripts and complete online documentation
<P>
<LI>Easy installation
<P>
<LI>Non-centralized archive management, allowing separate users to maintain separate
archives with no special permissions needed
<P>
<LI>Uses the Glimpse search engine, which provides some unique features:
</UL>
<BLOCKQUOTE>
<P>Uses a very small index (3 to 5 percent of the total text) Very fast search Searches
for approximate match, allowing errors
</BLOCKQUOTE>
<H3 ALIGN="CENTER"><A NAME="Heading6"></A><FONT COLOR="#000077">Search the Web with
WWW::Search</FONT></H3>
<P>For searching outside of your site, a set of modules called WWW::Search has been
written by John Heidemann. WWW::Search is a collection of Perl modules which provides
a common API to most popular WWW search engines. As of this writing, there are modules
which support AltaVista, Yahoo!, Lycos, Hotbot, and WebCrawler. The author is currently
developing more modules for other search engines and more sophisticated clients and
examples. The latest version of the WWW::Search module can be found at:</P>
<PRE><FONT COLOR="#0066FF">
</FONT><A HREF="javascript:if(confirm('http://www.isi.edu/lsam/tools/WWW_SEARCH/ \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.isi.edu/lsam/tools/WWW_SEARCH/'" tppabs="http://www.isi.edu/lsam/tools/WWW_SEARCH/"><FONT COLOR="#0066FF">http://www.isi.edu/lsam/tools/WWW_SEARCH/</FONT></A><FONT
COLOR="#0066FF">
</FONT></PRE>
<P>Installation of the module requires Perl5 version 5.003, and is very straightforward.
Using the module to generate custom queries to a search engine is very simple.</P>
<P>First, the type of search engine must be defined. Check the documentation to see
if the search engine you wish to query is supported, then create a new search:</P>
<PRE><FONT COLOR="#0066FF">$search = new WWW::Search(`SearchEngineName');
</FONT></PRE>
<P>An example would be:</P>
<PRE><FONT COLOR="#0066FF">$search = new WWW::Search(`AltaVista');
</FONT></PRE>
<P>Then specify the query string. This string is made up of some specific name value
pairs, and is URI encoded.</P>
<PRE><FONT COLOR="#0066FF">$search->native_query(`search-engine-specific+query+string');
</FONT></PRE>
<P>Here's a documented example which performs an AltaVista search, then prints the
URIs resulting from the search. Note that you could easily add nice custom formatting
of the results in the while loop.</P>
<PRE><FONT COLOR="#0066FF">my($search) = new WWW::Search::AltaVista;
$search->native_query(WWW::Search::escape_query($query));
my($result);
while ($result = $search->next_result()) {
print $result->url, "\n";
};
</FONT></PRE>
<P>Listing 10.1 is code from search.PL, a small example included with the WWW::Search
distribution. This example illustrates the usage of the Search Library. Figure 10.2
depicts an example of output that could easily be generated by search.PL.
<H3 ALIGN="CENTER"><A NAME="Heading7"></A><FONT COLOR="#000077">Listing 10.1. search.PL</FONT></H3>
<H3 ALIGN="CENTER"><A NAME="Heading8"></A><FONT COLOR="#000077">; real world example
of WWW::Search.</FONT></H3>
<PRE><FONT COLOR="#0066FF"># Copyright (c) 1996 University of Southern California.
# All rights reserved.
use strict;
&usage if ($#ARGV == -1);
&usage if ($#ARGV >= 0 && $ARGV[0] eq `-?');
use WWW::Search;
use Getopt::Long;
my(%opts);
&GetOptions(\%opts, qw(v a e=s o=s@)); # i.e -v -e=<string> -o=<options>
&usage if ($#ARGV == -1); # we MUST have one left, the query
my($verbose) = $opts{`v'};
my($all) = $opts{`a'};
&main(join(" ", @ARGV));
exit 0;
sub print_result {
my($result, $count) = @_;
my($prefix) = "";
$prefix = "[$count] " if defined($verbose);
if ($all) {
foreach ($result->urls()) {
print "$prefix$_\n";
$prefix = " ";
};
} else {
print $prefix, $result->url, "\n";
};
}
sub main {
my($query) = @_;
my($count) = "001" if defined($verbose);
my($search) = new WWW::Search($opts{e});
my($query_options_ref);
if (defined($opts{`o'})) {
$query_options_ref = {};
foreach (@{$opts{`o'}}) {
my($key, $value) = m/^([^=]+)=(.*)$/;
$query_options_ref->{$key} = WWW::Search::escape_query($value);
};
};
$search->native_query(WWW::Search::escape_query($query), $query_options_ref);
my($way) = 0; # 0=piecemeal, 1=all at once
my($result);
if ($way) { # return all at once.
foreach $result ($search->results()) {
print_result($result, $count++);
};
} else { # return page by page
while ($result = $search->next_result()) {
print_result($result, $count++);
};
};
};
</FONT></PRE>
<P><A HREF="11wpp02.jpg" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/11wpp02.jpg"><TT><B>Figure 10.2.</B></TT></A> Output possible
from search.PL.
<H3 ALIGN="CENTER"><A NAME="Heading9"></A><FONT COLOR="#000077">Summary</FONT></H3>
<P>Adding a search engine to your site with Glimpse greatly increases the usefulness
and functionality of your service. Whether you have an online catalog or are just
providing information, Glimpse is an easy way to make your information more accessible.
The WWW::Search module is a good way to provide a seamless link from your on-site
search to information resources elsewhere on the Internet.<BR>
<P ALIGN="CENTER"><A HREF="ch09.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/ch09.htm"><IMG SRC="blanprev.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blanprev.gif" WIDTH="37" HEIGHT="37"
ALIGN="BOTTOM" BORDER="2"></A><A HREF="index-1.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/index-1.htm"><IMG SRC="blantoc.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blantoc.gif" WIDTH="42"
HEIGHT="37" ALIGN="BOTTOM" BORDER="2"></A><A HREF="ch11.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/ch11.htm"><IMG SRC="blannext.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blannext.gif"
WIDTH="45" HEIGHT="37" ALIGN="BOTTOM" BORDER="2"></A>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -