Skip to content

Commit 8d6767c

Browse files
Merge pull request #257 from oracle-devrel/ulrike23c-scripts2
Ulrike23c scripts2
2 parents 104bfe4 + a0ed78d commit 8d6767c

File tree

7 files changed

+91
-0
lines changed

7 files changed

+91
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
REM Script for 23c: 1-create-ubiquitous-index.sql
2+
REM Create an ubiquitous index
3+
4+
-- prereq: install Oracle Customer order sample schema from https://github.com/oracle-samples/db-sample-schemas/tree/main/customer_orders
5+
-- create an ubiquitous index with the name SEARCH_PRODUCTS
6+
7+
execute DBMS_SEARCH.CREATE_INDEX(index_name=>'SEARCH_PRODUCTS');
8+
9+
-- it creates the infrastructure for Oracle Text including a table SEARCH_PRODUCTS with two JSON columns DATA and METADATA.
10+
11+
desc SEARCH_PRODUCTS
12+
13+
-- if you need to drop the index first use
14+
-- execute DBMS_SEARCH.DROP_INDEX('SEARCH_PRODUCTS');
15+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
REM Script for 23c: 2-add-data-sources.sql
2+
REM Add two tables as data sources
3+
4+
-- Let's add the table SHIPMENTS and STORES
5+
6+
execute DBMS_SEARCH.ADD_SOURCE(index_name =>'SEARCH_PRODUCTS', source_name => 'SHIPMENTS');
7+
execute DBMS_SEARCH.ADD_SOURCE(index_name =>'SEARCH_PRODUCTS', source_name => 'STORES');
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
REM Script for 23c: 3-review-virtual-document.sql
2+
REM Review the virtual document
3+
4+
-- GET_DOCUMENT returns a virtual indexed document that is created after populating it with the two tables.
5+
6+
set long 1000 longc 500
7+
select DBMS_SEARCH.GET_DOCUMENT (INDEX_NAME=>'SEARCH_PRODUCTS', DOCUMENT_METADATA=>METADATA) output
8+
from SEARCH_PRODUCTS;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
REM Script for 23c: 4-contains-query.sql
2+
REM Query using CONTAINS
3+
4+
-- Query using CONTAINS with FUZZY operator
5+
6+
select metadata output from SEARCH_PRODUCTS
7+
where CONTAINS(data,'fuzzy(Los)')>0;
8+
9+
-- check the result in table STORES
10+
11+
select physical_address from stores where store_id=10;
12+
13+
-- check the result in table SHIPMENTS
14+
15+
select delivery_address from shipments where shipment_id=976;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
REM Script for 23c: 5-json-textcontains-query.sql
2+
REM Query using JSON_TEXTCONTAINS
3+
4+
-- JSON_TEXTCONTAINS checks if a specified string exists in JSON property values or not.
5+
select metadata from SEARCH_PRODUCTS
6+
where JSON_TEXTCONTAINS(data,'$.CO.STORES.PHYSICAL_ADDRESS','fuzzy(LOS)');
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
REM Script for 23c: 6-add-more-data-sources.sql
2+
3+
-- Let's add the table CUSTOMERS
4+
5+
execute DBMS_SEARCH.ADD_SOURCE(index_name =>'SEARCH_PRODUCTS', source_name => 'CUSTOMERS');
6+
7+
-- Search for fuzzy(jon)
8+
9+
SELECT METADATA output from SEARCH_PRODUCTS WHERE CONTAINS(data,'fuzzy(jon)')>0;
10+
11+
--Let's add a row to the table CUSTOMERS und search for it again.
12+
13+
insert into customers values (1000,'[email protected]','John Johnson');
14+
15+
SELECT METADATA output from SEARCH_PRODUCTS WHERE CONTAINS(data,'fuzzy(jon)')>0;
16+
17+
-- You will find the new row when you commit the change.
18+
19+
commit;
20+
21+
-- search again
22+
SELECT METADATA output from SEARCH_PRODUCTS WHERE CONTAINS(data,'fuzzy(jon)')>0;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
REM Script for 23c: 7-monitoring-index.sql
2+
3+
-- Query USER_INDEXES to get basic information about the created index.
4+
col index_type format a10
5+
col ityp_owner format a10
6+
col table_owner format a10
7+
col table_name format a20
8+
9+
select index_type, table_owner, table_name, table_type, status, ityp_owner
10+
from user_indexes where index_name='SEARCH_PRODUCTS';
11+
12+
-- Query CTX_INDEX_VALUES to display values for each object used in the index. You need to have access on CTXSYS objects.
13+
14+
set linesize window
15+
16+
select ixv_class, ixv_object, ixv_attribute, ixv_value
17+
from ctxsys.ctx_index_values
18+
where ixv_index_owner='CO';

0 commit comments

Comments
 (0)