Skip to main content

Highlighting

Highlighting

You can highlight words in a returned text using the search_items syntax. Highlighting syntax is:

(text,search_items,search_option)

search_items: Highlighting uses the same search_items syntax as searching. This allows you to use the same search_items value for both returning records and highlighting the strings within those records that caused them to be returned. This also allows you to use the TestSearchString() method to validate highlighting search_items syntax. However, because highlighting is applied to every instance of every match, highlighting ignores the search_items syntax AND, OR, and NOT logical operators in a search_items string.

search_option: The optional search_option can be 0 (the default) or 4 (Regular Expressions).

You can apply highlighting using either of the following:

  • SELECT item highlighting:

    SELECT %iFind.Highlight(Narrative,'"visibility [1-4] mile*" AND "temp* ? degrees"') 
    FROM Aviation.TestSQLSrch 
    WHERE %ID %FIND search_index(NarrBasicIdx,'"visibility [1-4] mile*" AND "temp* ? degrees"',0,'en')
  • Utility method highlighting:

    You can use the %iFind.Utils.Highlight()Opens in a new tab method to perform an SQL Search and apply highlighting to the results.

By default, highlighting inserts the <b> and </b> (bold) XML tags at the appropriate places in the string. By default, highlighting is not case sensitive.

Highlighting can be used with any search_option, including Regular Expression search (search_option=4), as shown in the following example:

  SET x="Time flies like an arrow. other stuff. Fruit flies like a banana."
  WRITE ##class(%iFind.Utils).Highlight(x,"\p{LU}(\p{L}|\s)+",4)

When used with Word Search, this method highlights separately each occurrence of each specified word.

When used with Positional Phrase Search, this method highlights each occurrence of the positional phrase.

FeedbackOpens in a new tab