Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlight Multiple Words in Results

Status
Not open for further replies.

neofactor

Technical User
Jul 30, 2000
194
US
Hi:

Well.. I have a stumper.... I need a Highlight tag that is a bit smarter than the ones I have seen.

Basically I have an index search that allows you to search multiple words... and I highlight the matches throughout the results.

I have many methods that work great if you only have one feild keyword.... It will wrap a font tag around the word and add a style to highlight it. The problem is when it loops through the same paragraph to search for the second word.. to highlight it... the problem lies in that I have just introduced new characters into the description.. namely the font tag &quot;<font color=red style=background:yellow;&quot;.

The problem is it now tries to highlight ant matches thaty might be in those new letters... like background... it thinks it is part of the description.. and if I had a keyword called background... it matches and adds yet another font tag around it.. thus breaking it and shoing partial font tags in the results.

Does this make sense...
If not I can show you an example:

The custom tag that loops around it is this:
Code:
Partial code... but you get the idea... I add some info around any matches.. an opentag like: <font color=red style=background:yellow;> and a closetag like: </font>
The substring list is the list of keywords to highlight.

<CFLOOP Index=Substring
List=&quot;#SubStringList#&quot;>
<CFSET CurrentChar=1>
<CFSET Start=1>

<CFLOOP CONDITION=&quot;START ge 0&quot;>
<CFSET Substring=Trim(Substring)>
<CFSET Start=#FindNoCase(Substring, String, CurrentChar)#-1>
<CFIF Start ge 0>

<CFSET End=#Start# + #Len(SubString)# >
<CFSET String=Insert(CloseTag,String,End)>
<CFSET String=Insert(OpenTag,String,Start)>
<CFSET CurrentChar=End + Len(OpenTag & Closetag)>

</cfif>
</cfloop>

</cfloop>

Any ideas to do an exception to not highlight the <font> tag info, if it contains a keyword match?

Please let me know if you have a smart- smart results highlighter... all I see on MM exchange dont do it for me.

Thanks
 
Man... I jump on these things too quick... I find an answer like 20 minutes after I post....

I think it is the act of posting that makes me look further.. sort of a break.... a chance to take a breath.

I found a UDF (User Defined Function) that is for a single highlight but in the forum.. it talks about some work arounds for multiple passes.



I'll post a full fix here after I look at it in the moring.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top