oracle的博客
===========================================================
Oracle全文索引设置步骤
===========================================================

已有几个项目组开始使用oracle的全文索引。Oracle的词法分析器针对ZHS16GBK字符集的词法分析尚不够智能,只能机械地以字为单元进行匹配。对于utf8字符集的数据库有一个新的汉语分析器chinese_lexer,效率有了很大改善。现将验证并整理过的如何进行oracle全文索引设置的文档发给大家,适用于8i、9i各平台版本。

对于DB2,有一个叫做TIE(Text Information Extend)的插件可以实现全文索引,不过据说它的语法分析也很原始。据介绍使用CM(Content Manager)能做到比较好的全文检索,不过需要装一大堆的软件,不适于简单的应用。

一.创建数据库

1、使用dbassist创建数据库时要选择jserverintermedia两个选项。

2、检查你的数据库是否安装了intermedia,可以通过检查是否有ctxsys用户和ctxapp角色(role).

3、如果没有这个用户和角色,意味着数据库创建时未安装intermedia功能。必须修改数据库以安装这项功能。修改过程:

运行 $ORACLE_HOME/bin/dbassist, 选择'modify database', 然后在选择数据库功能时将jserver 和 intermedia 都选上(安装intermedia必须同时安装jserver).

二.设置extproc

Oracle 通过 外部调用功能(external procedure)来实现intermedia的,因此正确地设置extproc是关键一步。 一般数据库安装完jserverintermedia后在listener.ora 和tnsnames.ora中已经设置了extproc。

1、测试extproc是否正常

重新启动listener,然后,使用tnsping 来测试一下是否配置正确,

命令行下运行

tnsping extproc_connection_data 或者

tnsping extproc_connection_data.world

如果配置正确,会显示:

Attempting to contact (ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC)) OK(140毫秒)

如果正确,可以跳过2、3步骤。否则请按照步骤2、3设置listener.ora 和tnsnames.ora文件,修改后一定要重新启动listener,但并不需要重新启动数据库。

2、设置listerner.ora

如果tnsping失败,需要配置listener 使它能监听intermedia 调用的请求。可以通过运行$ORACLE_HOME/bin/netassit 来进行配置,也可以手工修改配置文件:$ORACLE_HOME/network/admin/listener.ora ,然后重新启动listener。

下面以一个例子来讲述如何手工修改配置文件:

打开listener.ora文件,在修改前,通常有如下内容(假定使用缺省listener):

LISTENER =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = MYDATABASE)(PORT = 1521))

)

SID_LIST_LISTENER =

(SID_DESC =

(GLOBAL_DBNAME = mydatabase.world)

(ORACLE_HOME = /u01/app/oracle/product/8.1.6)

(SID_NAME = mydatabase)

)

这个listener还没有配置extproc, 因此,需要为它增加对extproc的监听,办法就是分别增加description 和 sid_desc. 修改后的listner.ora 如下:

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = MYDATABASE)(PORT = 1521))

)

(DESCRIPTION =

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))

)

)

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(GLOBAL_DBNAME = mydatabase.world)

(ORACLE_HOME = /u01/app/oracle/product/8.1.6)

(SID_NAME = mydatabase)

)

(SID_DESC =

(PROGRAM = extproc)

(SID_NAME = PLSExtProc)

(ORACLE_HOME = /u01/app/oracle/product/8.1.6)

)

)

注意上面的host, global_dbname,sid_name,oracle_home应填写你的数据库的实际值,但program一项必须填写extproc.

3、设置tnsnames.ora

其次,要配置服务器端的tnsnames.ora文件。该文件的位置在$ORACLE_HOME/network/admin下面。同样可以通过运行netasst来进行配置。

tnsnames.ora文件中需要增加如下一项:

EXTPROC_CONNECTION_DATA,EXTPROC_CONNECTION_DATA.WORLD =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))

)

(CONNECT_DATA =

(SID = PLSExtProc)

)

)

注意其中,KEY 和SID必须与listener.ora中的key 和sid_name对应相同。

三.设置词法分析器(lexer)

Oracle 缺省使用basic_lexer这个分析器。basic_lexer针对英语。要指定使用中文分析器, 操作步骤:

1. ctxsys用户登陆intermedia text manager,口令ctxsys:

2.选择首选项——〉语言指示器——〉创建,输入指示器的名字如chinese_lexer,选择lexer下的chinese_vgrnm_lexer

3.建立intermedia索引,指定索引名,选择方案和表下的字段,例如system方案下的DOM_1_DOCLIB中的CURRENTTEXT字段,首选项中选择chinese_lexer

这样建立的全文检索索引,就会使用chinese_vgram_lexer作为分析器。

4.在索引建好后,在该用户下查到Oracle自动产生了以下几个表,可以使用dba studio查看:(假设索引名为myindex):

