Full Text search

์—ฌ๋Ÿฌ๋ถ„์ด ๊ฒŒ์‹œํŒ ์„œ๋น„์Šค๋ฅผ ์šด์˜ํ•œ๋‹ค๊ณ  ์นฉ์‹œ๋‹ค.

๊ทธ๋ž˜์„œ ํ…Œ์ด๋ธ” ํ•˜๋‚˜์— ๊ฒŒ์‹œ๋ฌผ์˜ ๊ธ€๋‚ด์šฉ, ์ž‘์„ฑ์ž, ๋ฐœํ–‰์ผ์„ ์ €์žฅํ•˜๊ธฐ ์‹œ์ž‘ํ–ˆ๋Š”๋ฐ

๊ฒ€์ƒ‰๊ธฐ๋Šฅ์ด ํ•„์š”ํ•ด์ง„๊ฒ๋‹ˆ๋‹ค. ๊ฒ€์ƒ‰๊ธฐ๋Šฅ์€ ์–ด๋–ป๊ฒŒ ๊ตฌํ˜„ํ•˜์ฃ ?

LIKE ์—ฐ์‚ฐ์ž

์˜ˆ์ „์— ๊ฐ„๋‹จํ•œ ๊ฒ€์ƒ‰๊ธฐ๋Šฅ ๋งŒ๋“ค๊ณ  ์‹ถ์œผ๋ฉด ์ปฌ๋Ÿผ๋ช… LIKE %๋‹จ์–ด% ํ•˜๋ฉด ๋œ๋‹ค๊ณ  ํ–ˆ์Šต๋‹ˆ๋‹ค.

์งง์€ ๋ฌธ์žฅ ์•ˆ์—์„œ ๊ฒ€์ƒ‰ํ•˜๋Š”๊ฑด ์ด๊ฑธ๋กœ ์ถฉ๋ถ„ํ•˜์ง€๋งŒ

1. % ๊ธฐํ˜ธ๋ฅผ ๋งจ ์•ž์— ์“ฐ๋ฉด ์ธ๋ฑ์Šคํ™œ์šฉ์„ ๋ชปํ•˜๊ณ 

2. ๋ฌธ์žฅ์ด ์ข€ ๊ธธ๊ฑฐ๋‚˜ ํ–‰์ด ๋„ˆ๋ฌด ๋งŽ์•„์ง€๋ฉด LIKE ๋งŒ์œผ๋กœ๋Š” ๋งค์šฐ ๋Š๋ฆฌ๊ฒŒ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ full text index๋ฅผ ๋งŒ๋“ค์–ด๋‘๋ฉด ๊ฑฑ์ •์—†์Šต๋‹ˆ๋‹ค.

Full text search๋ฅผ ์œ„ํ•œ index

๊ธด ๊ธ€๋„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ์ปฌ๋Ÿผ ํ•˜๋‚˜์— ๋ณด๊ด€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

text ๋ฐ์ดํ„ฐํƒ€์ž… ์“ฐ๋ฉด 6๋งŒ5์ฒœ์ž๋ฅผ ๋ณด๊ด€ํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ๊นŒ์š”.

์ด๋ ‡๊ฒŒ ๊ธด ๊ธ€ ์•ˆ์—์„œ ์›ํ•˜๋Š” ๋‹จ์–ด๋ฅผ ๊ฒ€์ƒ‰ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ๋‹น์—ฐํžˆ index๋ฅผ ๋งŒ๋“ค์–ด๋‘์–ด์•ผ ๊ฒ€์ƒ‰์ด ๋นจ๋ผ์ง‘๋‹ˆ๋‹ค.

๊ทผ๋ฐ ๊ธด ๊ธ€์€ ๊ทธ๋ƒฅ index ๋ง๊ณ  full text search index๋ฅผ ๋งŒ๋“ค์–ด๋‘๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๊ถ๊ธˆํ• ๊นŒ๋ด ์–ด๋–ค ์›๋ฆฌ๋กœ index๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๋Š”์ง€ ์„ค๋ช…ํ•˜์ž๋ฉด

id
๊ธ€

1

I run regularly.

2

I eat breakfast.

3

I like running.

4

I like eating pizza.

5

I swim in the sea.

์ด๋Ÿฐ ํ…Œ์ด๋ธ”์ด ์žˆ๋‹ค๊ณ  ์นฉ์‹œ๋‹ค.

์ด ํ…Œ์ด๋ธ”์— full text index๋ฅผ ๋งŒ๋“ค๋ผ๊ณ  ์‹œํ‚ค๋ฉด

๋‹จ์–ด

์–ด๋–ค ํ–‰์— ๋‚˜์˜ค๋ƒ๋ฉด

eat

2, 4

run

1, 3

swim

5

๊ธด ๊ธ€์— ์žˆ๋Š” ๋ชจ๋“  ๋‹จ์–ด๋ฅผ ๋ฝ‘์•„์„œ ์ •๋ ฌํ•ด์ฃผ๊ณ 

๊ทธ ๋‹จ์–ด๊ฐ€ ์–ด๋–ค ํ–‰์— ์ถœ๋ชฐ์ค‘์ธ์ง€๋ฅผ ์˜†์— ์ ์–ด๋‘ก๋‹ˆ๋‹ค.

