.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" 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 turned on, 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 .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "SEARCH.CGI 7" .TH SEARCH.CGI 7 "2014-09-03" "perl v5.20.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" search.cgi \-\- Example Perl program for searching with Swish\-e and SWISH::API .SH "DESCRIPTION" .IX Header "DESCRIPTION" This is a very simple program that shows how to use the \s-1SWISH::API\s0 module in a \s-1CGI\s0 script or mod_perl handler using Template-Toolkit to generate output. This program is intended for programmers that want to create a custom search script. .PP Unlike \fIswish.cgi\fR this script does not have many features, and provides no external configuration (with the execption of a few config options under mod_perl). So don't ask why it doesn't do something. The point is that this script is used as a starting point that \s-1YOU\s0 customize. .SH "REQUIREMENTS" .IX Header "REQUIREMENTS" You must have swish-e and the \s-1SWISH::API\s0 module installed. See the \s-1README\s0 and \s-1INSTALL\s0 documents in the swish-e distribution. As of this writing \s-1SWISH::API\s0 is part of the swish-e distribution, but in the future may be provided as a separate package (provided on the \s-1CPAN\s0). In either case \s-1SWISH::API\s0 is a separate installation procedure from installing swish-e. The Storable module is also required if using mod_perl. .PP This program does require that some modules are installed from \s-1CPAN.\s0 You will need Template-Toolkit and HTML::FillInForm (which depends on HTML::Parser). How those are installed depends on your computer's packaging system. .PP You will need a web server, obviously. The discussion below assumes Apache is used. If you are using \s-1MS IIS\s0 take note that \s-1IIS\s0 works differently in a number of ways. .SH "OVERVIEW" .IX Header "OVERVIEW" The \fIsearch.cgi\fR script and related templates are installed when swish-e is installed. \&\fIsearch.cgi\fR is installed in \f(CW$prefix\fR/lib/swish\-e/ and templates are installed in \f(CW$prefix\fR/share/swish\-e/templates/. \f(CW$prefix\fR is /usr/local by default but can be changed when running the swish-e \fIconfigure\fR script. Upon installation \fIsearch.cgi\fR is updated with correct paths to your perl binary and .PP When running as a \s-1CGI\s0 script \fIsearch.cgi\fR is copied or symlinked to the location of your \s-1CGI\s0 scripts (or any directory that allows \s-1CGI\s0 scripts). By default, the \fIsearch.cgi\fR script looks for the index \fIindex.swish\-e\fR in the current directory (that's what the web server considers the current directory). On Apache running mod-cgi that's the same place as the script. On \s-1IIS\s0 it's not. If your index is elsewhere you will need to modify the script. .PP The script works by parsing the query, calling \s-1SWISH::API\s0 to run the actual search, then calls Template-Toolkit to generate the ouput. .PP The script calls the \fIsearch.tt\fR template. This template generates the query form and the search results. The \fIsearch.tt\fR template uses a Template-Toolkit \*(L"\s-1WRAPPER\*(R"\s0 function to wrap the search form and results in your site's design. This design is in the \fIpage_layout\fR template. The idea is if you use Template-Toolkit to manage your entire site then your entire site would be formatted by the same \fIpage_layout\fR template. The \fIpage_layout\fR template calls two other templates \fIcommon_header\fR and \fIcommon_footer\fR to generate a common header and footer for the site. Those are just demonstrating Template-Toolkit's features. .PP The \fIpage_layout\fR page only defines the basic structure of the site. The true design of the site is managed by style sheets. \fIstyle.css\fR defines the basic layout and \fImarkup.css\fR sets fonts and colors. .PP Note: these style sheets are included directly in the output of the \s-1CGI\s0 script. In production the style sheets would be stored as separate style sheet files and imported by the browser instead of directly included in the search results page. .PP See the section \s-1MOD_PERL\s0 below for more on templates. .PP Highlighting of search terms is provided by the SWISH::PhraseHighlight module. That is a very slow module, so you may wish to disable it if you expect a lot of traffic. .SH "INSTALLATION EXAMPLE" .IX Header "INSTALLATION EXAMPLE" Enough talking, sometimes it's nice to see a complete example. Below swish-e is installed in the default location (/usr/local). The \*(L"$\*(R" is a normal user prompt, where \*(L"#\*(R" is a root prompt. Use ./configure \-\-prefix to install in another location (e.g. if you do not have root access). .PP Download and install swish-e .PP .Vb 8 \& $ wget \-q http://swish\-e.org/Download/latest.tar.gz \& $ tar zxf latest.tar.gz \& $ cd swish\-e\-2.x.x \& $ (./configure && make) >/dev/null \& $ make check \& $ su \& # make install \& # exit .Ve .PP Install \s-1SWISH::API\s0 .PP .Vb 5 \& $ cd perl \& $ perl Makefile.PL && make && make test \& $ su \& # make install \& $ exit .Ve .PP Install requried Perl modules. You can install via RPMs, Debs or directly from the \s-1CPAN\s0 or by using the \s-1CPAN\s0 shell. .PP .Vb 4 \& # su \& # perl \-MCPAN \-e \*(Aqinstall Template\*(Aq \& # perl \-MCPAN \-e \*(Aqinstall HTML::FillInForm\*(Aq \& # exit .Ve .PP Now setup the script in someplace that allows \s-1CGI\s0 scripts. .PP .Vb 9 \& $ cd $HOME/apache \& $ ln \-s /usr/local/lib/swish\-e/search.cgi . \& $ cat .htaccess \& deny from all \& \& allow from all \& SetHandler cgi\-script \& Options +ExecCGI \& .Ve .PP Create an index .PP .Vb 5 \& $ cat swish.config \& IndexOnly .htm .html \& DefaultContents HTML* \& StoreDescription HTML* \& metanames swishtitle swishdocpath \& \& $ swish\-e \-c swish.config \-i /usr/share/doc/apache\-doc/manual .Ve .PP Test the index and the \s-1CGI\s0 script: .PP .Vb 2 \& $ swish\-e \-w apache \-m1 | grep hits \& # Number of hits: 152 \& \& $ lynx \-dump http://localhost/apache/search.cgi?query=apache | grep hits \& Showing page 1 (1 \- 10 of 152 hits) [3]Next \& \*(Aqhits\*(Aq => 152, .Ve .PP Now, the above isn't very helpful because the Apache documentation indexed is not in the web space. You would likely index content available on your web site. .SH "Using with SpeedyCGI" .IX Header "Using with SpeedyCGI" Perl \s-1CGI\s0 script must be compiled for each request. SpeedyCGI is a tool to speed up scripts by running them persistently. To run \fIsearch.cgi\fR with SpeedyCGI install the program (you can Google, right?) and then change the first line of \fIsearch.cgi\fR to run the \fIspeedy\fR program. .PP For example: .PP .Vb 1 \& #!/usr/bin/speedy \-w .Ve .SH "Using with MOD_PERL" .IX Header "Using with MOD_PERL" This script can be run directly as a mod_perl handler, and the same code can be used to run multiple sites by using separate Location directives and passing in a \*(L"site id.\*(R" The script caches in memory different configurations based on this site id. .PP Below is a complete httpd.conf file. It requires an Apache httpd that has mod_perl compiled in statically. It runs mod_perl on a high port (port 5000) listening to all interfaces. .PP For testing I put this config file in a directory along with \fIsearch.cgi\fR, but that's just done to make the example simple (i.e. so I don't have to show any absolute paths). Normally the httpd.conf and the swish.cgi \*(L"module\*(R" would be in separate locations. .PP .Vb 1 \& # httpd.conf \-\- test file for search.cgi as mod_perl handler \& \& \& LoadModule mime_module /usr/lib/apache/1.3/mod_mime.so \& \& \& ErrorLog swish_error_log \& PidFile swish_httpd.pid \& \& Listen *:5000 \& \& \& push @PerlSetVar, [ \& index => Apache\->server_root_relative( \*(Aqindex.swish\-e\*(Aq), \& ]; \& $DocumentRoot = Apache\->server_root_relative; \& require "search.cgi"; \& \& \& NameVirtualHost *:5000 \& \& \& ServerName localhost \& \& \& SetHandler perl\-script \& PerlHandler SwishAPISearch \& \& \& \& SetHandler perl\-script \& PerlHandler SwishAPISearch \& # Define this site \& PerlSetVar site_id othersite \& PerlSetVar title "Some other Site" \& \& \& .Ve .PP The server is started using this command: .PP .Vb 1 \& $ /usr/sbin/apache\-perl \-d $(pwd) \-f $(pwd)/httpd.conf .Ve .PP which says to use the current directory as the ServerRoot. (See comments below.) Stop the server like: .PP .Vb 1 \& $ kill \`cat swish_httpd.pid\` .Ve .PP Then access either: .PP .Vb 2 \& http://localhost:5000/search \& http://localhost:5000/othersite .Ve .PP A few Notes: .PP I like test configurations to not care where things are located. Thus, the above httpd.conf does a few tricks in the \*(L"Perl Section\*(R" shown. .PP First, mod_perl, unlike \s-1CGI,\s0 doesn't set the working directory. So, the index file name must be absolute. This is accomplished by a PerlSetVar entry building the index file name from the ServerRoot. .PP Second, the DocumentRoot is set to the same as the ServerRoot. The DocumentRoot needs to be set so search.cgi can figure out the path to the script (for creating next and previous links). .PP Third, the script is loaded by a \f(CW\*(C`require\*(C'\fR statement. This works only because the current directory \*(L".\*(R" is in Perl's \f(CW@INC\fR path at Apache start up time and \&\fIsearch.cgi\fR is also in the current directory. Normally, set \s-1PERL5LIB\s0 on server startup or use a \*(L"use lib\*(R" line in your startup.pl file to point to the location of search.cgi. .PP The \*(L"PerlSetVar\*(R" lines pass config information into the script. Note that they can be set globally or specific to a given Location. .PP The following config options are currently available: .IP "site_id" 4 .IX Item "site_id" The site_id options allow caching of configurations on a per-site basis. It's overkill in this example, but normally you might have expensive configuration processes that you might want to do only once. But, since there is caching by this id it's a good id to set a site_id if using more than one Location directive. .IP "index" 4 .IX Item "index" This specifies the index file to use. The index file needs to be absolute as discussed above. Example: .Sp .Vb 1 \& PerlSetVar index /usr/share/swish/site.index .Ve .IP "title" 4 .IX Item "title" This options sets the title that's passed into the template. .IP "template" 4 .IX Item "template" Sets the file name of the template use to generate the form. This might be useful if you want an \*(L"advanced\*(R" form, for example. .IP "template_path" 4 .IX Item "template_path" This can be used to update the path where templates are searched. Useful if you wish to override templates. .IP "page_size" 4 .IX Item "page_size" This allow changing the default number of results shown per page. .SH "SUPPORT" .IX Header "SUPPORT" Not much support is provided. But what support is provided is \s-1ONLY\s0 provided via the Swish-e discussion list. .PP .Vb 1 \& http://swish\-e.org/ .Ve .SH "AUTHOR" .IX Header "AUTHOR" Bill Moseley .SH "LICENSE" .IX Header "LICENSE" Copyright 2003, 2004 Bill Moseley. All rights reserved. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\s-1SWISH::API, \s0 Template, HTML::FillInForm