Oracle9i full-text retrieval technology developer network Oracle

Source: Internet
Author: User
Tags lexer new set
Oracle9i full-text retrieval technology developer network Oracle

Oracle9i full-text retrieval technology developer network Oracle

The ORACLE tutorial is: Oracle9i full-text retrieval technology developer network Oracle.

Introduction: work in detail. The difference between a master and a cainiao is that the master knows everything and the cainiao knows something. Computer tips collect the latest tricks and tricks, so that you can easily embark on the road to master. >

  SummaryFull-Text retrieval is one of the key technologies of Intelligent Information Management. Oracle Text, as a component of Oracle9i, provides powerful full-Text retrieval functions and uses Oracle9i as the background database, you can make full use of its full-text retrieval technology to build a complex large-scale document management system. This article mainly introduces the architecture and usage of Oracle Text.

  KeywordsOracle Text full-Text search

Oracle has been committed to the research of full-text retrieval technology. When Oracle9i Rlease2 was released, the full-text retrieval technology of Oracle databases was already perfect, oracle Text enables Oracle9i to provide powerful Text retrieval capabilities and Intelligent Text management capabilities. Oracle Text is the new name used by Oracle9i. In Oracle8/8i, it is called Oracle interMedia Text. Before Oracle8, its name was Oracle ConText Cartridge. With Oracle9i and Oracle Text, you can easily and effectively use standard SQL tools to build new Text-based development tools or expand existing applications. Application developers can make full use of Oracle Text Search in any Oracle database application that uses Text. the application scope can be the comment fields that can be searched in existing applications, but it also implements a large document management system that involves a variety of document formats and complex search standards. Oracle Text supports basic full-Text search in most languages supported by Oracle databases. This article describes how to use the full-text retrieval technology of Oracle9i to provide an excellent solution for your applications.
 
  1 architecture of Oracle Text

Is the architecture of Oracle Text.


Architecture of Oracle Text

Based on the architecture diagram above, the main logical steps used in Oracle Text Index documents are as follows:

(1) store data to search all rows in a table and read the data in the column. Generally, this is only column data, but some data storage uses column data as a pointer to document data. For example, URL_DATASTORE uses column data as a URL.

