如何为'%abc%'搜索创建文本索引? [英] How to create text index for '%abc%' search?

查看:139
本文介绍了如何为'%abc%'搜索创建文本索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想索引像 x这样的查询,比如'%abc%'



如果我有表格如下所示:

pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' ;

我想创建一个索引以便能够高效地执行以下操作:

  select * from t where contains('%abc%'); 

与此:

  select * from t where contains('abc%'); 

我也希望这张表能够实时更新。



如何创建这样的索引? (我有一种感觉,我需要一个 ctxcat 索引,但我很困惑我需要给它什么选择)

我使用的是Oracle 10g。我将使用这个(设置您的最小和最大长度来定义适用的值)

  BEGIN 
ctx_ddl.create_preference('FT_WL','BASIC_WORDLIST');
ctx_ddl.set_attribute('FT_WL','substring_index','YES');
ctx_ddl.set_attribute('FT_WL','prefix_index','YES');
ctx_ddl.set_attribute('FT_WL','prefix_min_length',1);
ctx_ddl.set_attribute('FT_WL','prefix_max_length',6);
END;

CREATE INDEX fulltext_idx ON tmp_fulltext(全文)
INDEXTYPE是CTXSYS.CTXCAT
PARAMETERS('WORDLIST FT_WL')

参数在这里解释 Oracle Text Reference



并查看如何管理刷新以及索引可能不会更快的问题而不是全面扫描高基数数据:

LIKE'%...%'通配符查询的PL / SQL性能调优


I'd like to index queries like x like '%abc%'

If I have a table like the following

create table t
(
  data varchar(100)
);

I want to create an index to be able to do the following efficiently:

select * from t where contains('%abc%');

And this:

select * from t where contains('abc%');

I also want this table to be updated live.

How do I create such an index? (I have a feeling I need a ctxcat index, but I'm confused about what options I need to give it)

I'm using Oracle 10g.

解决方案

I would use this (set you min and max length to appropiate values)

BEGIN
    ctx_ddl.create_preference  ('FT_WL', 'BASIC_WORDLIST');
    ctx_ddl.set_attribute      ('FT_WL', 'substring_index',   'YES');
    ctx_ddl.set_attribute      ('FT_WL', 'prefix_index',      'YES');
    ctx_ddl.set_attribute      ('FT_WL', 'prefix_min_length', 1);
    ctx_ddl.set_attribute      ('FT_WL', 'prefix_max_length', 6);
  END;

CREATE INDEX fulltext_idx ON tmp_fulltext (fulltext)
 INDEXTYPE IS CTXSYS.CTXCAT
 PARAMETERS ('WORDLIST FT_WL')

The parameters are explained here Oracle Text Reference

and see this question on how to manage the refresh and how the index may not be quicker than a full scan with high cardinality data:

PL/SQL Performance Tuning for LIKE '%...%' Wildcard Queries

这篇关于如何为'%abc%'搜索创建文本索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