C.5 MULTI_LEXER例: マルチ言語表の索引付け

異なる言語のドキュメントを含む列を索引付けするには、MULTI_LEXERプリファレンス型を使用します。たとえば、テキスト列に英語、ドイツ語およびフランス語のドキュメントが格納されている場合は、このプリファレンス型を使用します。

最初のステップは、主キー、テキスト列および言語列を持つマルチ言語表を作成します:

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

表に格納されているドキュメントのほとんどが英語で、ドイツ語または日本語のドキュメントがいくつかあるとします。3つの言語を処理するには、英語、ドイツ語および日本語に対して1つずつの、3つのサブレクサーを作成する必要があります。

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');

PARAMETERS句にマルチレクサー・プリファレンスおよび言語列を指定して、globalx索引を作成します。

create index globalx on globaldoc(text) indextype is ctxsys.context
parameters ('lexer global_lexer language column lang');