Simple Search in PERL

I have had several requests for a simple search for a web directory. Most of the good perl searches are on websites that are offline or out of business. There are less and less good perl resources and some of the most basic programs are hard to find.

A basic search is very simple, but without a good example it is difficult to get started and build a custom application.

This search will be very effective up to about 2000-3000 average size text files. That is usually more than most people need, so there is nothing extra here. Just a simple search using perl that you can easily expand on and customize.

The search form is the default page, but you can easily copy the html to any html page on your website. There are no page numbers, so all the details show up on one page. If you have hundreds of results, you may want to limit the search to 20-50 results.

There are only 2 parameters to set.

# the directory with files you want to search
$searchdir = "./";

The default is the same directory as the script is in. If you have the script in a different directory than he files you want searched then specify the path to that directory.

# the file types you want to allow to be searched
@filetypes = ('*.html','*.htm','*.txt');

Set an arry of the file types you want to search. Remember they must all be text files, it can't search images or audio files. Do not include perl files, asp or php since the search will read the unparsed page and could give away details about programs you do not want to share.

Try the demo. If will search all the html and text files in this directory. There are only a few files in the directory so you will need to search for a common word like "the", "and" or "perl".

Installing The Program

download the search script easysearch.cgi

Rename the file to easysearch.cgi
configure the path and file types
upload th files in text format
chmod the file to 0755

Then just access the program with your browser and search your files.

There is a load of room to take this program to higher levels adding relevancy and sorting, breaking down pages into multiples and expanding the directories to multiple directories. The objective is to provide a simplified search so you can add in the functionailty you need.

I have extensive experience with searches having websites with millions of pages that require fast and efficient searches. I will add some ideas and additional search programs with more functionality as I have time. For now, the simple search in perl is a great start for any perl hacker.

Understanding Searches - Here is some insight into larger searches and the limits of the simple search program. Some ideas about how larger searches work.