Sql Postgres喜欢全文搜索
我正在尝试创建一个查询,以在我的sql数据库中查找名称Sql Postgres喜欢全文搜索,sql,postgresql,postgresql-9.4,postgresql-9.5,Sql,Postgresql,Postgresql 9.4,Postgresql 9.5,我正在尝试创建一个查询,以在我的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_
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)
试试“另一个”