Informix BTS
Informix从11.7版本开始支持中文的全文本搜索功能BTS -- Basic Text Search。
传统关系型表上,我们通常通过 LIKE 或 MATCHES 条件来搜索文本数据,往往需要进行全表扫描,性能低下。
BTS提供全文本搜索能力,可以检索一个表上的字符数据类型列(BLOB, CHAR, CLOB, LVARCHAR, NCHAR, NVARCHAR, or VARCHAR)数据。
准备:
为使用BTS功能,准备如下:
1.创建一个默认的sbspace空间
2.可选项:为bts 索引创建一个单独的sbspace空间
3.可选项:创建一个临时的 sbspace空间
4.创建 bts 索引
通过CJK分词器可以支持中文搜索能力。
对于zh_cn.gb18030-2000字符集,需要设置环境变量GL_USEGLU=1,否则无法进行中文分词。
实例:
UTF-8字符集
1.set environment variables:
export DB_LOCALE=en_us.utf8
export CLIENT_LOCALE=en_us.utf8
2.test the bts function.
dbaccess utf8db test.sql
drop table if exists test;
create table test (name varchar(20));
insert into test values("国际商业机器");
create index idx_test_bts on test(name bts_varchar_ops) using bts(analyzer="CJK") in sbspace1;
select * from test where bts_contains(name,'国际');
select * from test where bts_contains(name,'际商');
select * from test where bts_contains(name,'商业');
select * from test where bts_contains(name,'业机');
select * from test where bts_contains(name,'机器');
select * from test where bts_contains(name,'国际');
name
国际商业机器
1 row(s) retrieved.
select * from test where bts_contains(name,'际商');
name
国际商业机器
1 row(s) retrieved.
select * from test where bts_contains(name,'商业');
name
国际商业机器
------------------------------------------------------------------------------------------------
zh_cn.GB字符集
1.set environment variables:
export DB_LOCALE=zh_cn.gb
export CLIENT_LOCALE=zh_cn.gb
2.test the bts function.
dbaccess gbdb test.sql
drop table if exists test;
create table test (name varchar(20));
insert into test values("国际商业机器");
create index idx_test_bts on test(name bts_varchar_ops) using bts(analyzer="CJK") in sbspace1;
select * from test where bts_contains(name,'国际');
select * from test where bts_contains(name,'际商');
select * from test where bts_contains(name,'商业');
select * from test where bts_contains(name,'业机');
select * from test where bts_contains(name,'机器');
select * from test where bts_contains(name,'国际');
name
国际商业机器
1 row(s) retrieved.
select * from test where bts_contains(name,'际商');
name
国际商业机器
1 row(s) retrieved.
select * from test where bts_contains(name,'商业');
name
国际商业机器
-----------------------------------------------------------------------------------------------------
1.set environment variables:
export GL_USEGLU=1
export DB_LOCALE=zh_cn.gb18030-2000
export CLIENT_LOCALE=zh_cn.gb18030-2000
2.restart the server
onmode -ky;oninit -vy
3.create a new database with zh_cn.gb18030-2000
create database gb18030db
4.test the bts function.
dbaccess gb18030db test.sql
drop table if exists test;
create table test (name varchar(20));
insert into test values("国际商业机器");
create index idx_test_bts on test(name bts_varchar_ops) using bts(analyzer="CJK") in sbspace1;
select * from test where bts_contains(name,'国际');
select * from test where bts_contains(name,'际商');
select * from test where bts_contains(name,'商业');
select * from test where bts_contains(name,'业机');
select * from test where bts_contains(name,'机器');
添加新评论0 条评论