Search Engine [PHP]

Download Source Code [Downloads: 636]
SHA1: cfe2b83c63217bca6ebc72c2ae3c4acdc2648a6d
Search Engine input box screen shot

This script searches in a specified directory and down through all subdirectories and files for the given search word or phrase, which can be input as a regular string or a regular expression (regex). The script searches in all filenames and in content for filtypes specified in the script. Only files below a specified maximum size are opened and searched in. The search results are listed as links with a short preview of the matched content and info on the number of matches.

Known limitations: the script only works for (smaller) sites where all content is stored in files and not in a database. The PHP engine's default timeout is 30 seconds and if the script doesn't finish before this it will be terminated with an error. Depending on the webhost's policy it might be possible to extend this with set_time_limit().

Ideas for further development: make search progress animation with JavaScript. Highlight matched content when following a result link.

You can try the search engine in action here on my site: Search my Site.

Example of Usage

<!DOCTYPE html>
<html lang="en">
<title>Search Engine Example</title>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" media="all" />

$se = new com\dunweber\searchengine\SearchEngine('.'); // Current dir and down
echo $se->getSearchModule();