1 of 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

2 of 156

Agenda

  • Introduction
  • Architecture
  • Fundamentals
  • Considerations
  • Setting Up
  • Samples
  • Index Maintenance
  • Visualisation
  • New Features

3 of 156

Larry Lessig?

4 of 156

the law is strangling creativity

5 of 156

Identity 2.0 – Dick Hardt

6 of 156

who’s the Dick on your site

7 of 156

Connor McDonald

8 of 156

so today’s going to be more like this

9 of 156

and this

10 of 156

after I show a few pictures

11 of 156

who_am_i;

12 of 156

13 of 156

14 of 156

15 of 156

balance

16 of 156

17 of 156

18 of 156

19 of 156

20 of 156

21 of 156

22 of 156

23 of 156

Why use Oracle Application Express?

24 of 156

Why use Oracle Text?

25 of 156

26 of 156

What is Oracle Text?

27 of 156

Document Collection

28 of 156

29 of 156

Catalogue Information

30 of 156

31 of 156

Document Classification

32 of 156

33 of 156

Architecture

34 of 156

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?

35 of 156

1) Example

36 of 156

CREATE INDEX ctx_name ON my_names(name)

INDEXTYPE IS ctxsys.context

PARAMETERS ('DATASTORE CTXSYS.DEFAULT_DATASTORE');

37 of 156

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.

38 of 156

2) Datastore

39 of 156

CTXSYS.DEFAULT_DATASTORE

40 of 156

BLOB

41 of 156

BFiles

42 of 156

Pointers to objects on file system

43 of 156

URLs

44 of 156

Pointers to objects on the intertube

45 of 156

User Defined

46 of 156

Why would you?

47 of 156

3) Index Type

48 of 156

a) CONTEXT

49 of 156

Document Collection

50 of 156

large document size

51 of 156

provides a score

52 of 156

asynchronous index & table data

53 of 156

54 of 156

CONTAINS

55 of 156

b) CTXCAT

56 of 156

Catalogue Information

57 of 156

smaller documents

58 of 156

text fragments

59 of 156

multiple attributes

60 of 156

set lists

61 of 156

similar to typical index paradigm

62 of 156

transactional

63 of 156

64 of 156

CATSEARCH

65 of 156

c) CTXRULE

66 of 156

Document Classification

67 of 156

routing information

68 of 156

displace manual interaction

69 of 156

not binary files

70 of 156

MATCHES

71 of 156

4) Considerations

72 of 156

location of text

73 of 156

document format

74 of 156

bypassing rows - images

75 of 156

character set

76 of 156

language

77 of 156

fuzzy matching & stemming

78 of 156

wildcard query performance

79 of 156

80 of 156

stopwords & stopthemes

81 of 156

query performance and storage of LOBs

82 of 156

mixed queries

83 of 156

5) Setting up

84 of 156

GRANT ctxapp TO ausoug;

85 of 156

create & delete indexing preferences

86 of 156

use Oracle Text PL/SQL supplied packages

87 of 156

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.

88 of 156

PLS-00201: identifier "string" must be declared

89 of 156

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;

90 of 156

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');

91 of 156

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

92 of 156

93 of 156

94 of 156

95 of 156

96 of 156

97 of 156

98 of 156

99 of 156

100 of 156

101 of 156

102 of 156

103 of 156

104 of 156

105 of 156

106 of 156

107 of 156

108 of 156

109 of 156

110 of 156

111 of 156

112 of 156

6) Index maintenance

113 of 156

indexing errors

114 of 156

115 of 156

resume failed index

116 of 156

ALTER INDEX ctx_surname

REBUILD PARAMETERS ('resume memory 10m');

117 of 156

recreate index online (11g)

118 of 156

EXEC ctx_ddl.recreate_index_online

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

119 of 156

rebuilding an index

120 of 156

ALTER INDEX ctx_surname

REBUILD PARAMETERS('replace lexer sw_lexer')

ONLINE;

121 of 156

ctx_report.index_stats

122 of 156

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;

/

123 of 156

7) Data Dictionary

124 of 156

125 of 156

126 of 156

127 of 156

128 of 156

SQL> select count(*)

2 from all_views

3 where owner = 'CTXSYS';

COUNT(*)

----------

58

129 of 156

8) Common Questions

130 of 156

DML operations on a CONTEXT index

131 of 156

ctxsys.ctx_user_pending

132 of 156

synchronise the index

synchronize

133 of 156

EXEC ctx_ddl.sync_index('ctx_surname');

134 of 156

dbms_job

135 of 156

dbms_scheduler

136 of 156

how often?

137 of 156

138 of 156

optimise the index

139 of 156

can get fragmented

140 of 156

inverted index

141 of 156

each entry contains list of documents

142 of 156

DOG - DOC1 DOC3 DOC5

DOG - DOC7

DOG - DOC9

DOG - DOC11

143 of 156

ctx_ddl.optimize_index

144 of 156

capacity planning?

145 of 156

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

146 of 156

more text

147 of 156

cleaner data

148 of 156

less overhead

149 of 156

document format

150 of 156

151 of 156

next steps?

152 of 156

read Application Developer’s Guide

153 of 156

154 of 156

find examples

155 of 156

experiment

156 of 156

SAGE Computing Services

Customised Oracle Training Workshops and Consulting

Question time

Presentations are available from our website:

http://www.sagecomputing.com.au

enquiries@sagecomputing.com.au

scott.wesley@sagecomputing.com.au

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