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: