Full-text search in XML documents
Full-text search of natively stored XML data is available through Db2® Net Search Extender.
Important: Net Search Extender (NSE) is no longer supported in
Db2. Use the Db2 Text Search feature.
Db2 Net Search Extender
Db2 Net Search Extender fully supports the XML data type. It provides full-text indexing of documents stored in XML columns. By creating a text index on an XML column, you can query all text within an XML document and perform searches such as proximity or wildcard searches. Db2 Net Search Extender is part of all Db2 data server products for Linux®, UNIX, and Windows, but must be installed separately.
The following example shows a simple full-text search that finds the word "marketing" anywhere
within the path /dept/description of XML documents stored in the DEPTDOC column:
SELECT DEPTDOC
FROM DEPT
WHERE contains (DEPTDOC, SECTIONS("/dept/description") "marketing") = 1
The contains function, provided by Db2 Net Search Extender,
searches for the string "marketing" in any text under the path /dept/description, including element
or attribute names, and element or attribute values.To use full-text search, SQL
must be used. The results from the SQL query, however, can still
be returned to an XQuery context for further processing. The following
example shows how the results from an SQL query that used full-text
search can participate in an XQuery expression:
XQUERY for $i in db2-fn:sqlquery ('SELECT DEPTDOC FROM DEPT
WHERE contains
(DEPTDOC, SECTIONS("/dept/description") "marketing") = 1')//employee
return $i/name
In this example, the results of the SQL query, which
exploited full-text search, are returned to the for clause of the
XQuery FLWOR expression. The for clause then returns all <employee>
elements, and the return clause returns the <name> elements
within the retrieved <employee> elements.For more information on Db2 Net Search Extender, refer to the Db2 Net Search Extender documentation or see the Net Search Extender Knowledge Collection.