1. 前言
在这篇文章中,介绍了PostgreSQL的全文检索系统,里面有提到,PostgreSQL默认是不支持中文的。看下面的例子。
rails365_pro=# SELECT '号'::tsquery @@ '2015 - Rails365 Inc. All rights reserved. | 粤ICP备15004902号-2'::tsvector;
?column?
----------
f
(1 row)
rails365_pro=# SELECT '粤ICP备15004902号'::tsquery @@ '2015 - Rails365 Inc. All rights reserved. | 粤ICP备15004902号-2'::tsvector;
?column?
----------
t
(1 row)
说明没有按照我们的意愿分词,我们可以自己来看看PostgreSQL是怎么分词的。只要用to_tsvector这个指令就好了。
rails365_pro=# SELECT to_tsvector('english', '2015 - Rails365 Inc. All rights reserved. | 粤ICP备15004902号-2');
to_tsvector
---------------------------------------------------------------------------------
'-2':8 '2015':1 'in