How do you highlight searched words in results?

This is a simple matter of finding the text you are looking for, and replacing this text with a highlighted version of the same text. This can be accomplished using the replaceNoCase() function.

<cfset myText = "This is my text!">
<cfset myWord = "my">
<cfoutput>#replaceNoCase(myText,myWord,"<span style='background:yellow'>#myWord#</span>","all")#</cfoutput>

Also, Verity searches support this functionality right out of the box using the context column. In your Verity result set, the context column returns a context summary containing the search terms, highlighted in bold. (This is enabled if you set the contextpassages attribute to a number greater than zero.). If bolding your search term is not enough, you can use the contextHighlightBegin and contextHighlightEnd attributes to append custom HTML before and after your search term.

This question was written by Jeremy Petersen
It was last updated on June 30, 2006.

Categories

Strings
Full-Text Searching

Comments

comments powered by Disqus