(2) The filter extracts document data and converts it to text representation. This is required when storing binary files (such as Word or Acrobat files. The output of the filter does not need to be in plain text format-it can be in text format such as XML or HTML.

(3) The Field splitter extracts the output information of the filter and converts it to plain text. Different text formats, including XML and HTML, have different slots. Converting to plain text involves detecting important document field tags, removing invisible information, and re-formatting the text.

(4) the lexical analyzer extracts plain text from the field splitter and splits it into discontinuous tags. There are both lexical analyzers used by blank character separation languages and specialized lexical analyzers used by complicated segments in Asian languages.

(5) The index engine extracts all the tokens in the lexical analyzer, the offset of the document segment in the field splitter, and the list of low-information-content words called non-indexed words, and builds reverse indexes. Inverted indexes store tags and documents containing these tags.

[NextPage]

  2. Simple Example

Here is a simple example to illustrate how to use Oracle Text to implement full-Text search. Orcale9i provides Oracle Text Manager to simplify a lot of work. All the work done in Oracle Text Manager can be done through PL/SQL. To use Oracle Text, you must have the CTXAPP role or CTXSYS user. Oracle Text provides the system administrator with the CTXSYS user and the CTXAPP role for application developers.

The CTXSYS user can execute the following tasks: Start the Oracle Text server and execute all tasks of the CTXAPP role.
Users with the CTXAPP role can perform the following tasks: Create an index, manage the Oracle Text Data Dictionary, including creating and deleting preferences, query Oracle Text, and use the Oracle Text PL/SQL package.

Steps for using Oracle Text:

(1) create a table to save some documents. This example uses a primary keyword column to identify each document and a small VARCHAR2 column to save each document.

Create table docs (id number primary key, text VACHAR2 (80 ));

(2) place two sample documents in the table:

Insert into docs VALUES (1, 'the first doc ');
Insert into docs VALUES (2, 'The second doc ');
COMMIT;

(3) Use Oracle Text Manager to create and modify preferences. preferences are associated with indexes.

(4) use Oracle Text Manager to create Text indexes. In addition, you can enter the following SQL statement that uses the default preference:

Create index doc_index ON docs (text) indextype is ctxsys. CONTEXT;

(5) use the CONTAINS function to issue Content-based document queries. For example:

SELECT id FROM docs where contains (text, 'First ')> 0;

This will find all rows in the docs that contain the word first (that is, document 1) in the text column. More than 0 of the statements are required for valid Oracle SQL statements. Oracle SQL does not support Boolean return values of functions.

The above is just a simple example. It aims to provide the complete steps to create a full-Text index using Oracle Text, which are summarized as follows:

(1) create a table and load text (including text fields to be retrieved)

(2) Configure Indexes

(3) create an index

(4) issue a query

(5) index maintenance: synchronization and optimization (will be introduced later)

   3. Text Loading

To achieve full-text search, you must first load the correct text into the database table. By default, the index creation requires that the document be loaded in the text column, although you can store documents in other ways (including file systems and URLs) (set in the "Data Storage" option ). By default, the system should load the document in the text column. The text column can be VARCHAR2, CLOB, BLOB, CHAR, or BFILE. Note that text can be stored only when the Oracle7 system is migrated to Oracle8 using the LONG and long raw columns. You cannot create an index for column NCLOB, DATE, or NUMBER.

For document formats, the system can index most document formats, including HTML, PDF, Microsoft Word, and plain text, any document type can be loaded into the text column (set in the "filter" option ). For more information about Supported document Formats, see Appendix "Supported Filter Formats" in the Oracle Text User's Guide and Reference ".

The load methods include the following:

(1) SQL INSERT statement

(2) ctxload Executable File

(3) SQL * Loader

(4) Load LOB's DBMS_LOB.LOADFROMFILE () PL/SQL process from BFILE

(5) Oracle Call Interface

[NextPage]

  4. Create an index for text

After the Text is loaded into the Text column, you can create an Oracle Text Index. Documents are stored in many different solutions, formats, and languages. Therefore, each Oracle Text Index has many options that need to be set to configure indexes for specific situations. When creating an index, Oracle Text can use several default values, but in most cases, you are required to configure the index by specifying the preference.

Many options of each index constitute a functional group called "class". Each class embodies one aspect of the Configuration. You can think of these classes as problems related to the document database. For example, data storage, filters, lexical analyzers, related word lists, and storage.

Each class has many predefined behaviors, called objects. Each object is a possible answer to a class question, and most objects contain attributes. You can use attributes to customize objects so that the index configuration is more

[1]

The ORACLE tutorial is: Oracle9i full-text retrieval technology developer network Oracle. It is changeable to adapt to different applications.

(1) Storage Class

The storage class specifies the tablespace parameters and creation parameters for the database tables and indexes that constitute the Oracle Text Index. It has only one basic object: BASIC_STORAGE. Its attributes include: I _Index_Clause, I _Table_Clause, K_Table_Clause, N_Table_Clause, P_Table_Clause, and R_Table_Clause.

(2) Data Storage (Datastore)

Data storage: Location of text stored in columns and other information. By default, text is stored directly in the column, and each row in the table represents a separate complete document. Other data storage locations include those stored in individual files or Web pages identified by their URLs. Seven basic objects include Default_Datastore, Detail_Datastore, Direct_Datastore, File_Datastore, Multi_Column_Datastore, URL_Datastore, and User_Datastore ,.

(3) Section Group class

A document field group is an object used to specify a group of documents. You must first define the document segment before using the index to query WITHIN the document segment through the WITHIN operator. The document segment is defined as part of the document segment group. Contains seven basic objects: AUTO_SECTION_GROUP, BASIC_SECTION_GROUP, HTML_SECTION_GROUP, NEWS_SECTION_GROUP, NULL_SECTION_GROUP, XML_SECTION_GROUP, and PATH_SECTION_GROUP.

(4) Wordlist class

The related Word Table identifies the language of the stem and fuzzy match query options used for indexing. There is only one basic object BASIC_WORDLIST, and its attributes include: fuzzy_Match, Fuzzy_Numresults, Fuzzy_Score, Stemmer, Substring_Index, Wildcard_Maxterms, Prefix_Index, Prefix_Max_Length, and Prefix_Min_Length.

(5) Index Set)

An index is a collection of one or more Oracle indexes (not an Oracle Text Index). It is used to create an Oracle Text Index of the CTXCAT type and has only one basic object, BASIC_INDEX_SET.

(6) Lexer class

The Lexical analyzer class identifies the language used by the text and also determines how to mark the text. The default lexical analyzer is used in English or other Western European languages. It is marked with spaces, standard punctuation marks, and non-alphanumeric characters, and Case sensitivity is disabled. Contains eight basic objects: BASIC_LEXER, CHINESE_LEXER, CHINESE_VGRAM_LEXER, JAPANESE_LEXER, JAPANESE_VGRAM_LEXER, KOREAN_LEXER, korean1_morph _ LEXER, MULTI_LEXER.

(7) Filter class

The filter determines how to filter text to create an index. You can use filters to index documents processed by the text processor, formatted documents, plain text, and HTML documents, including five basic objects: CHARSET_FILTER, INSO_FILTER INSO, NULL_FILTER, PROCEDURE_FILTER, and USER_FILTER.

(8) Non-index Word Table (Stoplist) Class

A non-indexed Word Table class is used to specify a group of words that are not indexed (referred to as non-indexed words ). There are two basic objects: BASIC_STOPLIST (all non-indexed words in one language) and MULTI_STOPLIST (multi-language non-indexed Word tables that contain non-indexed words in multiple languages ).

   5. Query

