Question
· Feb 5, 2020

%iFind.Highlight

Hi

I've been working with SQL using an iFind index to search text.   Using the %iFind.Highlight function in my SELECT statement I can get text back that highlights the found words using <b> and </b>

I am aware that using ##class(%iFind.Utils).Highlight, I can pass a parameter to override the <b> tag and use instead a <span> tag with style to change the background color of the found words.

Is there a way to override the <b> tag from a SQL statement?

Thanks

Discussion (6)1
Log in or sign up to continue

Eduard,

I had seen that in the docs and have tried various flavors of it.  I am using embedded SQL in a classmethod here to do my search.   Here's the method

ClassMethod Search(pSessionId As %String, pSearchString As %String) As %Stream.GlobalCharacter
{
    set tTags="<span style='background-color:yellow;'>"
    &sql(
    SELECT %iFind.Highlight(Text , :pSearchString , '' , :tTags) into :results 
    FROM SSA_OCR.TempSearchable)
    quit results
}

When I try to use this, I get:

SSA>s rs=##class(SSA.OCR.TempSearchable).Search(20, "Cough")
 
 quit results }
 ^
<UNDEFINED>zSearch+7^SSA.OCR.TempSearchable.1 *results
SSA 2e1>w results
 
W results
^
<UNDEFINED>^SSA.OCR.TempSearchable.1 *results
SSA 2e1>w %objlasterror
0 àŠ=<CLASS DOES NOT EXIST>zApplyTransformation+6^%iFind.Utils.1”SSAŠ*^zApplyTransformation+6^%iFind.Utils.1^15d^zPrepareTransformations+27^%iFind.Filer.Basic.1^1(d^zFileIndex+33^%iFind.Filer.Basic.1^1*d^zFileIndex+8^%iFind.Filer.Semantic.1^1*d^zFileIndex+5^%iFind.Filer.Analytic.1^1"d^zHighlight+17^%iFind.Utils.1^1,e^%0JmCm3l4tudf^SSA.OCR.TempSearchable.1^41e^%0JmBuncommitted+1^SSA.OCR.TempSearchable.1^1(d^zSearch+6^SSA.OCR.TempSearchable.1^1e^^^0
SSA 2e1>d $System.OBJ.DisplayError(%objlasterror)
 
ERROR #5002: ObjectScript error: <CLASS DOES NOT EXIST>zApplyTransformation+6^%iFind.Utils.1
SSA 2e1>

Any thoughts on why this is erroring?

Try double quotes inside:

SELECT %iFind.Highlight(Text , :pSearchString , ,'<span style="background-color:yellow;">') into :results
FROM SSA_OCR.TempSearchable

I checked on my dataset and this query works for me:

SELECT *, %iFind.Highlight(Text,'hello', , '<span style="background-color:yellow;">')
FROM Test.Data
WHERE %ID %FIND search_index(TextIndex,'hello')

The reason I say this is that the method has extra parameters that don't correspond to the SQL %Fimd.Highlight SQL function.  

What do you mean? Highlight method signature:

ClassMethod Highlight(pText As %String, pSearchString As %String, pSearchOption As %String = {$$$IFSEARCHNORMAL}, pTags As %String = {$$$IFDEFAULTHLTAGS}, pLimit As %Integer = 0, pLanguage As %String = "en", Output pSC As %Status) As %String [ SqlName = Highlight, SqlProc ]

Shows that it is available in SQL context (bolded). All classmethod arguments (except sc) can be passed from SQL.