用Stop List来缩小Oracle全文索引的大小

    Oracle的全文索引是一个很好的搜索解决方案, 不过随着要搜索的内容的增加, 会发现全文搜索的索引会耗掉很多的空间, 也在一定的程度上影响了全文索引的查询速度. 我们可以用如下方法去看, Oracle是如何划分单词的, 如在CR_CTXDEMO表的COL2列上面建一了个CTXSYS.CONTENT类型的全文索引, 则可以用如下SQL语句去查询:

SELECT TOKEN_TEXT, COUNT(*)
  FROM DR$IDX_CR_CTXDEMO_COL2$I
  WHERE ROWNUM < 1000000
  GROUP BY TOKEN_TEXT
  HAVING COUNT(*) > 1000

    可能会得到如下这样的结果:

TOKEN_TEXT          COUNT(*)
----------------- ----------
01                    107284
02                    104629
03                    103982
04                    103776
05                    103362
06                    101581

    看起来是一些无用的单词占据了大部份的记录, 如果确定用户不太会用这样的单词做搜索, 则可以用Stop List来过滤这些单词, 让Oracle在维护全文索引时不索引这些单词, 这样的话全文索引占用的空间就要小多了. 创建一个这样的Stop List的代码:

begin
    ctx_ddl.create_stoplist('DEMO_STOPLIST', 'BASIC_STOPLIST');
    ctx_ddl.add_stopword('DEMO_STOPLIST', '01');
    ctx_ddl.add_stopword('DEMO_STOPLIST', '02');
    ctx_ddl.add_stopword('DEMO_STOPLIST', '03');
    ctx_ddl.add_stopword('DEMO_STOPLIST', '04');
    ctx_ddl.add_stopword('DEMO_STOPLIST', '05');
    ctx_ddl.add_stopword('DEMO_STOPLIST', '06');
end;
/

    然后在创建索引或Rebuild索引时加上StopList参数就可以了, 如下所示:

create index idx_cr_ctxdemo_col2 on cr_ctxdemo(col2)
  indextype is ctxsys.context
  parameters ('stoplist DEMO_STOPLIST');

ALTER INDEX idx_cr_ctxdemo_col2 REBUILD
  PARAMETERS ('REPLACE STOPLIST DEMO_STOPLIST');

    要作优化要懂的东西还真不少!

留言 (3)

这个东西好呀, 我们一个在Production用了一段时间Oracle Text 啦.

我就想问问你是从哪里找到这个窍门的 ?
(不要说是度User Guide, 给读出来的, 哈哈)

想出来的啊.

我用的是CTXCAT index, 同样是找 $i table.
SELECT DR$TOKEN, COUNT(*)
FROM abedba.DR$WANTS_AUT_X$I
WHERE ROWNUM GROUP BY DR$TOKEN
HAVING COUNT(*) > 1000
order by 2 desc
;

随后我在贴出我的全套解决办法, 针对 CTXCAT catalog index.

发表留言:

« Previous | Main | Next »

英语900句 | English 900

  • I find classical concerts more to my liking than rock concerts.
  • 我觉得古典音乐会比摇滚音乐会更合我胃口.
  • I've never read a more stirring story.
  • 我从来没读过比这更令人激动的故事.
  • He has a passion for literature.
  • 他很热衷于文学.
  • I am most attracted by Dickens.
  • 狄更斯的作品更吸引我.
  • I never grow tired of novels though I read them everyday.
  • 我每天看小说, 但从没厌烦过.