After an index is created, you can use the CONTAINS operator in the SELECT statement to issue a text query. CONTAINS can be used for two types of queries: Word query and ABOUT query.

5.1 word query example

Word query is a query of exact words or phrases between single quotes in the input to the CONTAINS operator. In the following example, all documents with the oracle word in the text column are searched. The scores of each row are selected by the SCORE operator of tag 1:

Select score (1) title from news where contains (text, 'oracle ', 1)> 0;

In a query expression, you can use text operators such as and or to obtain different results. You can also add structural predicates to the WHERE clause. You can use count (*), CTX_QUERY.COUNT_HITS, or CTX_QUERY.EXPLAIN to calculate the number of hit (matching) queries.

5.2 ABOUT query example

In all languages, ABOUT queries increase the number of related documents returned by a query. In English, ABOUT queries can use the indexed key word component, which is created by default. In this way, the operator returns a document based on the query concept, rather than just the specified exact word or phrase. For example, the following query searches for all documents about the topic politics in the text column, instead of documents containing only the word "politics:

Select score (1) title from news where contains (text, 'about (politics) ', 1)> 0;

[NextPage]

  6. Show the documents meeting the query Conditions

Generally, you can query the returned documents by using Oracle Text. The user selects a document from the hit list and the application displays the document in some form. Oracle Text allows you to reproduce documents in different ways. For example, you can highlight the query word to display the document. The highlighted query word can be a word in the related word query or a key word in the English ABOUT query.

The following is information about the output effect and the process used for each output effect:

Highlighted document, in plain text format (CTX_DOC.MARKUP)

Highlighted document, HTML Version (CTX_DOC.MARKUP)

Highlight the offset information of the plain text version (CTX_DOC.HIGHLIGHT)

Highlight the offset information of the HTML Version (CTX_DOC.HIGHLIGHT)

Plain text version, not highlighted (CTX_DOC.FILTER)

HTML Version document, not highlighted (CTX_DOC.FILTER)

  7. Index Maintenance

After the index is created, what if the table data changes, such as adding or modifying records? Because no DML statement occurs on the table, the index is not automatically modified. Therefore, you must regularly synchronize (sync) and optimize (optimize) indexes to correctly reflect data changes.
After the index is created, you can check that Oracle automatically generates the following tables under this user: (assuming the index name is myindex ):
DR $ myindex $ I, DR $ myindex $ K, DR $ myindex $ R, DR $ myindex $ N

The I table is the most important. You can query this table:

Select token_text, token_count from DR $ myindex $ I where rownum <= 20;

The query result is omitted here. As you can see, the table stores the term records generated after Oracle analyzes your documents, including the location, number of times, and hash value of the term. When the content of the document changes, you can imagine that the content of this I table should also change accordingly to ensure that the content is correctly retrieved by Oracle during full-text retrieval (because of the so-called full-text retrieval, in fact, the core is to query this table ). So how to maintain the content of the table, you cannot re-create the index for every data change, which requires sync and optimize.

Sync: Save the new term to the I table;

Optimize: clears the garbage from the I table, mainly to delete the deleted term from the I table.

Oracle provides a so-called ctx server for synchronization and optimization. You only need to run the process in the background. It monitors data changes and synchronizes data in a timely manner. In addition, you can also use the following job (the job should be created under the same user as the table ):
Create or replace procedure sync
Is
Begin
Execute immediate
'Alter index myindex rebuild online' |
'Parameters (''sync '')';
Execute immediate
'Alter index myindex rebuild online' |
'Parameters (''optimize full maxtime unlimited '')';
End sync;
/

[2]

The ORACLE tutorial is: Oracle9i full-text retrieval technology developer network Oracle.
Set ServerOutput on
Declare
V_job number;
Begin
Dbms_Job.Submit
(
Job => v_job,
What => 'sync ;',
Next_date => sysdate,/* default */
Interval => 'sysdate + 100'/* = 1 day/(24 hrs * 30 min) = 2 mins */
);
Dbms_Job.Run (v_job );
Dbms_Output.Put_Line ('submitted as job # '| to_char (v_job ));
End;
/>
Job SYSDATE + (1/720) means to synchronize every 2 minutes. The specific time interval can be determined based on your application needs.

   8. Summary

Text is the most effective carrier for companies and organizations of all sizes that contain a wealth of information. The launch of Oracle Text marks a new set of technologies provided by Oracle, you can conveniently and securely manage enterprise text information. Oracle Text allows application developers to transparently add full-Text retrieval capabilities to SQL-based applications. Oracle Text is also the core component of other Oracle products, such as Oracle9iAS Portal, Oracle eBusiness Suite, oracle Ultra Search and Oracle Internet File System. By using the full-Text retrieval technology provided by Oracle Text, your applications can have powerful full-Text retrieval capabilities.

Previous Page

[3]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.