Search Highlighter
This application allows webmasters to highlight search results on their web pages. When a user performs a search using Google, AltaVista or other search engine, then clicks on a link to a website which has the search highlighter installed, all matching search terms in the page are highlighted in yellow. The page will also automatically scroll down to the first match. This makes it much easier for the user to find what they're looking for. Try this example, search for "Neil Fraser" in your favourite search engine. Choose my site, and note the highlighting (if you've recently been to my homepage, your cache may serve an unhighlighted version of the page).
Features
- Double-quoted phrases are supported. If you search for "Neil Fraser" with quotes, it will only highlight those words when they appear together.
- Wildcards. Google and AltaVista support wildcards. So does the search highlighter. A "*" inside a double-quoted phrase will match any single word.
- It works on all browsers and on all HTML content on the whole website, whether it comes from files or CGI scripts. There is no need to make changes to any of the documents or scripts. Instead, it uses a filter on Apache's output. See the installation section below for details.
- It won't mangle the original HTML. Great care has been taken to make sure that other than adding the highlights, no other changes are made to the web page. It is aware of JavaScript, textareas and other special cases and won't add highlights in the middle of these sections.
- Can be installed globally across the entire server, selectively on individual accounts, or specifically to certain directories, filetypes, remote hosts, etc.
- Several optional meta tags can be added to pages. These override the global settings which are defined in the application and allow one to tweak the highlighting behaviour in a particular document:
- <META NAME="highlighter_on" VALUE=1>
- Enable (1) or disable (0) the highlighter.
- <META NAME="highlighter_jump" VALUE=0>
- Enable (1) or disable (0) the jump-to-first-match feature.
- <META NAME="highlighter_starttag" VALUE="<BLINK>">
- Use a custom highlighting tag. Useful on pages with different colour schemes.
- <META NAME="highlighter_endtag" VALUE="</BLINK>">
- Custom close tag for highlights.
Known Bugs
- Non-English HTML character entities such as é (é) aren't supported. Searches containing them won't be highlighted.
- Words which are broken up with HTML tags inside them (like this) don't get highlighted when one searches for the entire word.
- No highlighting is displayed on pages which use frames. This is because the referer information doesn't make it past the frameset page to the frame content pages.
- If the page uses server-side includes, and an include performs an internal redirect (usually this is due to sloppy HTML coding) the order of the includes may be rearranged. This is a known bug in Apache (bug 17629) and looks like it will be fixed soon.
- Also with server-side includes, the highlighter parses each include separately, then does so again for the completed page. In extremely rare cases (meaning only in rigged demos) this could lead to highlighting tags being inserted inside JavaScript code or textareas. This is a limitation of Apache which is being addressed in bug 20946.
Installation
- Make sure that your copy of Apache is version 2.0.48 or later and has mod_ext_filter installed.
- Add the following to your Apache config.
SetEnvIf Referer "[?&]q=." do_highlight # Google, AltaVista, MSN, AllTheWeb, etc.
SetEnvIf Referer "[?&]query=." do_highlight # Lycos, AOL, HotBot, Netscape, etc.
ExtFilterDefine highlighter mode=output enableenv=do_highlight intype=text/html \
cmd="/usr/bin/python /home/yourname/highlighter.py"
SetOutputFilter highlighter
- Download highlighter.py and place it in the location specified above.
Problems installing or want something special? Read the advanced installation guide.
Alternatives
An entirely different strategy for providing search highlighting is to do
it on the client's side using JavaScript. See
Lao-Tzu's highlighter
for a good implementation. Works for any browser with JavaScript 1.2
Another method is to use a custom Apache module. Adorn Software wrote one called
mod_suru which is pretty much identical
to my version, except that it costs money (mine is free) and only works on Apache 1.3.x
(mine only works for Apache 2.x).
Last modified: 7 August 2003