| Oracle Context Option QuickStart | Library |
Product |
Contents |
The following topics are covered in the chapter:
Attention: Before you can perform the QuickStart tasks described in this chapter, ConText Option must be installed and certain implementation tasks must be completed. If the required installation and installation tasks have not been completed, see "Implementing ConText Option (Chapter 4)."
You can start a ConText server by calling the ctxsrv/ctxsrvx executable from the command-line or through the ctxctl utility.
For example, to start a ConText server with the required personalities from the command-line of your server machine, execute the following command:
$ ctxsrv -user ctxsys/ctxsys -personality DQ -log ctx.log &
Note: The syntax for this example is specific to a UNIX-based operating system.
In this example, the password for the CTXSYS user is 'ctxsys.' The server is started in the background and information for the session is written to a file name ctx.log.
An additional personality, DML (M), can be assigned to ConText servers. ConText servers with the DML personality automatically reindex a text table when changes which affect the text index are made to the table.
Because the DML personality is not required for QuickStart, it is not discussed in this manual.
Additional Information:
Oracle ConText Option Administrator's Guide
Once a text indexing policy is created for a column and text is stored in the column, the column is ready for text indexing.
To define a text indexing policy for a column, call the CREATE_POLICY procedure in the CTX_DDL PL/SQL package and specify the following required parameters:
exec ctx_ddl.create_policy('ctx_docs','ctxdev.docs.text')In this example, a policy name CTX_DOCS is created, using all of the default ConText Option indexing options, for the TEXT column in the DOCS table owned by CTXDEV.
The ConText Option default indexing options are:
Additional Information:
Oracle ConText Option Administrator's Guide
Before you can perform a text query, you must create a text index for the text column you want to query.
In addition, if you want to use two-step queries, you must create a result table which is used to store the results of the query.
Once these tasks have been performed, you can use any one of the three supported query methods to query text in the column: two-step, one-step, or in-memory.
For example:
exec ctx_ddl.create_index('ctx_docs')In this example, CREATE_INDEX is called in SQL*Plus to create a text index for the text column (CTXDEV.DOCS.TEXT) in the CTX_DOCS policy.
After a text index is created for a column, ConText servers with the Query personality can process text queries for the column.
Additional Information:
Oracle ConText Option Administrator's Guide
The table also stores a score for each document. The score, generated by ConText Option, measures the relevance of a document to the query based on the number of occurrences of the query terms in the document.
The result table can have any name; however, it must have the structure (column names and datatypes) specified in the following example:
create table ctx_temp (textkey varchar(64),
score number,
conid number);
In this example, a result table named CTX_TEMP is created in SQL*Plus. The TEXTKEY column stores the primary key for the documents and the SCORE column stores the scores generated by a query.
The third column, CONID, stores a number which identifies the results for each query. This column is used only when the same result table is used to store the results for multiple queries.
Additional Information:
Oracle7 Server SQL Reference,
Oracle ConText Option Application Developer's Guide
In the second step, you query the result table to return a hitlist of the documents.
Attention: Because the result table does not store document details or the text of the document, if you want to create a hitlist that includes document details or retrieve the text of a document, you must perform a query that joins the original text table and the results table.
The following example illustrates a basic two-step query:
exec ctx_query.contains('ctx_docs','lotus|oracle','ctx_temp')
select score,title from ctx_temp, docs where ctx_temp.textkey=docs.pk order by score desc;
In this example, a search is performed on the text column (CTXDEV.DOCS.TEXT) in the CTX_DOCS policy to find all documents in which the term oracle or lotus occurs. The results of the search are stored in the CTX_TEMP results table.
Then, the CTX_TEMP and DOCS tables are joined by a query to create a hitlist which lists the SCORE and TITLE of each document in which the terms oracle or lotus occurs.
Additional Information:
Oracle ConText Option Application Developer's Guide
In a one-step query, the CONTAINS stored procedure and result tables required for two-step queries, are not used.
Note: Because SELECT statements operate on column and table names, the name of the text column is used in a one-step query, rather than the policy for the column.
The following example illustrates a one-step query that returns the same results as the two-step query example:
select score(1), pk, title from docs where contains(text, 'lotus | oracle', 1) > 0 order by score(1) desc;
Additional Information:
Oracle ConText Option Application Developer's Guide
OPEN_CON opens a CONTAINS cursor to a query buffer and executes a query. The results of the query are stored in the query buffer. FETCH_HIT retrieves the results, one hit at a time, and CLOSE_CON releases the CONTAINS cursor.
In-memory queries are generally faster than one-step and two-step queries for queries that return large hitlists. In addition, in-memory queries do not require the allocation of database tables for the results.
The following example illustrates an in-memory query that returns the same results as the two-step and one-step query examples:
declare
score char(5);
pk char(5);
title char(40);
curid number;
begin
curid := ctx_query.open_con(policy_name => 'ctx_docs',
text_query => 'lotus|oracle', score_sorted => true,
other_cols => 'title');
while (ctx_query.fetch_hit(curid, pk, score, title)>0)
loop
dbms_output.put_line(score||pk||substr(title,1,50));
end loop;
ctx_query.close_con(curid);
end;In this example, SCORE, PK, TITLE, and CURID are declared as variables used by CTX_QUERY.OPEN_CON and CTX_QUERY.FETCH_HIT.
The SCORE_SORTED argument for OPEN_CON specifies that the results of the query are stored in the buffer in descending order by score. The OTHER_COLS argument species that the TITLE column from the queried table is returned along with SCORE and PK in the query results.
FETCH_HITS retrieves SCORE, PK, and TITLE for each hit until the buffer is empty.
Additional Information:
Oracle ConText Option Application Developer's Guide
|
Prev Next |
Copyright © 1996 Oracle Corporation. All Rights Reserved. |
Library |
Product |
Contents |