Oracle8i Application Developer's Guide - XML
Release 3 (8.1.7)

Part Number A86030-01

Library

Solution Area

Contents

Index

Go to previous page Go to beginning of chapter Go to next page

Using interMedia Text to Search and Retrieve Data from XML Documents, 11 of 22


Creating an interMedia Text Index

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:

1 Determine the Role you Need and GRANT ctxapp Privilege

2 Set up Data, if Not Already Available

3 Creating an interMedia Text Index in Order to use CONTAINS

3.1 You Need an interMedia Text Index in Order to Use CONTAINS

3.2 Creating a Default Parameterized interMedia Text Index

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".

4 Creating a Preference: You Need to Express the Parameterization with a "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

5 Parameterizing the Preference

You need to do more than just CREATE 'my_section_group', you need to parameterize it too. Use CTX_DDL.Create_Section_Group

5.1 Parametrizing the Preference, my_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

5.2 Parameterize the Preference, 'my_section_group', Correctly Using CTX_DDL.Create_Section_Group and CTX_DDL.Add_Field_Section

This example shows that after creating the interMedia Text index and the preference, my_section_group, you need to parameterize the preference correctly.

interMedia Text Example 1: Creating an Index -- Creating a Preference and Correctly Parameterizing it

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.

interMedia Text Example 2: Creating a Section Group with AUTO_SECTION_GROUP

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


Note:

You can add attribute sections only to XML section groups. When you use AUTO_SECTION_GROUP, attribute sections are created automatically. Attribute sections created automatically are named in the form tag@attribute.  


interMedia Text Example 3: Creating a Section Group with XML_SECTION_GROUP

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?

Further examples for creating section group indexes are at the following site:

http://technet.oracle.com/products/intermedia

Then select the following:


Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 1996-2000, Oracle Corporation.

All Rights Reserved.

Library

Solution Area

Contents

Index