Postgres喜欢全文搜索

问题描述 投票:0回答:1

我试图创建查询以在我的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,这与我喜欢的搜索不同。为什么这样,当两个查询似乎都在执行类似的搜索时

sql postgresql postgresql-9.4 postgresql-9.5
1个回答
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)

尝试“另一个”。

© www.soinside.com 2019 - 2024. All rights reserved.