日期:2014-05-16  浏览次数:20524 次

【引用】Oracle全文检索方面的研究(全9)

3.10常用的脚本

3.10.1.删除preference:

begin

ctx_ddl.drop_preference('my_lexer');

end;

?

3.10.2.索引重建:

ALTER INDEX newsindex REBUILD PARAMETERS('replace lexer my_lexer');

?

3.10.3 同步索引

begin

ctx_ddl.sync_index('myindex', '2M');

end;

或通过后台设置同步脚本:

$ORACLE_HOME/ctx/sample/script/drjobdml.sql --后台同步脚本(9i 中有,10g 不知道放哪儿了,文档有问题)

SQL> @drjobdml myindex 360 --表示以周期360 分钟同步索引myindex

或通过创建索引加参数实现

--表示每小时同步一次,内存16m

CREATE INDEX IND_m_high ON my_high(DOCS) INDEXTYPE IS CTXSYS.CONTEXT

parameters ('sync (EVERY "TRUNC(SYSDATE)+ 1/24") memory 16m ') parallel 2 online;

(确认这个时间间隔内索引同步能完成,否则,sync job 将处于挂起状态)

--还可以是

sync (manual) --手工同步,默认

sync (on commit) --dml 后立即同步

--通过job 定义同步

declare

job number;

begin

dbms_job.submit(job,

'ctx_ddl.sync_index(''ind_m_high'');', --索引名

interval => 'SYSDATE+1/1440'); --1 分钟一次

commit;

dbms_output.put_line('job ' || job || ' has been submitted.');

end;

?

?

3.10.4.索引碎片:

刚开始建立索引后,DOG 可能是如下的条目

DOG DOC1 DOC3 DOC5

新的文档增加到表后,新行会同步到索引中去,假设新文档中Doc7 中的DOG 被同步到索引中去,DOG

可能变成如下条目

DOG DOC1 DOC3 DOC5

DOG DOC7

随后的DML 操作可能变成:

DOG DOC1 DOC3 DOC5

DOG DOC7

DOG DOC9

DOG DOC11

这就产生了碎片,需要进行索引的优化

查看索引碎片

create table output (result CLOB);

declare

x clob := null;

begin

ctx_report.index_stats('idx_auction', x);

insert into output values (x);

commit;

dbms_lob.freetemporary(x);

end;

select * from output

?

3.10.5索引优化:

快速fast 优化和全部full 优化的区别是,快速优化不会删除没用的、过期的数据,而full 会删除老的数据(deleted rows)

--快速优化

begin

ctx_ddl.optimize_index('myidx','FAST');

end;

--全部优化

begin

ctx_ddl.optimize_index('myidx','FULL');

end;

--对单个记号进行优化,默认是full 模式

begin