设为首页 加入收藏

TOP

Oracle全文检索方面的研究(全1)(一)
2014-11-24 08:12:01 来源: 作者: 【 】 浏览:3
Tags:Oracle 全文检索 面的 研究

1、准备流程

1.1检查和设置数据库角色

首先检查数据库中是否有CTXSYS用户和CTXAPP脚色。如果没有这个用户和角色,意味着你的数据库创建时未安装intermedia功能。你必须修改数据库以安装这项功能。 默认安装情况下,ctxsys用户是被锁定的,因此要先启用ctxsys的用户。

默认ctxsys用户是被锁定的且密码即时失效,所以我们以sys用户进入em,然后修改ctxsys用户的状态和密码。如图:

1.2 赋权 

测试用户以之前已经建好的foo用户为例,以该用户下的T_DOCNEWS为例

先以sys用户dba身份登录,对foo赋resource,connect权限

GRANT resource, connect to foo;

再以ctxsys用户登录并对foo用户赋权

GRANT ctxapp TO foo;

GRANT execute ON ctxsys. ctx_cls TO foo;

GRANT execute ON ctxsys. ctx_ddl TO foo;

GRANT execute ON ctxsys. ctx_doc TO foo;

GRANT execute ON ctxsys. ctx_output TO foo;

GRANT execute ON ctxsys. ctx_query TO foo;

GRANT execute ON ctxsys. ctx_report TO foo;

GRANT execute ON ctxsys. ctx_thes TO foo;

GRANT execute ON ctxsys. ctx_ulexer TO foo;

查看系统默认的oracle text 参数

Select pre_name, pre_object from ctx_preferences

2、Oracle Text 索引原理

Oracle text 索引将文本中所有的字符转化成记号(token),如www.taobao.com 会转化

成www,taobao,com 这样的记号。

Oracle10g 里面支持四种类型的索引,context,ctxcat,ctxrule,ctxxpath

2.1 Context 索引

Oracle text 索引把全部的word 转化成记号,context 索引的架构是反向索引(inverted

index),每个记号都映射着包含它自己的文本位置,如单词dog 可能会有如下的条目

这表示dog 在文档doc1,doc3,doc5 中都出现过。索引建好之后,系统中会自动产生

如下DR$MYINDEX$I,DR$MYINDEX$K,DR$MYINDEX$R,DR$MYINDEX$X,MYTABLE5 个表(假设表为

mytable, 索引为myindx) 。Dml 操作后, context 索引不会自动同步, 需要利用

ctx_ddl.sync_index 手工同步索引。

例子:

Create table docs (id number primary key, text varchar2(200));

Insert into docs values(1, <html>california is a state in the us.);

Insert into docs values(2, paris is a city in france.);

Insert into docs values(3, france is in europe.);

Commit;

/

--建立context 索引

Create index idx_docs on docs(text)

indextype is ctxsys.context parameters

(filter ctxsys.null_filter section group ctxsys.html_section_group);

--查询

Column text format a40; --字符串截为40位显示。

Select id, text from docs where contains(text, france) > 0;

id text

---------- -------------------------------

3 france is in europe.

2 paris is a city in france.

--继续插入数据

Insert into docs values(4, los angeles is a city in california.);

Insert into docs values(5, mexico city is big.);

commit;

Select id, text from docs where contains(text, city) > 0;--新插入的数据没有查询到

id text

--------------------------------------------

2 paris is a city in france.

--索引同步

begin

ctx_ddl.sync_index(idx_docs, 2m); --使用2M同步索引

end;

--查询

Column text format a50;

Select id, text from docs where contains(text, city) > 0; --查到数据

id text

-----------------------------------------------

5 mexico city is big.

4 los angeles is a city in california.

2 paris is a city in france.

-- or 操作符

Select id, text from docs where contains(text, city or state ) > 0;

--and 操作符

Select id, text from docs where contains(text, city and state ) > 0;

或是

Select id, text from docs where contains(text, city state ) > 0;

--score 表示得分,分值越高,表示查到的数据越精确

SELECT SCORE(1), id, text FROM docs WHERE CONTAINS(text, oracle, 1) > 0;

Context 类型的索引不会自动同步,这需要在进行Dml 后,需要手工同步索引。与context 索引相对于的查询操作符为contains

2.2 Ctxcat 索引

用在多列混合查询中

Ctxcat 可以利用index set 建立一个索引集,把一些经常与ctxcat 查询组合使用的查询列添加到索引集中。比如你在查询一个商品名时,还需要查询生产日期,价格,描述等,你可可以将这些列添加到索引集中。oracle 将这些查询封装到catsearch 操作中,从而提高全文索引的效率。在一些实时性要求较高的交易上,context 的索引不能自动同步显然是个问题,ctxcat则会自动同步索引

例子:

Create table auction(Item_id number,Title varchar2(100),Category_id number,Price number,Bid_close date);

Insert into auction values(1, nikon camer

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Oracle全文检索方面的研究(全3) 下一篇Oracle全文检索方面的研究(全4)

评论

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

·MySQL 基础入门视频 (2025-12-26 23:20:22)
·小白入门:MySQL超详 (2025-12-26 23:20:19)
·关于 MySQL 数据库学 (2025-12-26 23:20:16)
·SOLVED: Ubuntu 24.0 (2025-12-26 22:51:53)
·Linux 常用命令最全 (2025-12-26 22:51:50)