×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Search Utilities

Highlighting Query Side and Code Side by webmigit
Posted: 13 Aug 02 (Edited 21 Aug 02)

Glowball wrote an excellent piece of code for highlighting (FAQ232-1167).. but I felt it lacked in a few areas.. Here is where I add what I can to the cause

<CFSET LocalTD=ReReplaceNoCase(LocalTD,"[^A-Za-z0-9](#currword#)[^A-Za-z0-9]"," <span class=""highlight"">\1</SPAN> ","ALL")>

The above code is used to highlight the word when it appears as itself.. it can be followed by any punctuation but has to be a word of its own..

The [^A-Za-z0-9] before (#currword#) tells cold fusion to search for the string when not preceded by any alphanumeric character.. The [^A-Za-z0-9] after (#currword#) likewise tells Cold Fusion to search for the word in cases where it is not followed by an alphanumeric character..

Placing #currword# in parentheses creates the temporary variable \1.. We use this variable to replace our undefined characters with those same undefined characters surrounded by something..

In my case, I surrounded the string which my code did not know at design time with <span></span> to create a highlight-marker effect. Should you want the same effect, add this to your style sheet:

.highlight {  background-color: #FFFF00}

Then there is the issue I came across.. I wanted to find my keywords but I didn't want to return results from my query that contained my keywords but not as a whole.. my query was returning things like this:

+------------------------------------------+
| WORD | Matches                           |
+------------------------------------------+
|  AN  | and, than, candle, etc            |
+------------------------------------------+
|  HE  | the, they, hell, she, then, there |
+------------------------------------------+


This obviously caused problems.. And no one seemed to know what to do about it.. I settled for a very complex regex that ran a like statement for every concievable condition my word could be in.

I will save you the trouble, the headaches, the long coding hours, and the psychiatric bills caused by doing it that way.

Access has an extensive wildcard capability.. much like the find syntax for regex.. except that MS can never seem to comply to a standard completely (which admittedly, is why IE dominates the browser field)... I assumed this and tried to run my like statement like this:

dbField LIKE '%[^A-Za-z0-9]#myKeyword#[^A-Za-z0-9]%'

It was a failure, the sql did not function properly so I went back to my complex regex that ran about 15 LIKEs per term.. a royal headahce.. And then I was looking through the MS Access help files and found that MS, for Access at least, had their own way of being different for this issue.. Instead of using the carat (^) in brackets to signify characters that cannot be there, MS uses the exclamation point (!).. My statement now became:

dbField LIKE '%[!A-Za-z0-9]#myKeyword#[!A-Za-z0-9]%'

And it works perfectly..

So if you want to do advanced searching without some third party tag and want direct control of your queries, this code is your start.

If this helps, please rate it!

Tony Hicks

Back to Adobe FAQ Index
Back to Adobe Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close