2024年3月14日发(作者:)

Oracle Text使用小结

一、Oracle Text介绍

Oracle从7.3开始支持全文检索,即用户可以使用Oracle服务器的上下文

(ConText)完成基于文本的查询(具体可采用通配符查找、模糊匹配、相关分类、近似

查找、条件加权和词意扩充等方法);在Oracle 8.0.x中称为ConText ;在Oracle 8i

中称为interMedia Text ; Oracle9i中称为Oracle Text。Oracle Text是9i

标准版和企业版的一部分,Oracle9i将全文检索功能做为内置功能提供给用户,使得用户

在创建数据库实例时自动安装全文检索。

Oracle Text使Oracle 9i具备了强大的文本检索能力和智能化的文本管理能力。

使用Oracle Text,可以方便而有效地利用标准的SQL工具来构建基于文本的新的开发

工具或对现有应用程序进行扩展。应用程序开发人员可以在任何使用文本的Oracle数据

库应用程序中充分利用Oracle Text搜索,应用范围可以是现有应用程序中可搜索的注

释字段,也可是实现涉及多种文档格式(包括doc,excel,txt,pdf等)和复杂搜索标

准的大型文档管理系统,还可是来自Internet和文件系统的文本数据搜索XML应用程序。

Oracle Text支持Oracle数据库所支持的大多数语言的基本全文搜索功能。

要使用Oracle Text,必须具有CTXAPP角色或者是CTXSYS用户。Oracle Text

为系统管理员提供CTXSYS用户,为应用程序开发人员提供CTXAPP角色。CTXSYS 用户

可执行以下任务:启动Oracle Text服务器,执行CTXAPP角色的所有任务。具有CTXAPP

角色的用户可执行以下任务:创建索引,管理Oracle Text数据字典,包括创建和删除

首选项,进行Oracle Text查询,使用Oracle Text PL/SQL程序包。

二、Oracle Text索引

a、Index简介:

索引就是将文本打碎分成很多标记(token),这些标记通常是用空格分开的一个

个单词。Oracle Text应用的实现可以理解为就是一个“装载数据—> 配置索引—> 索

引数据—>执行检索—> 维护索引”的过程。

Index的索引类型有:CONTEXT,CTXCAT,CTXRULE。下面就对索引做简单的

描述:

Index Type Application Type

Use this index to build a text retrieval

application when your text consists of

large coherent documents. You can

CONTEXT

index documents of different formats

CONTAINS

such as MS Word, HTML, XML, or plain

text. With a context index, you can

customize your index in a variety of

ways.

CTXCAT

Use this index type to index small text

CATSEARCH

fragments such as item names, prices

Query Operator

and descriptions that are stored

across columns. With this index, query

performance is improved for mixed

queries.

Use a CTXRULE index to build a document

classification application. The

CTXRULE index is an index created on

CTXRULE a table of queries, where each query MATCHES

has a classification. Single documents

(plain text, HTML, or XML) can be

classified using the MATCHES operator.

最常用的就是 CONTEXT索引,使用最通用的CONTAINS操作符进行查询。

b、CONTEXT 索引

Oracle Text CONTEXT 索引是反向索引(inverted index),每个标记

(token)都映射着包含它自己的文本位置。在索引建好后,可以查到Oracle自动

产生的表(假设索引名为myindex):DR$myindex$I、DR$myindex$K、

DR$myindex$R、DR$myindex$N,其中以I表最重要,该表保存的是Oracle 分析

文档后生成的token记录,包括token出现的位置、次数、hash值等。

包括一下参数:Datastore Types,Filter Types,Lexer Types,Wordlist

Type,Storage Types,Section Group Types,Stoplists,System-Defined

Preferences,System Parameters,每个参数设置的目的是:

Preference Class Answers the Question

Datastore

Filter

Lexer

Wordlist

Storage

Stop List

Section Group

How are your documents stored?

How can the documents be converted to plain text?

What language is being indexed?

How should stem and fuzzy queries be expanded?

How should the index tables be stored?

What words or themes are not to be indexed?

Is querying within sections enabled, and how are

the document sections defined?

下面就对每个参数包含的值、值的意义及目的做简单描述:

1、Datastore Types

Datastore

DIRECT_DATASTORE

MULTI_COLUMN_DATASTORE

Type Use When

Data is stored internally in the text column.

Each row is indexed as a single document.

Data is stored in a text table in more than

one column. Columns are concatenated to

create a virtual document, one per row.

DETAIL_DATASTORE Data is stored internally in the text column.

Document consists of one or more rows stored