%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
Comments
Since ##class(%iFind.Utils).Highlight and %iFind.Highlight are the same method, you can pass fourth pTags argument to it:
SELECT %iFind.Highlight(Narrative,'"visibility [1-4] mile*" AND "temp* ? degrees"', , "<span>")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.1SSA*^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.TempSearchableI 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')Interesting. I did get this to work but don't believe it's calling the %iFind.Utils:Highlight method. The reason I say this is that the method has extra parameters that don't correspond to the SQL %Fimd.Highlight SQL function.
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.
I must not have had enough coffee today because it looks right to me.
:)