【发布时间】:2013-12-25 22:16:26
【问题描述】:
对于这个问题,我真的束手无策,我真的希望有人能帮助我。我正在使用 Postgresql 9.3。我的数据库主要包含德语文本,但不仅如此,因此它以 utf-8 编码。我想建立一个支持德语的全文搜索,到目前为止没有什么特别的。 但是搜索的行为真的很奇怪,而且我找不到我做错了什么。
因此,以下表为例
select * from test;
a
-------------
ein Baum
viele Bäume
Überleben
Tisch
Tische
Café
\d test
Tabelle »public.test«
Spalte | Typ | Attribute
--------+------+-----------
a | text |
sintext=# \d
Liste der Relationen
Schema | Name | Typ | Eigentümer
--------+---------------------+---------+------------
(...)
public | test | Tabelle | paf
现在,让我们看一些文本搜索示例:
select * from test where to_tsvector('german', a) @@ plainto_tsquery('Baum');
a
-------------
ein Baum
viele Bäume
select * from test where to_tsvector('german', a) @@ plainto_tsquery('Bäume');
--> No Hits
select * from test where to_tsvector('german', a) @@ plainto_tsquery('Überleben');
--> No Hits
select * from test where to_tsvector('german', a) @@ plainto_tsquery('Tisch');
a
--------
Tisch
Tische
而 Tische 是 Tisch(桌子)的复数形式,而 Bäume 是 Baum(树)的复数形式。因此,当 textsearch 表现良好时,显然 Umlauts 不起作用。
但真正让我困惑的是,a) 非德语特殊字符正在匹配
select * from test where to_tsvector('german', a) @@ plainto_tsquery('Café');
a
------
Café
和b)如果我不使用德语词典,则变音符号没有问题(当然也没有真正的文本搜索)
select * from test where to_tsvector(a) @@ plainto_tsquery('Bäume');
a
-------------
viele Bäume
那么,如果我使用德语词典进行文本搜索,那么只有德语特殊字符不起作用?真的吗?这到底是怎么回事?实在想不通,求大神帮忙!
【问题讨论】:
-
作为 SQLFiddle:sqlfiddle.com/#!15/3d571/4
标签: postgresql utf-8 full-text-search diacritics