Oracle8i Application Developer's Guide - XML Release 3 (8.1.7) Part Number A86030-01 |
Library | Service | Contents | Index

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

## Using the CTX_DDL PL/SQL Package

The CTX_DDL PL/SQL supplied package creates and manages the objects required for interMedia Text indexes. The detailed list of CTX_DDL package's stored procedures and functions can be found in Oracle8i interMedia Text Reference. Use the CTXAPP role when executing the CTX_DDL package.

The following CTX_DDL procedures are used in this chapter:

- create_preference

- create_section_group

- add_attr_section

- add_field_section

- add_special_section

- add_zone_section

### Listing the Required Roles for Each CTX Package

If you are uncertain which role to use with the CTX packages, run the following script. This lists the roles required for each CTX package:

    connect ctxsys/ctxsys
    column "Package"                        format a15
    column "Role needed to execute Package" format a30

    select dba_objects.object_name  "Package",
           dba_tab_privs.grantee    "Role needed to execute Package"
      from dba_objects, dba_tab_privs
      where dba_objects.object_name = dba_tab_privs.table_name (+)
        and dba_objects.object_type in ( 'PACKAGE', 'PROCEDURE', 'FUNCTION' )
        and dba_objects.object_name like 'CTX_%'
        order by "Role needed to execute Package";

This results in the following output:

    Package         Role needed to execute Package
    --------------- ------------------------------
    Ctx_Ddl         CTXAPP
    Ctx_Output      CTXAPP
    Ctx_Thes        CTXAPP
    Ctx_Contains    PUBLIC
    Ctx_Query       PUBLIC
    Ctx_Doc         PUBLIC
    Ctx_Adm

### CTX_DDL Procedures

The following lists the CTX_DDL procedures used in this chapter, along with each procedure's arguments and descriptions.

    procedure create_preference
     argument name                  type                    in/out default?
     ------------------------------ ----------------------- ------ --------
     preference_name                varchar2                in
     object_name                    varchar2                in

    procedure create_section_group
     argument name                  type                    in/out default?
     ------------------------------ ----------------------- ------ --------
     group_name                     varchar2                in
     group_type                     varchar2                in

    procedure add_attr_section
     argument name                  type                    in/out default?
     ------------------------------ ----------------------- ------ --------
     group_name                     varchar2                in
     section_name                   varchar2                in
     tag                            varchar2                in

    procedure add_field_section
     argument name                  type                    in/out default?
     ------------------------------ ----------------------- ------ --------
     group_name                     varchar2                in
     section_name                   varchar2                in
     tag                            varchar2                in
     visible                        boolean                 in     default

    procedure add_special_section
     argument name                  type                    in/out default?
     ------------------------------ ----------------------- ------ --------
     group_name                     varchar2                in
     section_name                   varchar2                in

    procedure add_zone_section
     argument name                  type                    in/out default?
     ------------------------------ ----------------------- ------ --------
     group_name                     varchar2                in
     section_name                   varchar2                in
     tag                            varchar2                in

### XML_SECTION_GROUP Attribute Sections

In Oracle8i versions higher than 8.1.5, the XML section group offers the ability to index and search within attribute values. Consider a document with the following lines:

      <comment author="jeeves">
        I really like interMedia Text
      </comment>

Now XML section group offers an attribute section. This allows the inclusion of attribute values to index. For example:

      ctx_ddl.add_attr_section('mysg','author','comment@author');

The syntax is similar to other add_section calls. The first argument is the name of the section group, the second is the name of the section, and the third is the tag, in the form <tag_name>@<attribute_name>. This tells interMedia Text to index the contents of the author attribute of the comment tag as the section "author".

Query syntax is just like for any other section:

    WHERE CONTAINS ( ... ,'jeeves WITHIN author...',...)...

and finds the document.

#### Attribute Value Sensitive Section Search

Attribute sections allow you to search the contents of attributes. They do not allow you to use attribute values to specify sections to search. For instance, given the document:

      <comment author="jeeves">
        I really like interMedia Text
      </comment>

You can find this document by asking:

      jeeves within comment@author

which is equivalent to "find me all documents which have a comment element whose author attribute's value includes the word jeeves".

However, there is no way to ask for something like:

      interMedia within comment where (@author = "jeeves")

in other words, "find me all documents where interMedia appears in a comment element whose author is jeeves". This feature -- attribute value sensitive section searching -- is planned for future versions of the product.

#### Dynamic Add Section

Because the section group is defined before creating the index, 8.1.5 is limited in its ability to cope with changing structured document sets; if your documents start coming with new tags, or you start getting new doctypes, you have to re-create the index to start making use of those tags.

8.1.6 and higher allows you to add new sections to an existing index without rebuilding the index, using alter index and the new add section parameters string syntax:

      add zone  section <section_name> tag <tag>
      add field section <section_name> tag <tag> [ visible | invisible ]

For instance, to add a new zone section named tsec using the tag title:

      alter index <indexname> rebuild
      parameters ('add zone section tsec tag title')

To add a new field section named asec using the tag author:

      alter index <indexname> rebuild
      parameters ('add field section asec tag author')

This field section would be invisible by default, just like when using add_field_section. To add it as visible field section:

      alter index <indexname> rebuild
      parameters ('add field section asec tag author visible')

Dynamic add section only modifies the index meta-data, and does not rebuild the index in any way. This means that these sections take effect for any document indexed after the operation, and do not affect any existing documents -- if the index already has documents with these sections, they must be manually marked for re-indexing (usually with an update of the indexed column to itself).

This operation does not support addition of special sections. Those would require all documents to be re-indexed, anyway. This operation cannot be done using rebuild online, but it should be a fairly quick operation.

### AUTO_SECTION_GROUP

Use AUTO_SECTION_GROUP group type to automatically create a zone section for each start-tag/end-tag pair in an XML document. The section names derived from XML tags are case-sensitive as in XML.

Attribute sections are created automatically for XML tags that have attributes. Attribute sections are named in the form attribute@tag.

Stop sections, empty tags, processing instructions, and comments are not indexed.

The following limitations apply to automatic section groups:

- You cannot add zone, field or special sections to an automatic section group.

- Automatic sectioning does not index XML document types (root elements.) However, you can define stop-sections with document type.

- The length of the indexed tags including prefix and namespace cannot exceed 64 characters.

- Tags longer than this are not indexed.

#### Automatic Sectioning in XML Documents

The following command creates a section group called auto with the AUTO_SECTION_GROUP group type. This section group automatically creates sections from tags in XML documents.

    begin
    ctx_ddl_create_section_group('auto', 'AUTO_SECTION_GROUP');
    end;
    create index myindex on docs(htmlfile) indextype is ctxsys.context
    parameters('filter ctxsys.null_filter section group auto');

| Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
Library | Service | Contents | Index