CREATE_POLICY

Creates a policy to use with the CTX_DOC.POLICY_* procedures, certain Oracle Data Mining procedures, and the in-memory Text index.

Syntax

PROCEDURE CTX_DDL.CREATE_POLICY(
         policy_name     IN VARCHAR2,
         filter          IN VARCHAR2 DEFAULT NULL,
         section_group   IN VARCHAR2 DEFAULT NULL,
         lexer           IN VARCHAR2 DEFAULT NULL,
         stoplist        IN VARCHAR2 DEFAULT NULL,
         wordlist        IN VARCHAR2 DEFAULT NULL,
         datastore       IN VARCHAR2 DEFAULT NULL
);

policy_name

Specify the name for the new policy. Policy names and Text indexes share the same namespace.

filter

Specify the filter preference to use.

section_group

Specify the section group to use. You can specify any section group that is supported by CONTEXT index.

lexer

Specify the lexer preference to use. Your INDEX_THEMES attribute must be disabled.

stoplist

Specify the stoplist preference to use.

wordlist

Specify the wordlist preference to use.

datastore

Specify the datastore preference to use for the in-memory Text index.

Note: The datastore parameter is only supported for the in-memory Text index.

Examples

Create a lexer preference named mylex.

begin
   ctx_ddl.create_preference('mylex', 'BASIC_LEXER');
   ctx_ddl.set_attribute('mylex', 'printjoins', '_-');
end;

Create a stoplist preference named mystop.

begin
   ctx_ddl.create_stoplist('mystop', 'BASIC_STOPLIST');
   ctx_ddl.add_stopword('mystop', 'because');
   ctx_ddl.add_stopword('mystop', 'nonetheless');
   ctx_ddl.add_stopword('mystop', 'therefore');
end;

Create a wordlist preference named mywordlist.

begin
   ctx_ddl.create_preference('mywordlist', 'BASIC_WORDLIST');
end;

Create a datastore preference named my_file_datastore.

begin
   create or replace directory wdirectory as '/path1/path2';
   GRANT read ON DIRECTORY WDIRECTORY TO user;
   EXEC ctx_ddl.create_preference('my_file_datastore', 'DIRECTORY_DATASTORE');
   EXEC ctx_ddl.set_attribute('my_file_datastore', 'DIRECTORY', 'WDIRECTORY');
end;

Create a policy named mypolicy.

exec ctx_ddl.create_policy(
   'mypolicy',
    NULL,
    NULL,
   'mylex',
   'mystop',
   'mywordlist',
   'my_file_datastore'
);

or

exec ctx_ddl.create_policy(
   policy_name => 'mypolicy',
   lexer => 'mylex',
   stoplist => 'mystop',
   wordlist => 'mywordlist',
   datastore => 'my_file_datastore'
);

Use ALTER TABLE to apply your defined policy to a column for in-memory search. Then enter your query statement, using the CONTAINS operator in the WHERE clause:

ALTER TABLE my_tab INMEMORY TEXT(my_txt_col using 'mypolicy');

SELECT id from my_tab WHERE CONTAINS(my_txt_col, 'Washington')>0;

Update the policy with the following:

exec ctx_ddl.update_policy(
   policy_name => 'mypolicy',
   lexer => 'my_new_lex'
);

Drop the policy with the following:

exec ctx_ddl.drop_policy(policy_name => 'mypolicy');

Related Topics