suda.co.uk

Search Engine Highlighting

Background

This function will extend a search engine's ability to search your domain by taking the terms the user entered and highlighting them within your own domain. This is achieved on the server-side without the users knowledge. The function takes the referrer from the search engine and parses out the query string, searches through your post-processed HTML code, and tags matching terms.

The function is written in PHP and uses some of the built-in functions, namely the output buffer. This enables the PHP code to be processed completely before the searching and tagging will begin, so any data that is created dynamically will also be searched through and highlighted. The regular expressions used to search through the code are tag sensitive, so if parts of the query string appear within a tag, they are ignored therefore not destroying any valid markup.

Installation Instructions

There are a few different ways that this can be installed throughout your system.

First, Download the zip file and place the sehl.php in any directory. You will need the output buffer libraries installed in PHP and depending on what other system rights you have will determine how this gets deployed. If you have access to your php.ini file you can specify a function to be automatically executed before PHP send the HTML to the buffer.

Alternatively, you could add the following lines to your .htaccess file.

include_path=".:/home/USERNAME/includes"
php_value auto_prepend_file "header.inc"
php_value auto_append_file "footer.inc"

Then every page in and under the directory the .htaccess file is in will have the two files added to them above and below its content respectively.

The header.inc and footer.inc can be use even if you can't use your .htaccess file, you will just have you manually add include statements to each PHP file.

Finally, the function will add span tags around the query terms. You will need to add a few entries into your style sheet.

.hl0 { background-color: #FFFF99 }
.hl1 { background-color: #FF99FF }
.hl2 { background-color: #99FFFF }

Outstanding Issues

There is a list of outstanding issues, which can be browsed and updated.

Download

This project has been moved to GitHub. You can still download the source, but now there is a more advanced issues system to track bugs and other issues.

Tags

Last modified: March 13, 2015 22:11:46 UTC

Copyright 2002-©-2024 Brian Suda
http://suda.co.uk/projects/SEHL/