Oracle

게시글 보기
작성자 유건데이타 등록일 2015-05-18
제목 CONTEXT 검색어의 HIGHLIGHTING 방법
Context option


CONTEXT 검색어의 HIGHLIGHTING 방법
==================================


Purpose
-------
Context option을 이용하여 원하는 단어를 검색할 때 찾는 단어를 강조하여
나타내는 방법에 대해 알아보자.


Explanation
-----------

Context Cartridate는 원하는 검색어가 있는 문서를 찾은 후에
문서를 조회하면서 그 검색어를 Highlighting 시키는 기능을 제공한다.
이 기능은 CTX_QUERY.HIGHLIGHT procedure를 통해 구현할 수 있다.

1. Highlighting 의 구현 방법

(1) Highlighted Document (MUTAB table 이용)
검색어로 선택한 문서를 특정 table에 highlight 된 형태로
저장하여 그 table을 조회하는 방법이다.

(2) Offset Information (HIGHTAB table의 이용)
해당 문서에서 highlight 해야 할 검색어의 offset 정보 즉, position과
length 만 저장하고 실제 검색시에 highlighting하는 방법이다.

(3) 검색어의 Highlighting
Highlighting은 보통 검색어 앞 뒤에 미리 지정한 문자를 첨가하는 것으로
나타낸다. 사용자가 따로 highlight 문자를 지정하지 않으면 기본적으로
검색어의 앞 뒤에 '<<<'과 '>>>' 를 highlighting 문자로 사용한다.

2. CTX_QUERY.HIGHLIGHT procedure

CTX_QUERY.HIGHLIGHT(
cspec IN VARCHAR2,
textkey IN VARCHAR2,
query IN VARCHAR2 DEFAULT NULL,
id IN NUMBER DEFAULT NULL,
nofilttab IN VARCHAR2 DEFAULT NULL,
plaintab IN VARCHAR2 DEFAULT NULL,
hightab IN VARCHAR2 DEFAULT NULL,
icftab IN VARCHAR2 DEFAULT NULL,
mutab IN VARCHAR2 DEFAULT NULL,
starttag IN VARCHAR2 DEFAULT NULL,
endtag IN VARCHAR2 DEFAULT NULL);

(1) cspec - 문서가 저장된 컬럼의 policy name 을 지정한다.
(2) textkey - 해당 문서의 primary key 를 지정한다.
(3) query - 문서를 찾기 위한 검색어를 지정한다.
(4) id - result table에 저장시 사용되는 query id이다.
(5) hightab - highlight를 위한 offset 정보를 저장할 table을
지정한다.
(6) mutab - highlight 된 문서를 저장할 table을 지정한다.
(7) starttag - highlight를 할 검색어의 앞에 나타낼 tag를
지정한다. 문서 종류에 따른 default 문자는 다음과 같다.
. ASCII와 formatted documents - '<<<'
. external filter를 사용한 HTML documents - '<<<'
. internal HTML filter를 사용한 HTML documents
- HTML tag ()
(8) endtag - highlight를 할 검색어의 끝에 나타낼 tag를
지정한다. 문서 종류에 따른 default 문자는 다음과 같다.
. ASCII와 formatted documents - '>>>'
. external filter를 사용한 HTML documents - '>>>'
. internal HTML filter를 사용한 HTML documents
- HTML tag ()


Example
-------

1. Highlight 된 문서를 저장하기 위한 MUTAB table과 highlighting
정보를 저장하기 위한 HIGHTAB table 그리고 result table을 생성한다.

create table mu_text ( id number, document varchar2(2000) );
create table high_offset ( id number,
offset number,
length number,
strength number);
create table ctx_temp ( textkey number,
score number,
conid number);

2. 검색어를 통해 원하는 문서를 찾는다.

exec ctx_query.contains('art_title','new','ctx_temp');

3. 검색어를 highlight 처리하여 mu_text table에 insert하고
high_offset table에는 highlighting 정보를 입력한다.

declare
cursor c1 is
select textkey from ctx_temp, articles
where article_id = textkey;
tk ctx_temp.textkey%type;
begin
open c1;
loop
fetch c1 into tk;
exit when c1%notfound;
ctx_query.highlight(
cspec => 'ART_TITLE',
textkey => tk,
query => 'new',
id => tk,
mutab => 'mu_text',
hightab => 'high_offset');
end loop;
end;
/

4. mu_text table을 select하여 결과를 확인한다.

select score Rank, textkey Key, document
from ctx_temp, mu_Text
where id = textkey
order by score desc;

RANK KEY DOCUMENT
------- --- -------------------------------------------------------
6 12 Technology: Honeywell Bull <<>> Computer Called
Fastest
6 15 Who's News: Leeco Diagnostics Has <<>> Top
Executives; Recordati Stake Cite
6 35 Supermarkets Push Private-Label Lines --- They Upgrade
Brands, Launch <<>>

5. high_offset table을 이용하여 highlighting시킨다.

declare
tk number;
v_title varchar2(2000);
cursor c1 is
select textkey, title from ctx_temp, articles
where article_id = textkey;
cursor c2 is
select offset, length from high_offset
where id = tk
order by offset desc;
begin
open c1;
loop
fetch c1 into tk, v_title;
exit when c1%notfound;
for i in c2 loop
v_title := substr(v_title,1,i.offset -1)||
'/*'||substr(v_title,i.offset, i.length)||'*/'||
substr(v_title,i.offset+i.length);
dbms_output.put_line(v_title);
end loop;
end loop;
end;
/

Technology: Honeywell Bull /*New*/ Computer Called Fastest
Who's News: Leeco Diagnostics Has /*New*/ Top Executives;
Recordati Stake Cited
Supermarkets Push Private-Label Lines --- They Upgrade Brands,
Launch /*New*/ Products
Comment
등록된 코멘트가 없습니다.