The following example shows how to classify documents by defining simple categories, creating a CTXRULE index, and using MATCHES, using the CTXAPP role user myuser.
Connect as the CTXAPP role user myuser:
CONNECT myuser;
We must create a rule table and populate it with query rules. In this example, we create a table called queries. Each row defines a category with an ID, and a rule which is a query string:
CREATE TABLE queries (
query_id NUMBER,
query_string VARCHAR2(80)
);
INSERT INTO queries VALUES (1, 'oracle');
INSERT INTO queries VALUES (2, 'larry or ellison');
INSERT INTO queries VALUES (3, 'oracle and text');
INSERT INTO queries VALUES (4, 'market share');
Create a CTXRULE index as follows:
CREATE INDEX queryx ON queries(query_string) INDEXTYPE IS CTXSYS.CTXRULE;
Use the MATCHES operator in the WHERE clause of a SELECT statement to match documents to queries and hence classify.
COLUMN query_string FORMAT a35;
SELECT query_id,query_string FROM queries
WHERE MATCHES(query_string,
'Oracle announced that its market share in databases
increased over the last year.')>0;
QUERY_ID QUERY_STRING
---------- -----------------------------------
1 oracle
4 market share
As shown, the document string matches categories 1 and 4. With this classification you can perform an action, such as writing the document to a specific table or e-mailing a user.
Classifying Documents in Oracle Text for more extended classification examples