oracle全字段检索,Oracle数据库建某字段全文全文检索

一、建表

create table myindextest (tid varchar2(50) primary key,

btext BLOB)

二、建索引及参数

1、中文分词及分词属性设置

begin

ctx_ddl.create_preference('cnlex','CHINESE_LEXER');

ctx_ddl.create_preference('mywordlist','BASIC_WORDLIST');

ctx_ddl.set_attribute('mywordlist','PREFIX_INDEX','TRUE');

ctx_ddl.set_attribute('mywordlist','PREFIX_MIN_LENGTH',1);

ctx_ddl.set_attribute('mywordlist','PREFIX_MAX_LENGTH',8);

ctx_ddl.set_attribute('mywordlist','SUBSTRING_INDEX','YES');

END;

2、设置中文过滤(中文编码)

begin

ctx_ddl.create_preference('cs_filter','CHARSET_FILTER');

ctx_ddl.set_attribute('cs_filter','charset','UTF8');

end;

3、创建索引

create index idx_myindextest on myindextest(btext)

indextype is ctxsys.context

parameters('DATASTORE CTXSYS.DIRECT_DATASTORE

FILTER cs_filter

LEXER CNLEX

WORDLIST MYWORDLIST');

三、查询

1、查看分词情况

SELECT * FROM dr$idx_myindextest$I

2、通过关键词查询记录

select * from myindextest where contains(btext,'正常')>0

四、同步 优化

begin

Ctx_ddl.sync_index('idx_myindextest','2M');

End;

begin

Ctx_dll.optimize_index('myidx','full');

End;

五、定时任务执行执行作业进行同步

create or replace procedure sync

is

begin

execute immediate

'alter index idx_myindextest rebuild online' ||

' parameters ( ''sync'' )'

execute immediate

'alter index idx_myindextest rebuild online' ||

' parameters ( ''optimize full maxtime unlimited'' )'

end sync;

/

Set ServerOutput on

declare

v_job number;

begin

Dbms_Job.Submit

(

job => v_job,

what => 'sync;',

next_date => sysdate, /* default */

interval => 'sysdate + 1/720' /* = 1 day / ( 24 hrs * 30 min) = 2 mins */

);

Dbms_Job.Run ( v_job );

Dbms_Output.Put_Line ( 'Submitted as job # ' || to_char ( v_job ) );

end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值