转:http://hi.baidu.com/lostdays/blog/item/bcbd6d3e2428343e70cf6cab.html
建立测试表
create table ftstest(id integer, url text, url_ftx tsvector);
插入数据
insert into ftstest (id, url, url_ftx) values (1, 'www.sina.com.cn', 'www sina com cn'::tsvector);
这里说明 url_ftx 是 url 字段经过分词以后的结果 我这里是将“.”换为“ ”
如‘www.sina.com.cn ’ 转化为 'www sina com cn'
添加全文索引
create INDEX ftstest_url_ftx_idx on ftstest using gist (url_ftx);
测试查询
select * from ftstest where url_ftx @@ 'sina'::tsquery;
select * from ftstest where url_ftx @@to_tsquery('sina com cn')
本文介绍了如何在PostgreSQL中创建包含全文检索功能的表。包括表结构的设计、数据插入方法、全文索引的创建过程及如何进行有效的全文检索查询。
2225

被折叠的 条评论
为什么被折叠?



