Search This! (
Page 1 of 6 )
Add search capabilities to your site using the popular open source tools PHP3 and ht://Dig.So, you want to put a "Search This Site" button on your PHP3 sites? Well, unless
all your pages are stored in a database (ugh!), there is no easy way to do this
using PHP alone.
The solution is to use another program designed specifically for indexing and
searching your site, and then use the results of that program in your PHP
script.
When I first needed this functionality for a site I was designing for the
SummerWorks Theatre Festival, I came across ht://Dig. For those who don't know,
"The ht://Dig system is a complete world wide web indexing and searching system
for a small domain or intranet. ... [It] is meant to cover the search needs for
a single company, campus, or even a particular sub section of a web site."
This tutorial will cover the following steps needed to get these two great
Open Source applications working together:
- Installing ht://Dig
- Configuring ht://Dig
- Indexing the Site
- Building the Search Page
- Performing the Search
- Parsing and Displaying the Results
Installing ht://Dig
I'm not going to spend much time on this section, since the ht://Dig
documentation can answer any questions much better than I can in this tutorial.
As of this writing, the latest version of ht://Dig is 3.1.0b4. The latest
version can always be found at http://www.htdig.org.
Once you've downloaded the archive, and unzipped it, read the
README and htdocs/install.html files for the latest
information and instructions on how to install. I'm running Linux 2.0.35 and
Apache 1.3.3, so your set-up may vary, but the first step is to run the
configuration program.
% ./configure
You may then want to edit the CONFIG file. Specifically I changed
these four settings to the following values:
prefix = /usr/local/htdig
CGIBIN_DIR = /usr/local/htdocs/htdig/cgi-bin
IMAGE_DIR = /usr/local/htdocs/htdig
SEARCH_DIR = /usr/local/htdocs/htdig
The last two settings aren't too important, because we're going to be making
our own search script and interface using PHP3.
Once the CONFIG file is to your liking, run make and then make
install:
% make
% make install
If all went well, ht://Dig should be installed and we can move on to
configuring it to work with PHP.