HIGHLIGHT
Use the CTX_DOC.HIGHLIGHT procedure to generate highlight offsets for a document. The offset information is generated for the terms in the document that satisfy the query you specify. These highlighted terms are either the words that satisfy a word query or the themes that satisfy an ABOUT query.
You can generate highlight offsets for either plaintext or HTML versions of the document. The table returned by CTX_DOC.HIGHLIGHT does not include any graphics found in the original document. Apply the offset information to the same documents filtered with CTX_DOC.FILTER .
You usually call this procedure after a query, from which you identify the document to be processed. You can store the highlight offsets to either an in-memory PL/SQL table or a result table.
Note that for queries that have predicates used mainly for filtering documents at query time, the predicates are ignored during highlighting. This applies to SNIPPET, MARKUP and HIGHLIGHT procedures. The following predicates are treated as filter predicates for this purpose: SDATA, HASPATH, and WITHIN/INPATH searching inside XML attributes.
See CTX_DOC.POLICY_HIGHLIGHT for a version of this procedure that does not require an index.
The performance of the procedures SNIPPET, HIGHLIGHT, and MARKUP can be improved by using the forward index feature of Oracle Text.
See Also: Oracle Text Application Developer’s Guide for more information about forward index
Syntax 1: In-Memory Result Storage
exec CTX_DOC.HIGHLIGHT(
index_name IN VARCHAR2,
textkey IN VARCHAR2,
text_query IN VARCHAR2,
restab IN OUT NOCOPY HIGHLIGHT_TAB,
plaintext IN BOOLEAN DEFAULT FALSE,
use_saved_copy IN NUMBER DEFAULT CTX_DOC.SAVE_COPY_FALLBACK);
exec CTX_DOC.HIGHLIGHT_CLOB_QUERY(
index_name IN VARCHAR2,
textkey IN VARCHAR2,
text_query IN CLOB,
restab IN OUT NOCOPY HIGHLIGHT_TAB,
plaintext IN BOOLEAN DEFAULT FALSE,
use_saved_copy IN NUMBER DEFAULT CTX_DOC.SAVE_COPY_FALLBACK);
Syntax 2: Result Table Storage
exec CTX_DOC.HIGHLIGHT(
index_name IN VARCHAR2,
textkey IN VARCHAR2,
text_query IN VARCHAR2,
restab IN VARCHAR2,
query_id IN NUMBER DEFAULT 0,
plaintext IN BOOLEAN DEFAULT FALSE,
use_saved_copy IN NUMBER DEFAULT CTX_DOC.SAVE_COPY_FALLBACK);
exec CTX_DOC.HIGHLIGHT_CLOB_QUERY(
index_name IN VARCHAR2,
textkey IN VARCHAR2,
text_query IN CLOB,
restab IN VARCHAR2,
query_id IN NUMBER DEFAULT 0,
plaintext IN BOOLEAN DEFAULT FALSE,
use_saved_copy IN NUMBER DEFAULT CTX_DOC.SAVE_COPY_FALLBACK);
index_name
Specify the name of the index associated with the text column containing the document identified by textkey.
textkey
Specify the unique identifier (usually the primary key) for the document.
The textkey parameter can be as follows:
-
a single column primary key value
-
encoded specification for a composite (multiple column) primary key. Use the CTX_DOC.PKENCODE procedure.
-
the rowid of the row containing the document
Toggle between primary key and rowid identification using CTX_DOC.SET_KEY_TYPE.
text_query
Specify the original query expression used to retrieve the document. If NULL, no highlights are generated.
If text_query includes wildcards, stemming, fuzzy matching which result in stopwords being returned, HIGHLIGHT does not highlight the stopwords.
If text_query contains the threshold operator, the operator is ignored. The HIGHLIGHT procedure always returns highlight information for the entire result set.
restab
You can specify that this procedure store highlight offsets to either a table or to an in-memory PL/SQL table.
To store results to a table specify the name of the table. The table must exist before you call this procedure.
See Also: “Highlight Table” in Oracle Text Result Tables for more information about the structure of the highlight result table.
To store results to an in-memory table, specify the name of the in-memory table of type CTX_DOC.HIGHLIGHT_TAB. The HIGHLIGHT_TAB datatype is defined as follows:
type highlight_rec is record (
offset number,
length number
);
type highlight_tab is table of highlight_rec index by binary_integer;
CTX_DOC.HIGHLIGHT clears HIGHLIGHT_TAB before the operation.
query_id
Specify the identifier used to identify the row inserted into restab. When query_id is not specified or set to NULL, it defaults to 0. You must manually truncate the table specified in restab.
plaintext
Specify TRUE to generate a plaintext offsets of the document. Specify FALSE to generate HTML offsets of the document if you are using the AUTO_FILTER filter or indexing HTML documents.
use_saved_copy
Specify whether to refer to the $D table to fetch the copy of the document, and what action to take when the copy of the document is not available in the $D table. The default value is CTX_DOC.SAVE_COPY_FALLBACK.
You can specify one of the following values for the use_saved_copy parameter:
-
CTX_DOC.SAVE_COPY_FALLBACK: Fetch the copy of the document from the $D table. If the copy of the document is not present in the $D table, then fetch the document from the data store. -
CTX_DOC.SAVE_COPY_ERROR: Fetch the copy of the document from the $D table. If the copy of the document is not present in the $D table, then show an error message. Specify this value when you want to implement a specific fallback logic when the copy of the document is not available in the $D table. -
CTX_DOC.SAVE_COPY_IGNORE: Always fetch the document from the data store.
Examples
Create the highlight table to store the highlight offset information:
create table hightab(query_id number,
offset number,
length number);
Word Highlighting in the Presence of Filters
When performing highlight on queries such as the following, only the keyword (“dog” in these examples) will be highlighted. The filtering predicates after the AND operator will be ignored.
begin
ctx_doc.highlight('newsindex', '20', 'dog AND cat WITHIN titlesection@name', 'hightab', 0, FALSE);
end;
begin
ctx_doc.highlight('newsindex', '20', 'dog AND SDATA(price > 100)', 'hightab', 0, FALSE);
end;
Word Highlight Offsets
To obtain HTML highlight offset information for document 20 for the word dog:
begin
ctx_doc.highlight('newsindex', '20', 'dog', 'hightab', 0, FALSE);
end;
begin
ctx_doc.highlight('newsindex', '20', 'dog AND cat WITHIN titlesection', 'hightab', 0, FALSE);
end;
Assuming the index newsindex has a theme component, obtain HTML highlight offset information for the theme query of politics by issuing the following query:
begin
ctx_doc.highlight('newsindex', '20', 'about(politics)', 'hightab', 0, FALSE);
end;
The output for this statement are the offsets to highlighted words and phrases that represent the theme of politics in the document.
Restrictions
CTX_DOC.HIGHLIGHT does not support the use of query templates or highlighting XML attribute values.
Related Topics
“MARKUP”
“SNIPPET”