IBM Books

XML Extender Administration and Programming

Using the Text Extender for structural text search

When searching the XML document structure, the XML Extender searches element and attribute values that are converted to general data types, but it does not search text. You can use the DB2 UDB Text Extender for structural or full text search on a column that is enabled for XML. The Text Extender supports XML document search in DB2 UDB version 6.1 or higher.

Structural text search
Searches text strings that are based on the tree structure of the XML document. For example, if you have the document structure of /Order/Customer/Name and you want to search for the character string "IBM" within the <Customer> subelement, you can use a structural text search. The document might also have the string IBM in a <Comment> subelement or as the name of part of a product. A structural text searches only in the specified elements for the string. In this example, only the documents which have IBM in the </Order/Customer/Name> subelement are found; the documents that have IBM in other elements but not in the </Order/Customer/Name> subelement are not returned.

Full text search
Searches text strings anywhere in the document structure, without regard to elements or attributes. Using the previous example, all documents that have the string IBM would be returned regardless of where the character string IBM occurs.

To use the Text Extender search, you must install the DB2 Text Extender and enable your database and tables as described below. To learn how to use the Text Extender search, see the chapter on searching with the Text Extender's UDFs in DB2 Universal Database Text Extender Administration and Programming.

Enabling an XML column for the Text Extender

Assuming that you have an XML-enabled database, use the following steps to enable the Text Extender to search the content of an XML-enabled column. For example purposes, the database is named SALES_DB, the table is named ORDER, and the XML column names are XVARCHAR and XCLOB:

  1. See the install.txt file on the Extenders CD to learn how to install the Text Extender.
  2. Enter the txstart command from one of the following locations:
  3. Open the Text Extender command line window. This step assumes that you have database named SALES_DB and a table named ORDER, which has two XML columns named XVARCHAR and XCLOB. You might need to run the sample programs in dxx\samples\c.
  4. Connect to the database. At the db2tx command prompt, type:
    'connect to SALES_DB' 
    
  5. Enable the database for the Text Extender.

    From the db2tx command prompt, type:

    'enable database'
    
  6. Enable the columns in the XML table for the Text Extender, defining the data types of the XML document, the language, code pages, and other information about the column.
  7. Check the status of the index.
  8. Define the XML document model in a document model ini file called desmodel.ini. This file is in: /db2tx/txins000 for UNIX and \instance\\db2tx\txins000 for Windows NT and sections in an initialization file. For example, for the textmodel.ini:
    ;list of document models
    [MODELS]
    modelname=Order
     
    ; an 'Order' document model definition
    ; left side = section name identifier
    ; right side = section name tag
     
    [Order]
    Order = /Order
    Order/Customer/Name = /Order/Customer/Name
    Order/Customer/Email = /Order/Customer/Email
    Order/Part/@color = /Order/Part/@color
    Order/Part/Shipment/ShipMode = /Order/Part/Shipment/ShipMode
     
    

Searching for text using the Text Extender

The Text Extender's search capability works well with the XML Extender document structural search. The recommended method is to create a query that searches on the document element or attributes and uses the Text Extender to search the element content or attribute values.

Example: The following statements search an XML document text with the Text Extender. At the DB2 command window, type:

'connect to SALES_DB'   
'select xvarchar from order where db2tx.contains(varcharhandle, 
	 'model Order section(Order/Customer/Name) "Motors"')=1'   
'select xclob from order where db2tx.contains(clobhandle, 
	 'model Order section(Order/Customer/Name) "Motors"')=1'

The Text Extender Contains() UDF searches.

This example does not contain all of the steps that required to use the Text Extender to search column data. To learn about the Text Extender search concepts and capability, see the chapter on searching with the Text Extender's UDFs in DB2 Universal Database Text Extender Administration and Programming.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]