DR$myindex$I,DR$myindex$K,DR$myindex$R,DR$myindex$N

其中以I表最重要,查询该表:

select token_text, token_count from DR$I_RSK1$I where rownum<=20;

可以看到该表中保存的是Oracle分析你的文档后,生成的term记录,包括term出现的位置、次数、hash值等。

四.使用job定时同步和优化

intermedia索引建好后,如果表中的数据发生变化,增加或修改了记录,由于对表所发生的任何dml语句,都不会自动修改索引,因此,必须定时同步(sync)和优化(optimize)索引,以正确反映数据的变化。

同步(sync):将新的term 保存到I表;

优化(optimize):清除I表的垃圾,主要是将已经被删除的term从I表删除。

Oracle提供了一个ctx server来做这个同步和优化的工作,只需要在后台运行这个进程,它会监视数据的变化,及时进行同步。但存在许多问题。可以用下的两个job来完成(该job要建在和表同一个用户下):

-- sync:

VARIABLE jobno number;

BEGIN

DBMS_JOB.SUBMIT(:jobno,'ctx_ddl.sync_index(''myindex'');',

SYSDATE, 'SYSDATE + (1/24/4)');

commit;

END;

-- optimizer

VARIABLE jobno number;

BEGIN

DBMS_JOB.SUBMIT(:jobno,'ctx_ddl.optimize_index(''myindex'',''FULL'');',

SYSDATE, 'SYSDATE + 1');

commit;

END;

其中,第一个job的SYSDATE + (1/24/4)是指每隔15分钟同步一次,第二个job的SYSDATE + 1是每隔1天做一次全优化。具体的时间间隔,你可以根据自己的应用的需要而定。至此,你的全文检索功能已设置完成。


oracle 发表于:2006.10.30 19:40 ::分类: ( 一般分类 ) ::阅读:(142663次) :: 评论 (66)
Hello webmaster [回复]

Hello webmaster
I would like to share with you a link to your site
write me here preonrelt@mail.ru

Alexwebmaster 评论于: 2009.03.04 05:23
Carey [回复]










Grady 评论于: 2009.03.05 23:04
Jarrett [回复]










Timmy 评论于: 2009.03.06 00:36
Christian [回复]










Jude 评论于: 2009.03.06 04:04
Dandre [回复]










Raul 评论于: 2009.03.06 05:35
Jarret [回复]










Bradford 评论于: 2009.03.06 06:36
Jarret [回复]










Bradford 评论于: 2009.03.06 06:36
Johan [回复]










Camden 评论于: 2009.03.06 08:10
Julien [回复]










Jordan 评论于: 2009.03.06 09:34
Ali [回复]










Carlos 评论于: 2009.03.06 11:05
Maximilian [回复]










Sean 评论于: 2009.03.06 14:34
Keyshawn [回复]










Neal 评论于: 2009.03.06 16:08
Manuel [回复]










Isidro 评论于: 2009.03.06 17:04
Camren [回复]










Ismael 评论于: 2009.03.06 18:36
Jacob [回复]










Jackie 评论于: 2009.03.06 19:34
Richard [回复]










Julien 评论于: 2009.03.06 21:09
Kelsey [回复]










Dandre 评论于: 2009.03.24 03:02
Justyn [回复]










Lewis 评论于: 2009.03.24 04:10
Josue [回复]










Sylvester 评论于: 2009.03.24 05:02
Joe [回复]










Louie 评论于: 2009.03.24 06:09
Ricky [回复]










Lance 评论于: 2009.03.24 07:03
Tristen [回复]










Jakob 评论于: 2009.03.24 08:12
Frank [回复]










Cecil 评论于: 2009.03.24 09:02
Aaron [回复]










Rodrick 评论于: 2009.03.24 10:12
Alec [回复]










Mychal 评论于: 2009.03.24 11:02
Gunnar [回复]










Stephon 评论于: 2009.03.24 12:17
Maximilian [回复]










Christopher 评论于: 2009.03.24 13:02
Irvin [回复]










Jessie 评论于: 2009.03.24 14:09
Cooper [回复]










Logan 评论于: 2009.03.24 15:02
Alessandro [回复]










Layne 评论于: 2009.03.24 16:16
Alexzander [回复]










Vincent 评论于: 2009.03.24 17:02
Nasir [回复]










Kale 评论于: 2009.03.24 18:08
Nikhil [回复]










Ronny 评论于: 2009.03.24 19:02
Devon [回复]










Tommie 评论于: 2009.03.24 20:12
Devon [回复]










Tommie 评论于: 2009.03.24 20:12
Devon [回复]










Tommie 评论于: 2009.03.24 20:12
Owen [回复]










Theodore 评论于: 2009.03.24 21:03
Luciano [回复]










Sam 评论于: 2009.03.24 22:07
Korey [回复]










Cael 评论于: 2009.03.24 23:03
Korey [回复]










