IBM Books
(C) IBM Corp. 2000, 2003.

Net Search Extender

管理和用户指南


有关视图的文本索引

当使用存储过程时,能够对视图创建文本索引。但是,它的一个主要缺点是不能对视图创建触发器,因此,不能识别底层基本表中的任何更改。

因此,对于增量索引更新,用户必须清楚已经添加、更新或删除了哪些文档以便使文本索引与数据库同步。为此,必须将所有更改添加至日志表。以下样本中说明了此过程:

  1. 要创建基本表,使用以下命令:
    db2 "create table sample (key INTEGER not null  PRIMARY KEY, name
                VARCHAR(50) not null, comment VARCHAR(90))" 
    
  2. 要添加一些条目,使用下列命令:
    db2 "insert into sample values(1,'Claus','works in room 301')"
    db2 "insert into sample values(2,'Manja','is in the same office
                                   as Juergen')"
    db2 "insert into sample values(2,'Juergen','has the longest way to
                                   Raiko')"
    db2 "insert into sample values(3,'Raiko','is sitting in the office
                                   besides Claus ')"
    
  3. 要创建视图,使用以下命令:
    db2 "create view sampleview as select key, comment from sample"
    
  4. 使用下列命令来创建、更新和激活文本索引:
    db2text "create index indexview for text on hde.sampleview(comment)
                cache table (comment) maximum cache size 1 key columns
                for index on view (key)"
    db2text "update index indexview for text"
    db2text "activate cache for index indexview for text"
    
    注意

    需要指定高速缓存表以便能够对视图创建文本索引。要创建正确的日志表,必须对视图的索引指定键列。

    在分布式 DB2 环境中,必须在单个节点上为管理表显式指定表空间,并在此节点上显式调用。

    为了确保连接至正确的节点,使用 DB2NODE 环境变量。

  5. 要更新表,使用下列命令:
    db2 "insert into sample values(4,'Bernhard','is working in the same floor
                as Manja, but not as Claus')"
    db2 "insert into sample values(5,'Guenter','shares the office with Raiko')"
    
  6. 然后,更新日志表。要获取日志表的名称,使用以下命令:
    db2 "select INDSCHEMA,INDNAME,LOGVIEWSCHEMA,LOGVIEWNAME
         from db2ext.textindexes"
    
    以下是日志表的布局:
    sqltype               sqllen  sqlname.data             sqlname.length
    --------------------  ------  -----------------------  --------------
    496   INTEGER              4  OPERATION                             9
    392   TIMESTAMP           26  TIME                                  4
    497   INTEGER              4  PK01                                  4   
    
    要将条目添加到日志表中,使用下列命令:
    db2 "insert into sample values(0,CURRENT TIMESTAMP,4)"
    db2 "insert into sample values(0,CURRENT TIMESTAMP,5)"
    
    第一个值用来描述操作(0 = 插入,1 = 更新,2 = 删除)。第二个值应当始终是 CURRENT TIMESTAMP,而最后一个值是已经插入的键。
  7. 使用以下命令再次更新该索引:
    db2text "update index indexview for text"
    

现在,可以使用存储过程对新值进行搜索了。


[ 页的顶部 | 上一页 | 下一页 | 目录 | 索引 ]