`

有关DB2 Net Search Extender V9.1简单介绍

阅读更多

DB2 Net Search Extender V9.1是DB2 Extender系统中的一个产品,对于存储在DB2,其他数据库和文件系统中的文本文档,DB2 Net Search Extender V9.1为用户和应用程序提供了一种使用SQL查询来搜索这些文档的快速、通用和智能的方法。


一、使用SQL标量函数搜索:
1、启动搜索引擎并创建数据库
db2text start
db2 create db testdb
2、启用数据库以进行文本搜索
db2text enable database for text connect to testdb
3、创建表
db2 connect to testdb
db2 "CREATE TABLE books (isbn VARCHAR( 18 ) not null PRIMARY KEY,author VARCHAR(30), story LONG VARCHAR, year INTEGER)"
db2 terminate
4、对文本列创建索引
db2text "CREATE INDEX db2ext.myTextIndex FOR TEXT ON books (story) CONNECT TO testdb"
5、插入测试数据
db2 connect to testdb
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)"
db2 terminate
6、使文本索引同步
db2text "UPDATE INDEX db2ext.myTextIndex FOR TEXT CONNECT TO testdb"
7、使用SQL标量函数搜索
db2 connect to testdb
db2 "SELECT author, story FROM books WHERE CONTAINS(story, '\"cat\"') = 1 AND YEAR >= 2000"

二、使用高速缓存用法和存储过程搜索:
1、对story列创建文本索引mySTPTextIndex,对author与story创建高速缓冲表
db2text "CREATE INDEX db2ext.mySTPTextIndex FOR TEXT ON books (story) CACHE TABLE (author, story) MAXIMUM CACHE SIZE 1 CONNECT TO testdb"
2、使用表的数据更新索引
db2text "UPDATE INDEX db2ext.mySTPTextIndex FOR TEXT CONNECT TO testdb"
3、激活高速缓存表
db2text "ACTIVATE CACHE FOR INDEX db2ext.mySTPTextIndex FOR TEXT CONNECT TO testdb"
4、使用db2ext.textSearch存储过程进行搜索
db2 "call db2ext.textSearch('\"cat\"','DB2EXT','MYSTPTEXTINDEX',0,2,0,0,?,?)"
5、取消调整缓存表
db2text "DEACTIVATE CACHE FOR INDEX db2ext.mySTPTextIndex FOR TEXT CONNECT TO testdb"

三、使用SQL标量表函数搜索:
db2 "SELECT author, story FROM books b, table (db2ext.textsearch('\"cat\"','DB2EXT','MYTEXTINDEX', 0, 2, CAST(NULL AS VARCHAR( 18 )))) T where T.primKey = b.isbn"

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics