parser切词&全文检索

全文检索:
http://www.postgresql.org/docs/9.3/interactive/textsearch.html

postgres 切词:
http://blog.163.com/digoal@126/blog/static/163877040201422410175698/
ts_parse:获取切词后的所有词组
SELECT * FROM ts_parse('zhparser', 'hello world! 2010年保障房建设在全国范围');
SELECT * FROM ts_parse('english', 'hello world! 2010年保障房建设在全国范围');
to_tsvector,to_tsquery:获取一个text的所有切词
select to_tsvector('english', ' example is a concatenation of title and body');
select ' before, full text search functionality includes the ability to do many m' @@ 'ability';
select to_tsvector(' before, full text search functionality includes the ability to do many m') @@ to_tsquery('ability');
在tsvector字段上加Gin索引可以加快检索速度:
http://www.postgresql.org/docs/9.3/interactive/textsearch-tables.html#TEXTSEARCH-TABLES-SEARCH
建立一个索引需要格式如CREATE INDEX pgweb_idx ON pgweb USING gin(to_tsvector('english', body));#body==>text字段
建索引的时候需注意to_tsvector函数有两个版本That is, WHERE to_tsvector('english', body) @@ 'a & b' can use the index, but WHERE to_tsvector(body) @@ 'a & b' cannot.
CREATE INDEX name ON table USING gist(column);

Creates a GiST (Generalized Search Tree)-based index. The column can be of tsvector or tsquery type.

CREATE INDEX name ON table USING gin(column);

Creates a GIN (Generalized Inverted Index)-based index. The column must be of tsvector type.


使用zhparser插件:
一般postgresql的切词是english的,对于中文切词不支持。
http://blog.163.com/digoal@126/blog/static/163877040201422410175698/

 

posted @ 2014-05-30 10:34  bielidefeng  阅读(189)  评论(0编辑  收藏  举报