本文简要说明全文检索功能的使用,不做太多的具体说明。
仅供参考使用方法。
1.授权
对具体使用全文检索的用户授权.
$ sqlplus "/ as sysdba"
SQL*Plus: Release 9.2.0.4.0 - Production on Sun May 15 20:00:10 2005
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
SQL> grant ctxapp to club;
Grant succeeded.
SQL> connect ctxsys/password
Connected.
SQL> grant execute on ctx_ddl to club;
Grant succeeded.
2.使用应用用户连接
创建域索引
SQL> connect club/password
Connected.
SQL> begin ctx_ddl.create_preference('club_lexer','chinese_vgram_lexer'); end;
2 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.03
SQL> create index id_cont_msg
2 on jivemessage ( SUBJECT ) indextype is ctxsys.context parameters
('lexer club_lexer');
Index created.
Elapsed: 00:01:22.42
SQL> select count(*) from jivemessage where contains(subject,'幸福')>0;
COUNT(*)
----------
1847
Elapsed: 00:00:00.17
SQL> select count(*) from jivemessage where subject like '%幸福%';
COUNT(*)
----------
1841
Elapsed: 00:00:02.89
3.检索比较
以下是一个全文检索的示例,我们检索'abc',那么全文检索可以把包含'abc'的任何变化组合都查询出来,包括大小写、全半角,而如果用单纯的SQL实现同样的结果,则需要多次like之后union all,其性能差距是不可想象的。
全文检索在类似文本模糊查询上具有极大的优势。当然也可能存在问题,即词法分析器是否准确,会否漏掉部分内容等。
总的说来,满足需求的技术就是好的技术,是否使用一项技术应该通过实践来检验.
SQL> select subject from jivemessage where contains(subject,'abc') >0;
SUBJECT
--------------------------------------------------------------------------------
【游戏】 把你的名字的首字母用智能ABC打出,看能出来什么?
游戏――把你的名字首字母用智能ABC打出来
智能ABC暗藏杀机
ABC
ABC
ABC
ABC
ABC
ABC
哈哇abc
abc
SUBJECT
--------------------------------------------------------------------------------
abc
ABC
振奋爱的激情方案ABC
智能ABC的错吗?
ABC全选
瓜果美容ABC
经典英文歌曲ABC,不好你拿版砖砍我,好就回帖顶一下!
初夜abc
Re: abc
Re: abc
Re: abc
SUBJECT
--------------------------------------------------------------------------------
abc
测试发贴""abc
abc
25 rows selected.
Elapsed: 00:00:00.04
3.定时优化同步域索引
创建定时任务,定期优化和同步域索引
SQL> create or replace procedure hsp_sync_index as
2 begin
3 ctx_ddl.sync_index('id_cont_msg');
4 end;
5 /
Procedure created.
Elapsed: 00:00:00.08
SQL> VARIABLE jobno number;
SQL> BEGIN
2 DBMS_JOB.SUBMIT(:jobno,'hsp_sync_index();',
3 SYSDATE, 'SYSDATE + (1/24/4)');
4 commit;
5 END;
6 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.27
SQL> create or replace procedure hsp_optimize_index as
2 begin
3 ctx_ddl.optimize_index('id_cont_msg','FULL');
4 end;
5 /
SQL> VARIABLE jobno number;
SQL> BEGIN
2 DBMS_JOB.SUBMIT(:jobno,'hsp_optimize_index();',
3 SYSDATE, 'SYSDATE + 1');
4 commit;
5 END;
6 /
Procedure created.
Elapsed: 00:00:00.03
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.02
SQL>
-----