PHP Search
Copyright (C) 2002-2004 Oliver Hitz
Introduction
This program interfaces PHP with the ht://Dig search engine. Instead of running the search engine (the htsearch tool) directly as a CGI script, this program runs it in a shell and parses the output of it. This output is then presented using PHP.
License
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Requirements
This program requires a web server with PHP 4 and ht://Dig set up. It needs access to an external script which calls the htsearch executable.
Usage
The Search class requires ht://Dig set up with special template files that can be found in the htdig-templates folder:
template_map: default default template.txt
search_results_header: header.txt
search_results_footer:
nothing_found_file: nomatch.txt
syntax_error_file: syntax.txt
Make sure that PHP has access to the htsearch script. If you are running in safe mode, copy the program to your safe_mode_exec_dir (see your php.ini file).
A search page for the site can be produced using the following excerpt:
<?php
$s = new Search("site");
$s->setCommand("/usr/local/bin/htsearch");
$s->form();
$s->results();
?>
The site parameter signifies what ht://Dig configuration file should be used (on web hosting platforms, the same ht://Dig installation services multiple sites). See the ht://Dig documentation for more on this.
The htsearch program called in the above example is NOT the htsearch binary but script such as the one included in the scripts directory.
Restricting the Output
Using the setRestrict operation, the URLs htsearch searches can be restricted.
The following example only returns matches whose URL contains "johnsweb":
<?php
$s->setRestrict("johnsweb");
?>
Customizing the Output
The output of the Search class can be customized using the set method:
$s->set("nomatch", "Sorry, no page matching your search criteria could be found.");
The following values can be set:
- internal: shown in case of an internal error (e.g. if the htsearch excecutable could not be found.
- nomatch: shown when no matches could be found.
- syntax: shown in case of an invalid search string.
- intro: shown in front of the search form.
- button: text shown on the search button.
- 1found: shown if exactly one match was found.
- nfound: shown when n matches were found (%d gets replaced with the number of matches.
- entry: every match is shown with this template. The following variables get replaced in this string: {n} the match number, {url} address of the match, {title} title of the match, {modified} last modified date, {size} of the page, {excerpt} an excerpt. The exact format of the date, size and excerpt need to be set in the ht://Dig configuration.
- pagestart: shown in front of the page numbers.
- pagestop: shown after the page numbers.
- pagecur: shows the current page number, %s gets replaced with the current number.
- pagelink: link to a specific page, the first %s gets replaced with the address and the second %s with the page number.
- pageprev: link to the previous page, %s gets replaced with the address.
- pagenext: link to the next page, %s gets replaced with the address.
- result: address of the search page, in case the form is used on a different page than the search page.
- target: name of the target frame if different from the current frame.