Search Hi-Lite Plugin

19th Jan 2006 stk
Introduction & Comparison

This plugin has now been updated for the 2.x series, you can download it here ( AM Search Highlighter ). NOTE : For this version you do not have to make any changes to your skin ;)

More Accurate Search Results Plus Multi-Term Highlighting

It's not often that you can kill two birds with one stone and do it with panache. We believe the "Search Hi-Lite" plugin accomplishes this. As the name suggests, it will highlight multiple search terms with different, user-customizable, colors and styles. Now visitors can actually see the results that they're searching for, at a glance. That in itself is useful, but that's not all this plug-in accompllishes. This plug-in yields more ACCURATE search results than the search function that ships with b2evolution!

You are going to like this plug-in!

While making the proto-type, we discovered that a b2evolution search matched on text inside XHTML tags. A search for "http://" returns every post with an img tag <img src="http://blah.jpg" /> or a link <a href=""> in other words, just about every post in a blog! Not good.

When returns are not highlighted, this behavior is difficult to notice. Once we highlighted the terms, however, it became apparent that b2evo was returning unseen text and highlighting them lead to broken images, broken links and - in the worst case - a broken site (if served with a MIME type of "application/xhtml+xml"). It looked awful and was FAR from the desired result. We had to completely redesign the plug-in to work around (and ultimagely FIX) this behavior.

Or goal: Give visitors highlighted search returns that matched the search term(s), either as full words or contained within a larger word (limiting the search to text VISIBLE in the blog).

We have achieved this, via creative coding and modifications to the skin's main template file "_main.php". Note: No core files were harmed in the making of this plugin.

To demonstrate the difference between the standard b2evo search returns and our "Astonish Me! Hi-Lite Search" Plug-in, click the links below. In each case, the search if for "http://":

This simple test makes it clear that not only does this plugin provide obviously VISIBLE search returns, but they're also more relevant and accurate!

You want this plugin, don't you? (I warned you about that!) HA! For downloading and installation instructions ... search on the next page.

  1. Introduction & Comparison
  2. Install Instructions
  3. Usage & Considerations
  4. FAQs & Something Else


Comment from: Danny
Any chance this plugin could include comment searching? A lot of people have asked for that.
02/04/06 @ 16:51
Comment from: stk
And retain highlighting for multiple pages? (Hey ... why not ask?)
02/05/06 @ 02:47
Comment from: stk
Note to self ... just noticed returns for the all_blog in the [css] [/css] section ... I remember that we were going to find (had?) a user-defined array where we could strip tags (and everything in between) to keep OUT of the search text??

JUst need to figure out where and HOW.

PS ... I added "special" blog to Randsco. (With a little help from my friends).

Steps (for an aging mind) ...

1) Make blog ... stub file about.php
2) For search to span ALL blogs ... add to search form
3) Make sure ALL blog has right skin :|
4) search returns now span more than one skin
5) set up skin for this new blog (title and such)
6) KEY (for me anyway) ... did not WANT sidebar elements to CHANGE (archives/categories always the same ... i.e., main blog)
7) use dirty little trick from multiblogs.php (to set $blog to be one I want ... right before archives ... and reset after categories.
8) Works ... BUT ... the links are a tad rough ... cats go to:

(instead of)

... same with archives ...
9) AND the "All Entries" (the all option in cats) ... goes to the (which is totally wrong and had to hard-code the cats_plugin file.

Wonder if there is a better way to get the all out of the links after a search throws one into the all blog?
03/02/06 @ 23:20
Comment from: MrDav
I was going to ask for comment searching too, but Danny beat me.
09/23/06 @ 19:57
I tried setting this on b2evo 1.8.5 but it didn't work for me. Have the instructions been updated for 1.8.5?


01/01/07 @ 22:15
I'm afraid we haven't got round to converting this to 1.8.6 yet.

As an aside you should upgrade to 1.8.6, see this security alert

01/02/07 @ 11:11
Comment from: Michael Watson
Has anyone been able to successfully install this plugin in b24evolution 1.9.2 as yet? I am able to run the install script without problems, but when I try to make the necessary changes to ../skins/custom/_main.php, it causes my blog to break, displaying only a blank page. I've looked pretty carefully to be sure I'm putting the changes in the right place, paying careful attention to closing braces & such. I'm wondering whether there's been a change in 1.9.2 that just makes it incompatible with am search hi-lite. By remming out various lines, I found that the problem seems to involve a line in the 2nd code block:

$am_search = $Plugins->get_by_name( 'am_search_plugin' );

01/31/07 @ 17:37
You might like to test out the beta 1.9.2 version which you can find here

You'll need to undo all the skin changes you made for this version as the new version doesn't require them ;)

If you find any problems with it then please leave a comment on that thread

02/01/07 @ 08:11
Comment from: Michael Watson
Thanks for the suggestion. I was able to install the beta 1.9.2 version without difficulty. I've managed to get it working after a fashion, but I think I'm missing an important detail on installation.

I restored the original _main.php before installing the plugin. After I installed the plugin, my blog displayed properly, and the search function did work, but search results still weren't highlighted.

I looked at the html source and noted that search words were enclosed in SPAN tags with class search_hit0, so I thought I'd missed instructions somewhere to modify the skin's stylesheet. I manually added a class of .search_hit0 with a background-color attribute to my skin's stylesheet. This did indeed make the search results highlight properly. But I'm not sure what other classes I might need to add. On examining _am_search.plugin.php, it looks like search results are tagged search_hit0, search_hit1, search_hit2 based on incrementing values of a variable etc. But I'm not sure how high the values of that variable might go, so I'm not sure what classes I need to create and assign a background-color attribute.

Did I miss documentation somewhere concerning required edits to the stylesheet?

Many thanks for your help on this, it's looking very promising!
02/01/07 @ 17:56
Hi Michael,
The most important thing you missed about the instructions is that they were written by an absent minded blonde :P

As you found out the plugin wraps the search terms in a span with a classname of search_hit# where # is a pointer for the keyword found ( 2 keywords == search_hit0 && search_hit1 ), so you need to add classes to your style sheet to cover what you think will be the maximum number of keywords that somebody might search for ( *note to self* add some sort of cap and re-use the classes for > ## keywords).

I'll upgrade the plugin to include some default styles so that it works straight out of the box, I warn you though I tend to pick gaudy colours ;)


The plugin has been upgraded (and the zip file on the original link has been updated). The keyword classes have been limited to 0 -> 6 ( after that they're re-used ).

Let me know if you have any further problems with it.
02/02/07 @ 08:04
Comment from: sam2kb

Download link is dead. ;)
02/11/08 @ 06:46
Ahh bugger, yet another broken link :-S

It's a good job really because we've done a complete recode for the 2.x series and need to update this post badly. I should get round to it in the next couple of days and I'll also add it to B.O.P.I.T so you'll know when it's updated ;)

02/11/08 @ 13:31

Comments are closed for this post.