insert into mytable3 values(111559,2.txt);
insert into mytable3 values(111560,2.doc);
insert into mytable3 values(111561,2.xls);
insert into mytable3 values(111562,2.pdf);
commit;
--先删除引用
begin
ctx_ddl.drop_preference(COMMON_DIR);
end;
--建立 file datastore
begin
ctx_ddl.create_preference(COMMON_DIR,FILE_DATASTORE);
ctx_ddl.set_attribute(COMMON_DIR,PATH,D:search);
end;
--先删除索引
drop index myindex3;
--建立索引,8个文件,内容简单,耗时1.5s
create index myindex3 on mytable3(docs) indextype is ctxsys.context parameters (datastore COMMON_DIR lexer foo.my_chinese_lexer);
select * from mytable3 where contains(docs,text)>0; --查询,支持txt
select * from mytable3 where contains(docs,pdf)>0; --查询,支持pdf
select * from mytable3 where contains(docs,excel)>0; --查询,支持excel
select * from mytable3 where contains(docs,word)>0; --查询,支持doc
select * from mytable3 where contains(docs,文本)>0; --查询,支持中文
select * from mytable3 where contains(docs,文档)>0; --查询,支持中文
select * from mytable3 where contains(docs,阅读)>0; --查询,支持中文pdf
select * from mytable3 where contains(docs,这是Excel)>0; --查询,支持中文
--暂时测试支持doc,txt,xls,pdf
--更新了文件内容2.txt
select * from mytable3 where contains(docs,这个测试用的文本)>0; --查询无更新好数据
--不同步索引,无效
--同步更新索引
Begin
Ctx_ddl.sync_index(myindex3);
End;
--再次查询
select * from mytable3 where contains(docs,测试)>0; --还是无效
--用相同的值取代2.txt然后再同步索引
Update mytable3 set docs=2.txt where id=111559;
--再同步索引
--同步更新索引
Begin
Ctx_ddl.sync_index(myindex3);
End;
--再次查询
select * from mytable3 where contains(docs,测试)>0; --结果出现,可见,单更新文件内容,同步索引是无效的,索引认的是数据库纪录,数据库纪录改变,索引才会更新
--新增加文件,结果雷同。关键是要更新数据库纪录,即使改了文件内容,也要用相同的值update数据库纪录一次。
4.3 检索结果高亮显示
Create table my_high (id number primary key, docs varchar2(1000));
insert into my_high values (1, this is a oracle text example. And oracle is the key word.);
insert into my_high values (2,
oracle textthis is a oracle ctx_doc hightlight example.);
commit;
/
--建立索引
create index ind_m_high on my_high(docs) indextype is ctxsys.context;
--返回结果的偏移量
set serverout on