There are two SQL table-valued functions available, both called db2ext.textsearch. To use the db2ext.highlight function, you must use the db2ext.textsearch function with the additional numberOfHits and hitInformation parameters.
In this example, call the db2ext.highlight function to display the whole document without highlighting any hits found by the db2ext.textsearch function.
select p.docid, db2ext.highlight(p.comment, t.hitinformation, 'WINDOW_NUMBER = 0') as highlight from DB2EXT.TEXTTAB p, table (db2ext.textsearch('"bestseller" | "peacekeeping" | "soldiers" | "attention"', 'DB2EXT', 'COMMENT', 0, 20, cast(NULL as INTEGER), 10)) t where p.docid = t.primkey and p.docid = 2
The search argument returns the following result:
DOCID HIGHLIGHT 2 A New York Times bestseller about peacekeeping soldiers called "Keepers" who devise a shocking scheme to get the worlds attention after their tour of duty ends. 1 record(s) selected.
In all the db2ext.highlight examples, the table function db2ext.textsearch searches for any of the following words: "bestseller", "peacekeeping", "soldiers", or "attention".
In this example, call the db2ext.highlight function to display the whole document and highlight all hits found by the db2ext.textsearch function.
select p.docid, db2ext.highlight(p.comment, t.hitinformation, 'WINDOW_NUMBER = 0, TAGS = ("<bf>", "</bf>" ) ') as highlight from DB2EXT.TEXTTAB p, table (db2ext.textsearch('"bestseller" | "peacekeeping" | "soldiers" | "attention"', 'DB2EXT', 'COMMENT', 0, 20, cast(NULL as INTEGER), 10)) t where p.docid = t.primkey and p.docid = 2
The search argument returns the following result:
DOCID HIGHLIGHT 2 A New York Times <bf>bestseller</bf> about <bf>peacekeeping</bf> <bf>soldiers</bf> called "Keepers" who devise a shocking scheme to get the worlds <bf>attention</bf> after their tour of duty ends. 1 record(s) selected.
In this example, call the db2ext.highlight function to display at maximum 10 parts (windows) of the document. Each window size is 24, which is approximately 12 bytes of data on each side of the hit. In addition, hits found by the table function db2.textsearch are highlighted.
select p.docid, db2ext.highlight(p.comment, t.hitinformation, 'WINDOW_NUMBER = 10, WINDOW_SIZE = 24, TAGS = ("<bf>", "</bf>" ) ') as highlight from DB2EXT.TEXTTAB p, table (db2ext.textsearch('"bestseller" | "peacekeeping" | "soldiers" | "attention"', 'DB2EXT', 'COMMENT', 0, 20, cast(NULL as INTEGER), 10)) t where p.docid = t.primkey and p.docid = 2
The search argument returns the following result:
DOCID HIGHLIGHT 2 York Times <bf>bestseller</bf> about <bf>peacekeeping</bf> ... <bf>peacekeeping</bf> <bf>soldiers</bf> called "Keepers" ... the worlds <bf>attention</bf> after their 1 record(s) selected.
The first hit found is <bf>bestseller</bf> and this hit determines the first window. The second hit, <bf>peacekeeping</bf> is only 8 bytes away from the first hit and is completely taken into the first window. The third hit, <bf>soldiers</bf> is outside the first window and determines a new window. As the second hit <bf>peacekeeping</bf> is only 2 bytes away from the left side of the <bf>soldiers</bf> hit, it is also taken into the second window and highlighted. The fourth hit <bf>attention</bf> is outside the second window and so determines a new window. As no previous or additional hit is contained in the size of this window, only data surrounding the hit is contained in the window.
Additionally, as no WINDOW_SEPARATOR is specified, the default window separator, " ... " is taken to separate the three document windows.
To ensure high performance when using the db2ext.highlight function, the user should limit the search results in the db2ext.textsearch table-valued function.
See the DB2EXT.HIGHLIGHT for further details on the parameters.