3.4 Section Group 属性
Section group 支持查询包含内部结构的文档(如html、xml 文档等),可以指定对文档
的某一部分进行查询,你可以将查询范围限定在标题head 中。在html、xml 等类似结构的文
档中,除了用来显示的内容外,还包括了大量用于控制结构的标识,而这些标识可能是不希望被索引的,这就是section group 的一个主要功能(原文:In order to issue WITHIN queries on document sections, you must create a section group before you define your sections)
3.4.1 Null_section_group
系统默认,不进行任何节的过滤
例子:
Create table my_sec (id number, docs varchar2(100));
Insert into my_sec values (1, 'a simple section group, test null_section_group attribute.');
Insert into my_sec values (2, 'this record one, can be query in nornal');
Insert into my_sec values (4, 'this record
are tested for
the query in paragraph');
Commit;
/
--定义null_section_group
Create index ind_m_sec on my_sec(docs) indextype is ctxsys.context
parameters ('section group ctxsys.null_section_group');
Select * from my_sec where contains(docs, 'record and query') > 0;
--要预先定义sentence 或paragraph',否则查询会出错
Select * from my_sec where contains(docs, '(record and query) within sentence') > 0;
Begin
ctx_ddl.create_section_group('test_null', 'null_section_group');
ctx_ddl.add_special_section('test_null', 'sentence');
ctx_ddl.add_special_section('test_null', 'paragraph');
End;
drop index ind_m_sec;
Create index ind_m_sec on my_sec(docs) indextype is ctxsys.context
parameters ('section group test_null');
Select * from my_sec where contains(docs, '(record and query) within sentence') > 0;
Select * from my_sec where contains(docs, '(record and query) within paragraph') > 0;
3.4.2 Basic_section_group
basic_section_group 才是支持节搜索的最基础的一种属性,但是它只支持以<tag>开头以
</tag>结尾的结构的文档
Create table my_sec1 (id number, docs varchar2(1000));
Insert into my_sec1 values (1, '<heading>title</heading>
<context>this is the contents of the example.
Use this example to test the basic_section_group.</context>');
Insert into my_sec1 values (2, '<heading>example</heading>
<context>this line incluing the word title too.</context>');
Commit;
/
Create index ind_my_sec1 on my_sec1(docs) indextype is ctxsys.context;
Select * from my_sec1 where contains (docs, 'heading') > 0;
--定义basic_section_group
Begin
Ctx_ddl.create_section_group('test_basic', 'basic_section_group');
End;
drop index ind_my_sec1;
Create index ind_my_sec1 on my_sec1(docs) indextype is ctxsys.context
parameters ('section group test_basic');
Select * from my_sec1 where contains (docs, 'heading') > 0;
Select * from my_sec1 where contains (docs, 'context') > 0;
Select * from my_sec1 where contains (docs, 'use') > 0;
节搜索的另一个主要功能就是可以限制查询的范围,上面的文档包含了两部分,标题和正文,
其中标题使用标签<heading>,正文使用标签<context>,我们可以对basic_section_group 添加
区域属性,运行查询在文档的某个范围内进行
Drop index ind_my_sec1;
Begin
ctx_ddl.add_zone_section('test_basic', 'head', 'heading');
End;
Create index ind_my_sec1 on my_sec1(docs) indextype is ctxsys.context
parameters ('section group test_basic');
Select * from my_sec1 where contains (docs, 'title') > 0;
--在head 里面查询
Select * from my_sec1 where contains (docs, 'title within head') > 0;
3.4.3 Html_section_group
Html 文档具有很多不规范的表示方法,oracle 建议使用html_section_group 以便能够得到更
好的识别
--定义html_section_group
begin
ctx_ddl.create_section_group('htmgroup', 'HTML_SECTION_GROUP');
end;
create index myindex on docs(htmlfile) indextype is ctxsys.context
parameters('filter ctxsys.null_filter section group htmgroup');
无论是field_section 还是zone_section,表示文档的tag 标签都是大小写敏感的,其大小写需
要和原文中匹配
3.4.4.Xml_section_group
Xml 文档的格式要求比html 文档严谨、规范, 这也使得xml_section_group 比
html_section_group 具有了更多的功能
例子:
Create table my_sec2 (id number, docs varchar2(1000));
Insert into my_sec2 values (1, 'context.xml');
commit;
/
--定义xml_section_group
Begin
ctx_ddl.create_preference('test_file', 'file_datastore');
ctx_ddl.set_attribute('test_file', 'path', '/opt/tmp');
ctx_ddl.create_section_group('test_html', 'html_section_group');
ctx_ddl.create_section_group('test_xml', 'xml_section_group');
End;
Create index ind_t_docs on my_sec2 (docs) indextype is ctxsys.context
parameters('datastore ctxsys.test_file filter ctxsys.null_filter section group
ctxsys.test_xml')
Begin
ctx_ddl.add_attr_section('test_xml', 'name', 'const@name');
End;
Select * from my_sec2 where contains (docs, 'complete within name') > 0;
3.4.5.Auto_section_group
Xml_section_group 的增强型,对于xml_section_group 用户需要自己添加需要定义的节组,
而使用auto_section_group,则oracle 会自动添加节组以及属性信息
3.4.6 Path_section_group
和auto_section_group 十分类似,path_section_group 比auto_section_group 增加了haspath 和
inpath 操作,但是path_section_group 不支持add_stop_section 属性
3.4.7 参考脚本
--建立null_section_group
Create index ind_m_sec on my_sec(docs) indextype is ctxsys.context
parameters ('section group ctxsys.null_section_group');
--建立basic_section_group
Begin
Ctx_ddl.create_section_group('test_basic', 'basic_section_group');
End;
Begin
ctx_ddl.add_zone_section('test_basic', 'head', 'heading'); --设定节查询
End;
Create index ind_my_sec1 on my_sec1(docs) indextype is ctxsys.context
parameters ('section group test_basic');
--建立Html_section_group
begin
ctx_ddl.create_section_group('htmgroup', 'HTML_SECTION_GROUP');
end;
create index myindex on docs(htmlfile) indextype is ctxsys.context
parameters('filter ctxsys.null_filter section group htmgroup');
--建立Xml_section_group
Begin
ctx_ddl.create_section_group('test_xml', 'xml_section_group');
End;
Create index ind_t_docs on my_sec2 (docs) indextype is ctxsys.context
parameters('filter ctxsys.null_filter section group ctxsys.test_xml')