Cael 评论于: 2009.03.24 23:04
Branden [回复]










Louis 评论于: 2009.03.25 00:13
Tanner [回复]










Malcolm 评论于: 2009.03.25 01:03
Julio [回复]










Keanu 评论于: 2009.03.25 02:13
re: Oracle全文索引设置步骤 [回复]










Randal 评论于: 2009.04.27 09:05
re: Oracle全文索引设置步骤 [回复]










Matthew 评论于: 2009.04.27 10:34
re: Oracle全文索引设置步骤 [回复]










Bill 评论于: 2009.04.27 12:03
re: Oracle全文索引设置步骤 [回复]










Nathan 评论于: 2009.04.27 13:20
re: Oracle全文索引设置步骤 [回复]










Aden 评论于: 2009.04.27 14:33
re: Oracle全文索引设置步骤 [回复]










Domingo 评论于: 2009.04.27 15:46
re: Oracle全文索引设置步骤 [回复]










Samson 评论于: 2009.04.27 17:04
re: Oracle全文索引设置步骤 [回复]










Cale 评论于: 2009.04.27 18:09
re: Oracle全文索引设置步骤 [回复]










Darren 评论于: 2009.04.27 19:04
re: Oracle全文索引设置步骤 [回复]










Tyrone 评论于: 2009.04.27 20:09
[回复]

溧 铈桠桦

Anagspeassy 评论于: 2009.09.13 03:40
Test, just a test [回复]

Hello. And Bye.

XRumerTest 评论于: 2009.09.28 16:46
[回复]

皴犟 珥嚓铎耱忄 痤爨 耱疱脲

uderweq 评论于: 2009.12.09 12:53
礤狃栩 觇耜 [回复]

皴犟 珥嚓铎耱忄 桤疣桦

uderweqh 评论于: 2009.12.09 15:07
镱痦 [回复]

Thank you very well read allss textt about drsating and ilike it very much

cEngerneGueddy 评论于: 2010.05.21 11:29
Bap [回复]

Thanks , I have recently been searching for information approximately this subject for a long time and yours is the greatest I have found out so far. But, what about the bottom line? Are you sure concerning the source?|What i don't realize is in reality how you're now not actually much more smartly-appreciated than you might be right now. You're very intelligent.

Bap 评论于: 2012.03.30 21:13
jocuri cu ferme [回复]

Thanks for every other informative website. Where else could I am getting that type of information written in such an ideal approach? I have a venture that I'm just now running on, and I have been on the look out for such information.

jocuri cu ferme 评论于: 2012.04.04 10:14
how to win the lottery [回复]

I just like the helpful info you supply on your articles. I'll bookmark your weblog and check once more here regularly. I'm moderately certain I'll be told many new stuff proper right here! Best of luck for the next!

how to win the lottery 评论于: 2012.04.05 07:24
online games [回复]

Excellent items from you, man. I have be mindful your stuff prior to and you're simply too magnificent. I really like what you've acquired right here, certainly like what you're saying and the best way during which you assert it. You're making it enjoyable and you still care for to keep it sensible. I can't wait to read far more from you. This is actually a terrific website.

online games 评论于: 2012.04.07 10:36
clenbuterol fat loss [回复]

I simply wanted to say thanks all over again. I'm not certain what I would've created in the absence of the type of creative ideas shared by you relating to such subject matter. It truly was a frightening condition in my opinion, however , being able to see the well-written fashion you dealt with the issue forced me to jump for gladness. I am just thankful for the assistance and in addition hope that you really know what a powerful job your are undertaking educating some other people via your site. I am sure you have never got to know all of us.

clenbuterol fat loss 评论于: 2012.04.07 16:41
computer repair frederick maryland [回复]

Terrific paintings! That is the type of info that are supposed to be shared around the net. Disgrace on Google for not positioning this submit upper! Come on over and talk over with my site . Thank you =)

computer repair frederick maryland 评论于: 2012.04.09 00:49
hcg dangers [回复]

It's my belief mesothelioma can be the most fatal cancer. It has unusual features. The more I actually look at it the more I am certain it does not respond like a true solid human cancer. In the event mesothelioma is often a rogue virus-like infection, hence there is the probability of developing a vaccine and also offering vaccination for asbestos uncovered people who are open to high risk of developing potential asbestos connected malignancies. Thanks for expressing your ideas about this important ailment.

hcg dangers 评论于: 2012.04.09 05:45
Dostawa i czesci do w髗k體 widlowych [回复]

części do wózków widłowych

Erokygory 评论于: 2012.04.17 14:05

发表评论
标题

在此添加评论
表情符号: smile laughing tongue angry crying sad wassat wink

称呼

邮箱地址(可选)

个人主页(可选)




切换风格
新闻聚合
博客日历
文章归档...
最新发表...
博客统计...
网站链接...