Oracle Text in APEX

156
SAGE Computing Services Customised Oracle Training Workshops and Consulting Oracle Text in Apex Advanced Indexing Techniques Integrated with Application Express Scott Wesley Systems Consultant & Trainer

Transcript of Oracle Text in APEX

Page 1: Oracle Text in APEX

SAGE Computing Services

Customised Oracle Training Workshops and Consulting

Oracle Text in Apex

Advanced Indexing Techniques Integrated with

Application Express

Scott Wesley

Systems Consultant & Trainer

Page 2: Oracle Text in APEX

Agenda

• Introduction

• Architecture

• Fundamentals

• Considerations

• Setting Up

• Samples

• Index Maintenance

• Visualisation

• New Features

Page 3: Oracle Text in APEX

Larry Lessig?

Page 4: Oracle Text in APEX

the law is strangling creativity

http://www.ted.com/talks/larry_lessig_says_the_law_is_strangling_creativity.html

http://presentationzen.blogs.com/presentationzen/2005/10/the_lessig_meth.html

Page 5: Oracle Text in APEX

Identity 2.0 – Dick Hardt

http://identity20.com/media/OSCON2005/

Page 6: Oracle Text in APEX

who’s the Dick on your site

Page 7: Oracle Text in APEX

Connor McDonald

http://www.oracledba.co.uk

Page 8: Oracle Text in APEX

so today’s going to be more like this

Page 9: Oracle Text in APEX

and this

Page 10: Oracle Text in APEX

after I show a few pictures

Page 11: Oracle Text in APEX

who_am_i;

Page 13: Oracle Text in APEX
Page 14: Oracle Text in APEX
Page 15: Oracle Text in APEX

balance

Page 16: Oracle Text in APEX
Page 17: Oracle Text in APEX
Page 18: Oracle Text in APEX
Page 19: Oracle Text in APEX
Page 20: Oracle Text in APEX
Page 21: Oracle Text in APEX
Page 22: Oracle Text in APEX
Page 23: Oracle Text in APEX

Why use Oracle Application Express?

Page 24: Oracle Text in APEX

Why use Oracle Text?

Page 25: Oracle Text in APEX
Page 26: Oracle Text in APEX

What is Oracle Text?

Page 27: Oracle Text in APEX

Document Collection

Page 28: Oracle Text in APEX
Page 29: Oracle Text in APEX

Catalogue Information

Page 30: Oracle Text in APEX
Page 31: Oracle Text in APEX

Document Classification

Page 32: Oracle Text in APEX
Page 33: Oracle Text in APEX

Architecture

Page 34: Oracle Text in APEX

Class Description

Datastore How are your documents stored?

Filter How can the documents be converted to plain text?

Lexer What language is being indexed?

Wordlist How should stem and fuzzy queries be expanded?

Storage How should the index data be stored?

Stop List What words or themes are not to be indexed?

Section Group How are documents sections defined?

Page 35: Oracle Text in APEX

1) Example

Page 36: Oracle Text in APEX

CREATE INDEX ctx_name ON my_names(name)

INDEXTYPE IS ctxsys.context

PARAMETERS ('DATASTORE CTXSYS.DEFAULT_DATASTORE');

Page 37: Oracle Text in APEX

SQL> SELECT SCORE(1), name

2 FROM my_names

3 WHERE CONTAINS(name, 'fuzzy(john,,,weight)', 1) > 0

4 ORDER BY SCORE(1) DESC;

SCORE(1) NAME

---------- ----------------------------------------

100 John

100 John

70 Jon

70 Jon

63 Joan

63 Joan

52 Jong

48 Jona

8 rows selected.

Page 38: Oracle Text in APEX

2) Datastore

Page 39: Oracle Text in APEX

CTXSYS.DEFAULT_DATASTORE

Page 40: Oracle Text in APEX

BLOB

Page 41: Oracle Text in APEX

BFiles

Page 42: Oracle Text in APEX

Pointers to objects on file system

Page 43: Oracle Text in APEX

URLs

Page 44: Oracle Text in APEX

Pointers to objects on the intertube

Page 45: Oracle Text in APEX

User Defined

Page 46: Oracle Text in APEX

Why would you?

Page 47: Oracle Text in APEX

3) Index Type

Page 48: Oracle Text in APEX

a) CONTEXT

Page 49: Oracle Text in APEX

Document Collection

Page 50: Oracle Text in APEX

large document size

Page 51: Oracle Text in APEX

provides a score

Page 52: Oracle Text in APEX

asynchronous index & table data

