日期:2014-05-16  浏览次数:20418 次

【引用】Oracle全文检索方面的研究(全2)

3.2 Filter 属性

过滤器负责将各种文件格式的数据转换为纯文本格式,索引管道中的其他组件只能处理纯文本数据,不能识别 microsoft word 或 excel 等文件格式,filter 有charset_filter、

inso_filter、null_filter、user_filter、procedure_filter 几种类型。(可将文档格式转化为数据库文本格式等。)

?

?

?

?

?

3.2.1 CHARSET_FILTER

把文档从非数据库字符转化成数据库字符(原文:Use the CHARSET_FILTER to convert

documents from a non-database character set to the character set used by the database)

?

例子:

create table hdocs ( id number primary key, fmt varchar2(10), cset varchar2(20),

text varchar2(80)

);

begin

cxt_ddl.create.preference('cs_filter', 'CHARSET_FILTER');

ctx_ddl.set_attribute('cs_filter', 'charset', 'UTF8');

end

insert into hdocs values(1, 'text', 'WE8ISO8859P1', '/docs/iso.txt');

insert into hdocs values (2, 'text', 'UTF8', '/docs/utf8.txt');

commit;

create index hdocsx on hdocs(text) indextype is ctxsys.context

parameters ('datastore ctxsys.file_datastore

filter cs_filter

format column fmt

charset column cset');

?

?

?

3.2.2 NULL_FILTER

默认属性,不进行任何过滤

oracle 不建议对html、xml 和plain text 使用auto_filter 参数,oracle 建议你使用

null_filter 和section group type

--建立null filter

create index myindex on docs(htmlfile) indextype is ctxsys.context

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

Filter 的默认值会受到索引字段类型和datastore 的类型的影响,对于存储在数据库中的

varchar2、char 和clob 字段中的数据,oracle 自动选择了null_filtel,若datastore 的属性设置为

file_datastore,oracle 会选择 auto_filter 作为默认值。

?

3.2.3 AUTO_FILTER

通用的过滤器,适用于大部分文档,包括PDF 和Ms word,过滤器还会自动识别出plain-text, HTML, XHTML,

SGML 和XML 文档

Create table my_filter (id number, docs varchar2(1000));

Insert into my_filter values (1, 'Expert Oracle Database Architecture.pdf');

Insert into my_filter values (2, '1.txt');

Insert into my_filter values (3, '2.doc');

commit;

/

--建立 file datastore

Begin

ctx_ddl.create_preference('test_filter', 'file_datastore');

ctx_ddl.set_attribute('test_filter', 'path', '/opt/tmp');

End;

--错误信息表

select * from CTX_USER_INDEX_ERRORS

--建立 auto filter

Create index idx_m_filter on my_filter (docs) indextype is ctxsys.context