KBD

Keith Devens .com

Wednesday, July 9, 2008 Flag waving
The function of wisdom is to discriminate between good and evil. – Cicero
← Girls, please don't get breast implantsClient-side word highlighter →

Daily link icon Tuesday, April 29, 2003

Search term highlighting on my site

New feature: click through to my site from a search engine (try the first link on this search), and you'll get to see the new feature. It pretty much explains itself. Smiley You may have to refresh the page, however, if the page is stored in your disk cache.

I took one regular expression trick from Dean Allen (thanks Dean).

Two issues: I can't do real highlighting of search terms of more than one word. Say you have a phrase in which one word is <em>emphasized</em>. If you search for "one word is emphasized", there's no real way to highlight that with regular expressions, since you could have an arbitrary nesting of HTML. "one word is <strong><em><span>emphasized</span></em></strong>"... etc. Is there a trick I don't know about?

The problem could theoretically happen even within one word, since you can have HTML markup within a word, but that's very rare.

The other issue is that I'd probably like to somehow make you only see the highlighted words once, so if you're browsing back and forth around the site you don't keep seeing these ugly yellow words staring you in the face. Not sure whether this is a feature or a bug as it stands. Hmm... by the way, it's super easy to set different caching levels in my CMS. To turn caching off, for instance, all I have to say is $cms->setSetting('http.cache',0). Smiley

Lastly, I may eventually do multi-color highlighting like Google does. But plain old yellow will have to suffice for now.

← Girls, please don't get breast implantsClient-side word highlighter →

Comments XML gif

M. Bean wrote:

That is really slick dude. It didn't even dawn on me that this type of thing was even possible.

∴ M. Bean | 29-Apr-2003 2:54am est | #1932

Donncha O Caoimh (http://blogs.linux.ie/xeer/) wrote:

Great minds think alike!
I spent some time at the weekend working on something similar. I highlighted searches on my own site, but I never thought of highlighting Google searches! Cool idea!

Donncha.

∴ Donncha O Caoimh | 29-Apr-2003 9:21am est | http://blogs.linux.ie/xeer/ | #1934

Keith (http://www.keithdevens.com/) wrote:

It didn't even dawn on me that this type of thing was even possible.

I got the idea from Dean Allen. I'd been meaning to try it out for a long time, and it worked pretty well. That's why I was looking for a list of search engine syntaxes yesterday. I didn't get to use any of that code from MT Ref or whatever, but it gave me an idea of how to structure mine.

So, right now this thing works with Google, Yahoo, MSN, AOL, AltaVista, Overture, Ask Jeeves, and AlltheWeb. As I get searches engine hits in my referrers I've been making sure they work, and adding things when they don't. I may do it for searches within my web site someday too.

Keith | 29-Apr-2003 4:51pm est | http://www.keithdevens.com/ | #1935

jim wrote:

got this at the top of my page

Notice: Undefined index: path in /home/keith/kbdcms/Modules/searchengine_module.php on line 78

when i tried your search link from Google back here.

∴ jim | 30-Apr-2003 12:15am est | #1936

Keith (http://www.keithdevens.com/) wrote:

Thanks, small silly error. Fixed.

Keith | 30-Apr-2003 12:21am est | http://www.keithdevens.com/ | #1937

Keith (http://www.keithdevens.com/) wrote:

Actually, I shouldn't even call it an error... it was a typo.

Keith | 30-Apr-2003 12:21am est | http://www.keithdevens.com/ | #1938

202.89.189.183 wrote:

there's no real way to highlight that with regular expressions, since you could have an arbitrary nesting of HTML

Then you have answered your own question. That's the way Google does it and I have yet to see it cause problems in the rendering of a page. Sure it's disgusting when you look at the source code, but on the surface everything seems to be situation normal:

http://72.14.203.104/search?q=cache:74P3...+for+a+list+of+search+engine%22&hl=en

∴ 202.89.189.183 | 22-Jan-2006 3:20pm est | #9041

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

July 2008
SunMonTueWedThuFriSat
 12345
6789101112
13141516171819
20212223242526
2728293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 2 posts

Recent comments XML

getElementsByClass function

http://pitfalls.wordpress.com/2008/​07/07/querying-it-jquery-way-getele​ments...

maxgandalf: Jul 7, 5:50am

Generated in about 0.216s.

(Used 8 db queries)

mobile phone