Use the following steps in the DB2 Net Search Extender example:
You can issue the sample commands on the command line of the operating system by using an existing database. For the following examples, the database name is sample.
db2 "create database sample"
db2text "START"Use the following command to prepare the database for use with DB2 Net Search Extender:
db2text "ENABLE DATABASE FOR TEXT CONNECT TO sample"You need to do this step only once for each database.
db2 "CREATE TABLE books (isbn VARCHAR(18) not null PRIMARY KEY, author VARCHAR(30), story LONG VARCHAR, year INTEGER)"This DB2 command creates a table called books. It contains columns for the author, story, isbn number, and the year the book was published.
db2text "CREATE INDEX db2ext.myTextIndex FOR TEXT ON books (story) CONNECT TO sample"This command creates a full-text index for the column story. The name of the text index is db2ext.myTextIndex
db2 "INSERT INTO books VALUES ('0-13-086755-1','John', 'A man was running down the street.',2001)" db2 "INSERT INTO books VALUES ('0-13-086755-2','Mike', 'The cat hunts some mice.', 2000)" db2 "INSERT INTO books VALUES ('0-13-086755-3','Peter', 'Some men were standing beside the table.',1999)"These commands load the isbn, author, story, and publishing year for these books into the table.
db2text "UPDATE INDEX db2ext.myTextIndex FOR TEXT CONNECT TO sample"
db2 "SELECT author, story FROM books WHERE CONTAINS (story, '\"cat\"') = 1 AND YEAR >= 2000"
Depending on the operating system shell you are using, you might need a different escape character in front of the double quotes surrounding the text search phrase. The above example, uses "\" as an escape character.
This query searches for all books about the term cat that are greater or equal to the year 2000. The query returns the following result table:
AUTHOR STORY Mike The cat hunts some mice.
Other functions supported include SCORE and NUMBEROFMATCHES. SCORE returns an indicator on how well the search argument describes a found document. NUMBEROFMATCHES returns how many matches of the query terms are found in a resulting document.