繁体   English   中英

Postgres 喜欢全文搜索

[英]Postgres Like to Full Text Search

我试图创建一个查询以在我的 sql 数据库中查找other名称。 我有一个基本的类似搜索,如下所示,并想改用全文搜索。

点赞查询

SELECT g.*, COUNT(*) OVER() AS total 
FROM group AS g 
WHERE UPPER(g.name) LIKE UPPER('oth%')

全文查询

SELECT g.*, COUNT(*) OVER() AS total 
FROM group AS g 
WHERE to_tsvector(g.name) @@ to_tsquery('oth:*') 

看来我的全文返回 0 不像我的喜欢搜索。 当两个查询似乎都在进行类似的搜索时,为什么会这样

看起来“其他”在英语的默认停用词列表中。 我已经在 Linux 级别使用 PostgreSQL 12 进行了测试:

$ grep other /usr/pgsql-12/share/tsearch_data/english.stop 
other

在数据库中:

postgres=# select to_tsvector('french','other');
 to_tsvector 
-------------
 'other':1
(1 row)

postgres=# select to_tsvector('english','other');
 to_tsvector 
-------------

(1 row)

postgres=# select to_tsvector('english','others');
 to_tsvector 
-------------
 'other':1
(1 row)

postgres=# select to_tsvector('english','another');
 to_tsvector 
-------------
 'anoth':1
(1 row)

尝试另一个'。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM