Oracle8i Application Developer's Guide - XML Release 3 (8.1.7) Part Number A86030-01 |
|
Using interMedia Text to Search and Retrieve Data from XML Documents, 11 of 22
The following example illustrates how to create an interMedia Text index. The example is presented in tutorial fashion. Creating an interMedia Text index involves the following steps:
Determine the role you need. See "Listing the Required Roles for Each CTX Package" and grant the appropriate privilege.
CONNECT system/manager GRANT ctxapp to scott; CONNECT scott/tiger
-- Set up some data CREATE TABLE my_table (id number(5) primary key, my_column clob ); INSERT INTO my_table VALUES ( 1, '<author>Fred Smith</author>' || '<document>I had a nice weekend in the mountains.</document>' ); INSERT INTO my_table VALUES ( 2, '<author>Jack Jones</author>' || '<document>My month at the coast was relaxing.</document>' ); INSERT INTO my_table VALUES ( 3, '<publisher>Dog House</publisher>' || '<document>His year in Provence was fulfilling.</document>' || '<junk>banana</junk>' ); COMMIT;
SELECT my_column FROM my_table WHERE CONTAINS ( my_column, 'smith WITHIN author' ) > 0;
The following error message is obtained:
DRG-10599: column is not indexed
This example shows that a default parameterized interMedia Text index does not support XML functionality:
CREATE INDEX my_index ON my_table ( my_column ) INDEXTYPE IS Ctxsys.Context /* implies defaults */; SELECT my_column FROM my_table WHERE CONTAINS ( my_column, 'smith WITHIN author' ) > 0;
The following error message is obtained:
DRG-10837: section author does not exist
See "5 Parameterizing the Preference".
Consider a preference, "my_section_group". It must be created before we can refer to it! This example shows that you need to express parameterization with a preference:
DROP INDEX my_index; CREATE INDEX my_index ON my_table ( my_column ) INDEXTYPE IS Ctxsys.Context PARAMETERS ( 'SECTION GROUP my_section_group' );
The following error message is obtained:
DRG-12203: section group my_section_group does not exist
You need to do more than just CREATE 'my_section_group', you need to parameterize it too. Use CTX_DDL.Create_Section_Group
This example shows the need to parameterize the my_section_group preference:
DROP INDEX my_index; BEGIN Ctx_Ddl.Create_Section_Group ( group_name => 'my_section_group', group_type => 'xml_section_group' ); end; / CREATE INDEX my_index ON my_table ( my_column ) INDEXTYPE IS Ctxsys.Context PARAMETERS ( 'SECTION GROUP my_section_group' ); SELECT my_column FROM my_table WHERE CONTAINS (my_column, 'smith WITHIN author' ) > 0;
The following error message is obtained:
DRG-10837: section author does not exist
This example shows that after creating the interMedia Text index and the preference, my_section_group, you need to parameterize the preference correctly.
Using Table CTX_OBJECTS and CTX_OBJECT_ATTRIBUTES View for a brief description of the CTX_DDL package, and Oracle8i interMedia Text Reference for detailed notes on CTX_DDL.:
See Also:
DROP INDEX my_index; BEGIN Ctx_Ddl.Drop_Section_Group ( group_name => 'my_section_group' ); END; / BEGIN Ctx_Ddl.Create_Section_Group /* We're dealing here with XML, not say HTML */ ( group_name => 'my_section_group', group_type => 'xml_section_group' ); Ctx_Ddl.Add_Field_Section /* THIS IS KEY */ ( group_name =>'my_section_group', section_name =>'author',/* do this for EVERY tag used after "WITHIN" */ tag =>'author' ); Ctx_Ddl.Add_Field_Section /* THIS IS KEY */ ( group_name =>'my_section_group', section_name =>'document',/*do this for EVERY tag after "WITHIN" */ tag =>'document' ); ... END; / CREATE INDEX my_index ON my_table ( my_column ) INDEXTYPE IS Ctxsys.Context PARAMETERS ( 'SECTION GROUP my_section_group' ); SELECT my_column FROM my_table WHERE CONTAINS ( my_column, 'smith WITHIN author' ) > 0;
The last example is correct.
The following command creates a section group called autogroup with the AUTO_SECTION_GROUP group type. This section group automatically creates sections from tags in XML documents.
BEGIN ctx_ddl.create_section_group('autogroup', 'AUTO_SECTION_GROUP'); END;
To index your documents you can use the following statement:
CREATE INDEX myindex ON docs(htmlfile) INDEXTYPE IS ctxsys.context parameters('filter ctxsys.null_filter section group autogroup');
The following command creates a section group called xmlgroup with the XML_SECTION_GROUP group type.
BEGINE ctx_ddl.create_section_group('xmlgroup', 'XML_SECTION_GROUP'); END;
You can add sections to this group using CTX_DDL.ADD_SECTION
.
To index your documents, you can use the following statement:
CREATE INDEX myindex ON docs(htmlfile) INDEXTYPE IS ctxsys.context parameters('filter ctxsys.null_filter section group xmlgroup');
Further examples for creating section group indexes are at the following site:
Then select the following:
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|