I've implemented Brian Dunning's Custom function (https://www.briandunning.com/cf/578) for highlighting text within search results.
Let ( [
// TEST FOR MATCH
pos = Position ( text ; searchString ; 1 ; 1 )
// IF MATCH IS FOUND
Case ( pos ;
// BEGIN CALCULATION
Let ( [
textBefore = Left ( text ; pos - 1 ) ;
len = Length ( searchString ) ;
string = Middle ( text ; pos ; len ) ;
textAfter = Right ( text ; Length ( text ) - pos - len + 1 )
textBefore & TextStyleAdd ( string ; HighlightYellow ) & HiliteSingle ( textAfter ; searchString )
I have a field called gUniversalSearch into which the search string is typed and a text field called study titles which it searches. The custom function is applied to the latter as a calculated value.
The search is driven by the following script.
It is kind of working, but I have two questions and would appreciate any help.
When I perform a search not all instances of a search word get highlighted and I would like to clear the highlighted text. Is there something in my above setup that is missing?