์ด๋Ÿฌ๋ฉด eat ์ด๋Ÿฐ ๋‹จ์–ด๋ฅผ ๊ฒ€์ƒ‰ํ–ˆ์„ ๋•Œ ์–ด๋–ค ํ–‰์— ๋“ค์–ด์žˆ๋Š”์ง€ ์‰ฝ๊ฒŒ ํŒŒ์•…๊ฐ€๋Šฅํ•˜๊ฒ ์ฃ ?

์ด๊ฒŒ ๋์ž…๋‹ˆ๋‹ค.

๊ทผ๋ฐ ๋ฌธ์žฅ ์•ˆ์—์„œ stopwords๋ผ๊ณ  ๋ถ€๋ฅด๋Š”

"is the a are and I" ๋“ฑ ๋‚ด์šฉ๊ณผ ์ƒ๊ด€์—†๋Š” ์“ธ๋ฐ์—†๋Š” ๋‹จ์–ด๋“ค์„ ์ œ๊ฑฐํ•˜๊ณ  index๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ ์›น์˜ ๊ฒ€์ƒ‰์—”์ง„๋“ค์ด is the a are ์ด๋Ÿฐ ๋‚ด์šฉ ๋ถ™์—ฌ์„œ ๊ฒ€์ƒ‰ํ•˜๋ฉด ๋Œ€๋ถ€๋ถ„ ๋ฌด์‹œํ•˜๋Š” ์ด์œ ๊ฐ€ ๊ทธ๊ฒ๋‹ˆ๋‹ค.

Full text index ๋งŒ๋“œ๋Š” ๋ฒ•

CREATE INDEX LIB_IDX_TEXT ON TEST.LIBRARY (์„œ๋ช…)
indextype is ctxsys.context;

Index ์„ฑ๋Šฅ ํ‰๊ฐ€

1. LIKE ๊ฒ€์ƒ‰ ์‹œ ์„ฑ๋Šฅ

2. CONTAINS ๊ฒ€์ƒ‰ ์‹œ ์„ฑ๋Šฅ

Full text index๋ฅผ ์ด์šฉํ•ด ๊ฒ€์ƒ‰ํ•˜๋ ค๋ฉด

WHERE ๋’ค์— ์กฐ๊ฑด์‹ ํ˜•ํƒœ๋กœ CONTAINS(์ปฌ๋Ÿผ๋ช… , '%์ฐพ์„๋‹จ์–ด%') > 0 ์ด๋Ÿฐ์‹์œผ๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

SELECT *
  FROM LIBRARY l 
 WHERE CONTAINS(์„œ๋ช…, '%๋ถ€๋™์‚ฐ%') > 0;

์ด๋ ‡๊ฒŒ ์ž‘์„ฑํ•ด์„œ ์‹คํ–‰ํ•ด๋ด…์‹œ๋‹ค.

๊ทธ๋Ÿผ '๋ถ€๋™์‚ฐ' ์ด๋ผ๋Š” ์ •ํ™•ํ•œ ๋‹จ์–ด๋ฅผ ๊ฐ€์ง„ ํ–‰์„ ๋งค์šฐ ๋น ๋ฅด๊ฒŒ ํ•„ํ„ฐ๋งํ•ด์ค๋‹ˆ๋‹ค.

์ง„์งœ ๋น ๋ฅธ์ง€ ํ™•์ธํ•˜๋ ค๋ฉด execution plan ๋ˆŒ๋Ÿฌ๋ด…์‹œ๋‹ค.

Oracle Text ๊ด€๋ฆฌํ•  ๋•Œ ์ฃผ์˜์‚ฌํ•ญ

- ์ด ์ •๋„์˜ ์„ฑ๋Šฅ ๋ง๊ณ  ๋„ค์ด๋ฒ„, ๊ตฌ๊ธ€, ๋Œ€ํ˜•์‡ผํ•‘๋ชฐ์ฒ˜๋Ÿผ ๊ฒ€์ƒ‰์„ฑ๋Šฅ์ด ์•„์ฃผ ์ค‘์š”ํ•œ ์‚ฌ์ดํŠธ๋ฅผ ๋งŒ๋“ค๊ณ  ์žˆ๋‹ค๋ฉด

elastic search๋ผ๋“ ์ง€ ๊ฒ€์ƒ‰๋งŒ์„ ์œ„ํ•œ DB ๋˜๋Š” ์„œ๋น„์Šค๋ฅผ ๋”ฐ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ทธ๊ฑธ ์“ฐ๋Š”๊ฒŒ ๋‚˜์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

- ๋‹ค๋ฅธ DBMS๋Š” ๋‹ค๋ฅธ ๋ฌธ๋ฒ•์ด๋‚˜ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์•„์„œ ํ•„์š” ์‹œ ๋”ฐ๋กœ ๊ฒ€์ƒ‰ํ•ด๋ด…์‹œ๋‹ค.

(์ฐธ๊ณ )

Oracle Text๋ฅผ์˜ˆ์ „์—๋Š” Intermedia Text ๋ผ๊ณ  ๋ถˆ๋ ธ์—ˆ์Šต๋‹ˆ๋‹ค.

๋˜๋Š” Domain Index ๋ผ๊ณ  ๋ถ€๋ฅด๋Š” ์‚ฌ๋žŒ๋„ ์žˆ๊ณ , Text Index ๋ผ๊ณ  ๋ถ€๋ฅด๋Š” ์‚ฌ๋žŒ๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ชจ๋‘ ๊ฐ™์€ ๊ฒ๋‹ˆ๋‹ค.

Last updated