Page 53: Oracle Text in APEX
Page 54: Oracle Text in APEX

CONTAINS

Page 55: Oracle Text in APEX

b) CTXCAT

Page 56: Oracle Text in APEX

Catalogue Information

Page 57: Oracle Text in APEX

smaller documents

Page 58: Oracle Text in APEX

text fragments

Page 59: Oracle Text in APEX

multiple attributes

Page 60: Oracle Text in APEX

set lists

Page 61: Oracle Text in APEX

similar to typical index paradigm

Page 62: Oracle Text in APEX

transactional

Page 63: Oracle Text in APEX
Page 64: Oracle Text in APEX

CATSEARCH

Page 65: Oracle Text in APEX

c) CTXRULE

Page 66: Oracle Text in APEX

Document Classification

Page 67: Oracle Text in APEX

routing information

Page 68: Oracle Text in APEX

displace manual interaction

Page 69: Oracle Text in APEX

not binary files

Page 70: Oracle Text in APEX

MATCHES

Page 71: Oracle Text in APEX

4) Considerations

Page 72: Oracle Text in APEX

location of text

Page 73: Oracle Text in APEX

document format

Page 74: Oracle Text in APEX

bypassing rows - images

Page 75: Oracle Text in APEX

character set

Page 76: Oracle Text in APEX

language

Page 77: Oracle Text in APEX

fuzzy matching & stemming

Page 78: Oracle Text in APEX

wildcard query performance

Page 79: Oracle Text in APEX
Page 80: Oracle Text in APEX

stopwords & stopthemes

Page 81: Oracle Text in APEX

query performance and storage of LOBs

Page 82: Oracle Text in APEX

mixed queries

Page 83: Oracle Text in APEX

5) Setting up

Page 84: Oracle Text in APEX

GRANT ctxapp TO ausoug;

Page 85: Oracle Text in APEX

create & delete indexing preferences

Page 86: Oracle Text in APEX

use Oracle Text PL/SQL supplied packages

Page 87: Oracle Text in APEX

1* select grantee, owner, table_name, privilege from dba_tab_privs where table_name =

'CTX_DDL'

SQL> /

GRANTEE OWNER TABLE_NAME PRIVILEGE

-------------------- ------------ ------------------------------ --------------------

CTXAPP CTXSYS CTX_DDL EXECUTE

APEX_040000 CTXSYS CTX_DDL EXECUTE

APEX_030200 CTXSYS CTX_DDL EXECUTE

AUSOUG CTXSYS CTX_DDL EXECUTE

XDB CTXSYS CTX_DDL EXECUTE

5 rows selected.

Page 88: Oracle Text in APEX

PLS-00201: identifier "string" must be declared

Page 89: Oracle Text in APEX

CTX PL/SQL Packages

GRANT EXECUTE ON CTXSYS.CTX_CLS TO ausoug;

GRANT EXECUTE ON CTXSYS.CTX_DDL TO ausoug;

GRANT EXECUTE ON CTXSYS.CTX_DOC TO ausoug;

GRANT EXECUTE ON CTXSYS.CTX_OUTPUT TO ausoug;

GRANT EXECUTE ON CTXSYS.CTX_QUERY TO ausoug;

GRANT EXECUTE ON CTXSYS.CTX_REPORT TO ausoug;

GRANT EXECUTE ON CTXSYS.CTX_THES TO ausoug;

GRANT EXECUTE ON CTXSYS.CTX_ULEXER TO ausoug;

Page 90: Oracle Text in APEX

Using URL Datastore in 11g

CREATE ROLE apex_url_datastore_role;

GRANT apex_url_datastore_role TO APEX_040000

WITH ADMIN OPTION;

GRANT apex_url_datastore_role TO ausoug;

EXEC

ctxsys.ctx_adm.set_parameter

('file_access_role'

,'APEX_URL_DATASTORE_ROLE');

Page 91: Oracle Text in APEX

Demonstrations

Script Description

Ctx_blobs.sql Import & index a range of documents

Ctx_bfiles.sql Import & index BFILE pointers

Ctx_urls.sql Index & search URL references

Ctx_dict.sql Index & search English dictionary words

Ctx_views.sql Index view SQL text for impact analysis

Ctx_apex_files.sql Duplicate and search Apex file repository

Ctx_apex_backups.sql Hunt through your (automated) Apex app backups

Ctx_names.sql Basic name filter options

Ctx_products.sql Multiple column searches

Ctx_category.sql Attribute based searching

Ctx_classify.sql Classify documents into categories

