手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle 11g Release 1 (11.1) Oracle 文本自定义 CONTEXT 索引的“偏好”

[日期:2012-06-24] 来源:Linux社区  作者:liuning8023 [字体:大 中 小]
NULL_FILTER 示例: 索引 HTML 文档

如果你的文档集合完全是 HTML,那么,Oracle 建议在你的过滤偏好中使用 NULL_FILTER。

例如,若索引 HTML 文档集合,你可以指定 NULL_FILTER 和 HTML_SECTION_GROUP 如下所示:

create index myindex on docs(htmlfile) indextype is ctxsys.context 
  parameters('filter ctxsys.null_filter
  section group ctxsys.html_section_group');
PROCEDURE_FILTER 示例

过滤存储过程 CTXSYS.NORMALIZE 的签名如下:

PROCEDURE NORMALIZE(id IN ROWID, charset IN VARCHAR2, input IN CLOB,
output IN OUT NOCOPY VARCHAR2);
 

你若使用这个存储过程过滤,建立过滤偏好如下:

begin
ctx_ddl.create_preference('myfilt', 'procedure_filter');
ctx_ddl.set_attribute('myfilt', 'procedure', 'normalize');
ctx_ddl.set_attribute('myfilt', 'input_type', 'clob');
ctx_ddl.set_attribute('myfilt', 'output_type', 'varchar2');
ctx_ddl.set_attribute('myfilt', 'rowid_parameter', 'TRUE');
ctx_ddl.set_attribute('myfilt', 'charset_parameter', 'TRUE');
end;
BASIC_LEXER 示例: 设置 Printjoin 字符

printjoin 字符是非字母数字字符,它们不能包含在索引中,因此,像网址这样的词可以作为网址来索引。

下面示例设置 printjoin 字符为“连字符”和“下划线”BASIC_LEXER:

begin
ctx_ddl.create_preference('mylex', 'BASIC_LEXER');
ctx_ddl.set_attribute('mylex', 'printjoins', '_-');
end;

若利用前面设置的 printjoins 字符创建索引,如下所示:

create index myindex on mytable ( docs ) 
  indextype is ctxsys.context 
  parameters ( 'LEXER mylex' );
MULTI_LEXER 示例: 索引一个多语言表

你可以使用 MULTI_LEXER 偏好来索引一个包含不同语言的文档。例如,当你的文本列存储英语、德语和日语文档时,可以使用该偏好。

首先,创建一个有三列的多语言表,包括主键、语言和文本,如下所示:

create table globaldoc (
   doc_id number primary key,
   lang varchar2(3),
   text clob
);

假设,该表大部分是英文文档,和一些德语、日语文档。若处理这三种语言,你必须为三种语言分别创建分词(子分词):

ctx_ddl.create_preference('english_lexer','basic_lexer');
ctx_ddl.set_attribute('english_lexer','index_themes','yes');
ctx_ddl.set_attribute('english_lexer','theme_language','english');
 
ctx_ddl.create_preference('german_lexer','basic_lexer');
ctx_ddl.set_attribute('german_lexer','composite','german');
ctx_ddl.set_attribute('german_lexer','mixed_case','yes');
ctx_ddl.set_attribute('german_lexer','alternate_spelling','german');
 
ctx_ddl.create_preference('japanese_lexer','japanese_vgram_lexer');

创建多分词偏好:

ctx_ddl.create_preference('global_lexer', 'multi_lexer');

因为,存储的文档大部分是英文,使用 CTX_DDL.ADD_SUB_LEXER 让英文分词为默认:

ctx_ddl.add_sub_lexer('global_lexer','default','english_lexer');

现在,用 CTX_DDL.ADD_SUB_LEXER 分别在德语和日语中添加它们的分词。另外,假设语言列用标准的 ISO 639-2 语言编码。

ctx_ddl.add_sub_lexer('global_lexer','german','german_lexer','ger');
ctx_ddl.add_sub_lexer('global_lexer','japanese','japanese_lexer','jpn');

现在,创建名为 "globalx" 的索引,在参数中指定多分词��好和语言列,如下所示:

create index globalx on globaldoc(text) indextype is ctxsys.context
parameters ('lexer global_lexer language column lang');
BASIC_WORDLIST 示例: 启用子字符串和前缀索引

本例设置前缀和子字符串的词表偏好,以提高通配符查询的性能。

若建立前最索引,本例指定,Oracle 文本创建3到4个字符长度的前缀标记。如下所示:

begin 
ctx_ddl.create_preference('mywordlist', 'BASIC_WORDLIST'); 
ctx_ddl.set_attribute('mywordlist','PREFIX_INDEX','TRUE');
ctx_ddl.set_attribute('mywordlist','PREFIX_MIN_LENGTH', '3');
ctx_ddl.set_attribute('mywordlist','PREFIX_MAX_LENGTH', '4');
ctx_ddl.set_attribute('mywordlist','SUBSTRING_INDEX', 'YES');
end;
linux
相关资讯       Oracle存储过程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款