Creating a text search index
After you enable a database for Db2® Text Search, you can create text search indexes on columns that contain the text that you want to search.
Before you begin
- CONTROL privilege on the index table
- INDEX privilege on the index table with either the IMPLICIT_SCHEMA authority on the database or the CREATEIN privilege on the index table schema
- DBADM with DATAACCESS authority
To schedule automatic index updates, the instance owner must have DBADM authority or CONTROL privileges on the administrative task scheduler tables.
A primary key must exist for this table. If a primary key does not exist, you must create one before creating the index.
About this task
db2ts "CREATE INDEX MYSCHEMA.MYTEXTINDEX FOR TEXT ON PRODUCT(NAME)
UPDATE FREQUENCY d(1,3) h(0,12) m(0) UPDATE MINIMUM 5"
CALL SYSPROC.SYSTS_CREATE('myschema', 'myTextIndex', 'product (name)',
'UPDATE FREQUENCY D(1,3) H(0,12) M(0)' 'UPDATE MINIMUM 5', 'en_US', ?)
When you create an index, you can specify its locale (language and territory) by using the LANGUAGE option. To have your documents automatically scanned to determine the locale, set the LANGUAGE to AUTO. If you do not specify LANGUAGE, a default is used. This default is derived using the DEFAULTVALUE from SYSIBMTS.TSDEFAULTS where DEFAULTNAME='LANGUAGE'. (In this case, DEFAULTVALUE is set at the time the database is enabled for text search. This value is derived from the database territory if the database territory can be mapped to one of the document locales supported. If the database territory cannot be used to determine a supported document locale, DEFAULTVALUE is set to AUTO.)
Restrictions
- A text column in an index must be one of the following supported types:
- CHAR
- VARCHAR
- LONG VARCHAR
- CLOB
- GRAPHIC
- VARGRAPHIC
- LONG VARGRAPHIC
- DBCLOB
- BLOB
- XML
- Text search related objects must follow not only DB2® naming conventions, their identifiers must also contain these characters only:
- [A-Za-z][A-Za-z0-9@#$_]* or
- "[A-Za-z ][A-Za-z0-9@#$_ ]*"
- the name of the schema containing the text search index
- the name of the table the text search index is associated with
- the name of the text column
- the name of the text search index
Procedure
Create a text search index using one of the following methods:
Examples
For example, the PRODUCT table in the SAMPLE database includes columns for the product ID, name, price, description, and so on. To create a text search index called MYSCHEMA.MYTEXTINDEX for the NAME column, issue the command or called the stored procedure, as follows:
db2ts "CREATE INDEX MYSCHEMA.MYTEXTINDEX FOR TEXT ON PRODUCT(NAME)"
CALL SYSPROC.SYSTS_CREATE('MYSCHEMA', 'MYTEXTINDEX', 'PRODUCT(NAME)', '', 'en_US',?)
db2ts "CREATE INDEX MYSCHEMA.MYXMLINDEX FOR TEXT ON PRODUCT(DESCRIPTION)"
or CALL SYSPROC.SYSTS_CREATE('MYXMLINDEX', 'MYXMLINDEX',
'PRODUCT (DESCRIPTION)', '', 'en_US', ?)