WEB开发网
开发学院数据库DB2 使用 DB2 Text Search 进行全文本搜索 阅读

使用 DB2 Text Search 进行全文本搜索

 2009-11-20 00:00:00 来源:WEB开发网   
核心提示: 清单 5. 启用数据库文本搜索的命令,它包含特定的连接信息db2ts"ENABLEDATABASEFORTEXTCONNECTTOmytstestUSERdb2adminUSINGmypswd"连接到数据库 mytstest:清单 6. 连接到数据库 mytstest con



清单 5. 启用数据库文本搜索的命令,它包含特定的连接信息
db2ts "ENABLE DATABASE FOR TEXT CONNECT TO mytstest USER db2admin USING mypswd" 

连接到数据库 mytstest:


清单 6. 连接到数据库 mytstest
connect to mytstest 

创建并填充一个表:


清单 7. 表 books
CREATE TABLE books ( isbn VARCHAR(18) NOT NULL PRIMARY KEY, 
           author VARCHAR(30), 
           title VARCHAR(128), 
           year INTEGER, 
           bookinfo XML) 

注意,为了能够创建文本索引和运行文本搜索查询,必须为数据表指定一个主键。

将以下数据插入到 books 表中:


清单 8. 将数据插入到 books 表中
INSERT INTO books VALUES ('123-014014014', 'Joe Climber', 
             'Climber''s Mountain Tops',1995, 
XMLPARSE( 
DOCUMENT '<bookinfo>  
 <author>Joe Climber</author> 
<title>Climber''s Mountain Tops</title> 
<story>This vivid description of Joe Climber''s experiences 
when tackling the mountains of his native Mountainland lets you 
hold your breath when you follow Joe on his adventures in the regions where 
 the air is thin and the weather is treacherous. Includes beautiful color photos 
 of Mountainland''s mountain ranges.</story> 
  <year>1995</year> 
  <price>16.00</price> 
  <pages>176</pages> 
</bookinfo>')); 
 
INSERT INTO books VALUES ('678-014014078', 'Joe Smith', 'The Range', 1991, 
XMLPARSE( 
DOCUMENT '<bookinfo> 
 <author>Joe Smith</author> 
<title>The Range</title> 
<story>All you need to know about kitchen ranges. A pictured description 
 based on the most recent ergonomics studies for everybody who is involved in 
 food preparation in the home.</story> 
  <year>1991</year> 
  <price>6.00</price> 
  <pages>76</pages> 
</bookinfo>')); 
 
INSERT INTO books VALUES ('111-223334444', 'Sam Climber', 
'Top of the Mountain: Mountain Lore', 1966, 
 XMLPARSE( 
 DOCUMENT '<bookinfo> 
 <author>Sam Climber</author> 
 <title>Top of the Mountain: Mountain Lore</title> 
 <story>Sam Climber has traveled through the world to gather 
stories about mountains. This compendium includes the best stories 
and is beautifully illustrated.</story> 
  <year>1966</year> 
  <price>20.00</price> 
  <pages>449</pages> 
 </bookinfo>')); 
 
 INSERT INTO books VALUES ('777-010101010', 'Samantha Smitt', 
     'The Database Compendium', 2001, 
 XMLPARSE(DOCUMENT 
 '<bookinfo> 
 <author>Samantha Smitt</author> 
 <title>The Database Compendium</title> 
<story>Follow Samantha into the world of database management. 
Covers a wide range of the most popular database architectures.</story> 
  <year>2001</year> 
  <price>19.00</price> 
  <pages>222</pages> 
 </bookinfo>')); 
 
 INSERT INTO books VALUES ('123-918273645', 'Joanne Miller', 
    'The Travel Companion', 2005, 
 XMLPARSE( 
 DOCUMENT '<bookinfo> 
 <author>Joanne Miller</author> 
 <title>The Travel Companion </title> 
 <story>If you like to travel, this is the book for you. Joanne Miller has compiled 
 her funny and often surprising diary entries about places and people which were 
 previously published as travel log in ''Here and There''</story> 
  <year>2005</year> 
  <price>31.00</price> 
  <pages>321</pages> 
 </bookinfo>')); 

上一页  1 2 3 4 5 6 7 8  下一页

Tags:使用 DB Text

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接