TEXT 질의
본 장에서는 Tibero TEXT 기능을 이용한 질의에 대해 설명합니다.
CATSEARCH
CATSEARCH는 CTXCAT 인덱스를 이용하기 위한 함수로 SELECT 문장의 WHERE 절에 사용됩니다.
사용법
CATSEARCH( column, text_query, reserved argument)
column
CTXCAT 인덱스가 걸려 있는 컬럼이다.
text_query
컬럼에서 찾을 Text를 정의하는 CATSEARCH 쿼리 연산이다.
reserved argument
추후 추가 기능 구현을 위해 예비된 argument이다.
CATSEARCH 쿼리 연산
CATSEARCH 쿼리는 다음의 6가지 연산을 지원합니다.
Logical AND
a b c
a, b, c 모두를 포함한 row를 찾는다.
Logical OR
a | b | c
a, b, c 중 하나 이상을 포함한 row를 찾는다.
Logical NOT
a - b
a를 포함하고 b를 포함하지 않는 row를 찾는다.
단독으로 사용될 수 없다.
" "
"a b c"
"a b c"로 구성된 구(phrase)를 포함한 row를 찾는다.
( )
(a b) | c
연산의 우선순위를 정한다.
a b를 먼저 계산하고 | c를 후에 계산한다.
와일드카드
ab*, a*b, *ab
*는 0개 이상의 임의의 문자를 나타낸다.
반환값
NUMBER 타입으로 의미를 가지지 않습니다.
예제
다음은 테이블 및 CTXCAT 인덱스를 생성하는 예제입니다.
SQL> create table book(id number, name varchar(4000));
SQL> create index book_ctxcatindex on book(name) ctxcatindex;
다음은 테이블에 데이터를 입력하는 예제입니다.
SQL> insert into book values(1,'The little boat.');
SQL> insert into book values(2,'The little yellow digger.');
SQL> insert into book values(3,'The magic pasta pot : an old tale.');
SQL> insert into book values(4,'The mousehole cat.');
SQL> insert into book values(5,'The pear in the pear tree.');
SQL> insert into book values(6,'The rainbow fish.');
SQL> insert into book values(7,'The story about Ping.');
다음은 데이터를 검색하는 예제입니다.
SQL> select * from book where catsearch(name, 'story ping', null) = 0;
ID NAME
------- --------------
7 The story about Ping.
1 row selected.
SQL> select * from book where catsearch(name, 'li*', null) = 0;
ID NAME
------- --------------
1 The little boat.
2 The little yellow digger.
2 rows selected.
SQL> select * from book where catsearch(name, '"little boat"', null) = 0;
ID NAME
------- --------------
1 The little boat.
1 row selected.
CONTAINS
CONTAINS는 CONTEXT 인덱스를 이용하기 위한 함수로 SELECT 문장의 WHERE 절에 사용됩니다.
사용법
CONTAINS( column, text_query, reserved argument)
column
CONTEXT 인덱스가 걸려 있는 컬럼이다.
text_query
column에서 찾을 Text를 정의하는 CONTAINS 쿼리 연산이다.
reserved argument
추후 추가 기능 구현을 위해 예비된 argument이다.
CONTAINS 쿼리 연산
CONTAINS 쿼리는 다음의 6가지 연산을 지원합니다.
Logical AND
a AND b
a, b 모두를 포함한 row를 찾는다.
Logical OR
a OR b, a | b
a, b 중 하나 이상을 포함한 row를 찾는다.
Logical NOT
a ~ b
a를 포함하고 b를 포함하지 않는 row를 찾는다.
SEQUENCE
a b
a b로 구성된 구(phrase)를 포함한 row를 찾는다.
와일드카드
ab%, %ab
%는 0개 이상의 임의의 문자를 나타낸다.
WITHIN
a WITHIN SEN TENCE, a WITHIN PARAGRAPH
a를 포함하고 있는 SENTENCE 또는 PARAGRAPH가 있는 row를 찾는다.
반환값
NUMBER 타입으로 의미를 가지지 않습니다.
예제
다음은 테이블 및 CONTEXT 인덱스 생성 및 입력하는 예제입니다.
SQL> create table t(c1 clob);
SQL> insert into t values('Paris Rome Warsav');
SQL> insert into t values('Seoul Incheon');
SQL> insert into t values('Paris Rome Seoul');
SQL> commit;
SQL> create index t_idx on t(c1) indextype is ctxsys.context;
다음은 데이터를 검색하는 예제입니다.
SQL> select * from t where contains(c1, 'Paris', NULL) > 0;
C1
------------------------------------------------------------------
Paris Rome Warsav
Paris Rome Seoul
2 rows selected.
SQL> select * from t where contains(c1, 'Paris and Warsav', NULL) > 0;
C1
-------------------------------------------------------------------
Paris Rome Warsav
1 row selected.
SQL> select * from t where contains(C1, 'Warsav | Seoul', null) = 0;
C1
---------------------------------------------------------------------
Paris Rome Warsav
Seoul Incheon
Paris Rome Seoul
3 rows selected.
SQL> select * from t where contains(c1, 'Paris - Seoul', NULL) > 0;
C1
---------------------------------------------------------------------
Paris Rome Warsav
Paris Rome Seoul
2 rows selected.
다음은 WITHIN 연산자를 사용해서 데이터를 검색하는 예제입니다.
LEXER 속성에 WHITESPACE 설 정이 필요하며 해당 내용은“TEXT Indexing Elements”를 참고합니다.
SQL> drop table t;
Table 'T' dropped.
SQL> create table t (c1 clob);
Table 'T' created.
SQL> insert into t values ('Paris.-Rome');
1 row inserted.
SQL> commit;
Commit completed.
SQL> select * from t;
C1
--------------------------------------------------------------------------
Paris.-Rome
1 row selected.
SQL> begin
2 text_ddl.create_preference('mylex','BASIC_LEXER');
3 text_ddl.set_attribute('mylex','WHITESPACE','-');
4 end;
5 /
PSM completed.
SQL> begin
2 text_ddl.create_section_group('nullgroup', 'NULL_SECTION_GROUP');
3 text_ddl.add_special_section('nullgroup', 'SENTENCE');
4 end;
5 /
PSM completed.
SQL> create index t_idx on t (a) indextype is ctxsys.context
2 parameters ('LEXER mylex sync (on commit) section group nullgroup');
Index 'T_IDX' created.
SQL> select * from t where contains(a, 'Paris Rome within sentence') > 0;
0 row selected.
SQL> select * from t where contains(a, 'Paris within sentence') > 0;
C1
-------------------------------------------------------------------------------
Paris.-Rome
1 row selected.
Last updated