设为首页 加入收藏

TOP

Oracle全文检索方面的研究(全10)(一)
2014-11-24 08:09:26 来源: 作者: 【 】 浏览:7
Tags:Oracle 全文检索 面的 研究

4、操作实例

4.1 单列与多列支持中文检索

Create table mytable1(id number primary key, doc1 varchar2(400),doc2 clob,doc3 clob);

Insert into mytable1 values(1,今天的天气很不错,我想去逛街,今天是星期天,不用上班。天天好心情,明天是星期一,要上班。心情不好);

Insert into mytable1 values(2,天是蓝色的,万里无云。天气非常好。,天是多云的,天气看起来要下雨了。不适宜出门,天正在下雨,大雨倾盆。不能出门。);

Insert into mytable1 values(3,this is a text,this is a word,this is a pdf);

Commit;

--先删除引用

begin

ctx_ddl.drop_preference(my_chinese_vgram_lexer);

ctx_ddl.drop_preference(my_chinese_lexer);

end;

--支持中文分词

Begin

ctx_ddl.create_preference(my_chinese_vgram_lexer, chinese_vgram_lexer);

ctx_ddl.create_preference(my_chinese_lexer, chinese_lexer);

End;

--先删除引用

begin

ctx_ddl.drop_preference(my_multi);

end;

--多列查询,如果仅仅是单列,则不用设置这个类型

Begin

Ctx_ddl.create_preference(my_multi, multi_column_datastore);

Ctx_ddl.set_attribute(my_multi, columns, doc1, doc2, doc3);

End;

drop index myindex;

--单列查询,支持中文的索引建立

Create index myindex on mytable(docs)

indextype is ctxsys.context

parameters (datastore ctxsys.default_datastore lexer foo.my_chinese_lexer)

drop index idx_mytable;

--多列查询,支持中文的索引的建立

Create index idx_mytable on mytable1(doc1)indextype is ctxsys.context

parameters(datastore my_multi lexer foo.my_chinese_lexer);

--chinese_lexer词法分析器下的结果,三列都可以查询

Select * from mytable1 where contains(doc1, 今天)>0; --检索到第一条数据

Select * from mytable1 where contains(doc1, 不适宜)>0; --检索到第二条数据

Select * from mytable1 where contains(doc1, 适宜)>0; --检索不到数据,他的分词技术太简单,将‘不适宜’作为一个词了

Select * from mytable1 where contains(doc1, 出门)>0; --检索到第二条数据

Select * from mytable1 where contains(doc1, this is a word)>0; --检索到第三条数据,中英文适用

--chinese_vgram_lexer词法分析器下的结果,

--chinese_vgram_lexer词法分析器虽然没那么智能,但检索结果往往比较符合我们的要求,

--如:“不适宜”这个词语应该拆分为“不适宜”和“适宜”两个词语,而不是单独的作为一个词语,

--chinese_vgram_lexer可以查询的到,而chinese_lexer不可以。

drop index idx_mytable;

--多列查询,支持中文的索引的建立

Create index idx_mytable on mytable1(doc1)indextype is ctxsys.context

parameters(datastore my_multi lexer foo.my_chinese_vgram_lexer);

--chinese_vgram_lexer词法分析器下的结果,三列都可以查询

Select * from mytable1 where contains(doc1, 今天)>0; --检索到第一条数据

Select * from mytable1 where contains(doc1, 不适宜)>0; --检索到第二条数据

Select * from mytable1 where contains(doc1, 适宜)>0; --检索到第二条数据,这个分词虽然效率低点,但检索结果还可以

Select * from mytable1 where contains(doc1, 出门)>0; --检索到第二条数据

Select * from mytable1 where contains(doc1, this is a word)>0; --检索到第三条数据,中英文适用

--对于多列查询,更新列操作

--只更新从表,看是否能查到更新的信息

Update mytable1 set doc2=adladlhadad this datastore when your text is stored test where id=2;

--同步更新索引

Begin

Ctx_ddl.sync_index(idx_mytable);

End;

--可见,虽然你检索是三个列,但是你更新的不是索引对应的那列(doc1),同步了索引也是不起作用的

Select * from mytable1 where contains(doc1,adladlhadad)>0; --没有记录

--更新与doc1列原来相同内容(实际内容不变,只有操作而已)

Update mytable1 set doc1=天是蓝色的,万里无云。天气非常好。 where id=2;

--再同步更新索引

Begin

Ctx_ddl.sync_index(idx_mytable);

End;

--再查询一次

Select * from mytable1 where contains(doc1,adladlhadad)>0; --有结果,可见,对于其他查询的列(非索引对应的列)的更新操作,可以连同索引对应的列一起更新,只是不改变索引的内容即可做到同步索引就可以出现效果了。

4.2 本地磁盘检索

create table mytable3(id number primary key, docs varchar2(2000));

insert into mytable3 values(111555,1.txt);

insert into mytable3 values(111556,1.doc);

insert into mytable3 values(111557,1.xls);

insert into mytable3 values(111558,1.pdf);

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Oracle下SQL基本操作(二) 下一篇Oracle存储过程返回游标,查询语..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·SOLVED: Ubuntu 24.0 (2025-12-26 22:51:53)
·Linux 常用命令最全 (2025-12-26 22:51:50)
·新人如何从零开始学 (2025-12-26 22:51:47)
·我的Linux内核学习笔 (2025-12-26 22:21:10)
·如何评价腾讯开源的 (2025-12-26 22:21:07)