You can use an SQL statement or XQuery to search through
text search indexes.
Procedure
To search a text search index for a specific term or
phrase, use one of the following methods:
- Search with SQL.
To search a text search
index for a specific term or phrase with an SQL statement, use the
CONTAINS function as follows:
db2 "SELECT column-name FROM table-name
WHERE CONTAINS (...)=1"
For example, the following
query searches the PRODUCT table for the names and prices of various
snow shovels:
db2 "SELECT NAME, PRICE FROM PRODUCT
WHERE CONTAINS (NAME, '"snow shovel"') = 1"
- Search with XQuery.
To search a text search
index for a specific term or phrase using XQuery, use the db2-fn:xmlcolumn-contains() function.
For
example, the following query searches the PRODUCT table for the names
and prices of various snow shovels:
db2 "xquery for \$info in db2-fn:xmlcolumn-contains
('PRODUCT.DESCRIPTION','"snow shovel"')
return <result> {\$info/description/name, \$info/description/price} </result>"
Note: Depending
on the operating system shell that you are using, you might need a
different escape character in front of the dollar sign of the variable
information. The previous example uses the backward slash ( \ ) as
an escape character for UNIX operating
systems.