Page 92: Oracle Text in APEX
Page 93: Oracle Text in APEX
Page 94: Oracle Text in APEX
Page 95: Oracle Text in APEX
Page 96: Oracle Text in APEX
Page 97: Oracle Text in APEX
Page 98: Oracle Text in APEX
Page 99: Oracle Text in APEX
Page 100: Oracle Text in APEX
Page 101: Oracle Text in APEX
Page 102: Oracle Text in APEX
Page 103: Oracle Text in APEX
Page 104: Oracle Text in APEX
Page 105: Oracle Text in APEX
Page 106: Oracle Text in APEX
Page 107: Oracle Text in APEX
Page 108: Oracle Text in APEX
Page 109: Oracle Text in APEX
Page 110: Oracle Text in APEX
Page 111: Oracle Text in APEX
Page 112: Oracle Text in APEX

6) Index maintenance

Page 113: Oracle Text in APEX

indexing errors

Page 114: Oracle Text in APEX
Page 115: Oracle Text in APEX

resume failed index

Page 116: Oracle Text in APEX

ALTER INDEX ctx_surname

REBUILD PARAMETERS ('resume memory 10m');

Page 117: Oracle Text in APEX

recreate index online (11g)

Page 118: Oracle Text in APEX

EXEC ctx_ddl.recreate_index_online

('ctx_surname', 'replace lexer sw_lexer');

Page 119: Oracle Text in APEX

rebuilding an index

Page 120: Oracle Text in APEX

ALTER INDEX ctx_surname

REBUILD PARAMETERS('replace lexer sw_lexer')

ONLINE;

Page 121: Oracle Text in APEX

ctx_report.index_stats

Page 122: Oracle Text in APEX

create table ausoug.my_stats (stats clob);

declare

x clob := null;

begin

for r_rec in

(select *

from ctxsys.ctx_indexes

where idx_owner = 'AUSOUG'

and idx_type = 'CONTEXT') loop

ctx_report.index_stats(r_rec.idx_name,x);

insert into ausoug.my_stats values (x);

end loop;

commit;

dbms_lob.freetemporary(x);

end;

/

Page 123: Oracle Text in APEX

7) Data Dictionary

Page 124: Oracle Text in APEX
Page 125: Oracle Text in APEX
Page 126: Oracle Text in APEX
Page 127: Oracle Text in APEX
Page 128: Oracle Text in APEX

SQL> select count(*)

2 from all_views

3 where owner = 'CTXSYS';

COUNT(*)

----------

58

Page 129: Oracle Text in APEX

8) Common Questions

Page 130: Oracle Text in APEX

DML operations on a CONTEXT index

Page 131: Oracle Text in APEX

ctxsys.ctx_user_pending

Page 132: Oracle Text in APEX

synchronise the index

synchronize

Page 133: Oracle Text in APEX

EXEC ctx_ddl.sync_index('ctx_surname');

Page 134: Oracle Text in APEX

dbms_job

Page 135: Oracle Text in APEX

dbms_scheduler

Page 136: Oracle Text in APEX

how often?

Page 137: Oracle Text in APEX
Page 138: Oracle Text in APEX

optimise the index

Page 139: Oracle Text in APEX

can get fragmented

Page 140: Oracle Text in APEX

inverted index

Page 141: Oracle Text in APEX

each entry contains list of documents

Page 142: Oracle Text in APEX

DOG - DOC1 DOC3 DOC5

DOG - DOC7

DOG - DOC9

DOG - DOC11

Page 143: Oracle Text in APEX

ctx_ddl.optimize_index

Page 144: Oracle Text in APEX

capacity planning?

Page 145: Oracle Text in APEX

Object of Interest Num

Rows

Table

Size

Index

size

Dictionary 150k 7 27

Documents 28 34 1.5

Names 27k 1 6

Views 2k 7 2

BFiles 4

Product 1

URL 1

Page 146: Oracle Text in APEX

more text

Page 147: Oracle Text in APEX

cleaner data

Page 148: Oracle Text in APEX

less overhead

Page 149: Oracle Text in APEX

document format

Page 150: Oracle Text in APEX
Page 151: Oracle Text in APEX

next steps?

Page 152: Oracle Text in APEX

read Application Developer’s Guide

Page 153: Oracle Text in APEX
Page 154: Oracle Text in APEX

find examples

Page 155: Oracle Text in APEX

experiment

Page 156: Oracle Text in APEX

SAGE Computing Services

Customised Oracle Training Workshops and Consulting

Question time

Presentations are available from our website:

http://www.sagecomputing.com.au

[email protected]

[email protected]

http://triangle-circle-square.blogspot.com