Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
postgresql+;文本搜索+;德国umlauts&x2B;UTF8_Postgresql_Utf 8_Full Text Search_Diacritics - Fatal编程技术网

postgresql+;文本搜索+;德国umlauts&x2B;UTF8

postgresql+;文本搜索+;德国umlauts&x2B;UTF8,postgresql,utf-8,full-text-search,diacritics,Postgresql,Utf 8,Full Text Search,Diacritics,对于这个问题,我真的束手无策,我真的希望有人能帮助我。我使用的是Postgresql 9.3。我的数据库主要包含德语文本,但不仅如此,所以它是用utf-8编码的。我想建立一个支持德语的fulltextsearch,到目前为止没有什么特别的。 但是搜索的行为真的很奇怪,我无法找出我做错了什么 因此,以下表为例 select * from test; a ------------- ein Baum viele Bäume Überleben Tisch Tisch

对于这个问题,我真的束手无策,我真的希望有人能帮助我。我使用的是Postgresql 9.3。我的数据库主要包含德语文本,但不仅如此,所以它是用utf-8编码的。我想建立一个支持德语的fulltextsearch,到目前为止没有什么特别的。 但是搜索的行为真的很奇怪,我无法找出我做错了什么

因此,以下表为例

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(树)的复数。因此,当文本搜索性能良好时,Umlauts显然不起作用

但真正让我困惑的是,a)非德语特殊字符匹配

select * from test where to_tsvector('german', a) @@ plainto_tsquery('Café');
   a   
 ------
  Café
b)如果我不使用德语词典,umlauts就没有问题(当然也没有真正的文本搜索)


因此,如果我使用德语词典进行文本搜索,仅仅是德语特殊字符不起作用?真的吗?这到底是怎么回事?我真的搞不懂,请帮帮我

您在
to_tsvector
调用中明确使用了德语词典,但在
to_tsquery
plainto_tsquery
调用中没有使用德语词典。您的默认词典可能没有设置为
德语
;使用
SHOW default\u text\u search\u config
进行检查

比较:

regress=> select plainto_tsquery('simple', 'Bäume'),
                 plainto_tsquery('english','Bäume'), 
                 plainto_tsquery('german', 'Bäume');
 plainto_tsquery | plainto_tsquery | plainto_tsquery 
-----------------+-----------------+-----------------
 'bäume'         | 'bäume'         | 'baum'
(1 row)
语言设置会影响单词简化和根提取,因此一种语言的向量不一定与另一种语言的查询匹配:

regress=> SELECT to_tsvector('german', 'viele Bäume'), plainto_tsquery('Bäume'),
          to_tsvector('german', 'viele Bäume') @@ plainto_tsquery('Bäume');
    to_tsvector    | plainto_tsquery | ?column? 
-------------------+-----------------+----------
 'baum':2 'viel':1 | 'bäume'         | f
(1 row)
如果使用一致的语言设置,则一切正常:

regress=> SELECT to_tsvector('german', 'viele Bäume'), plainto_tsquery('german', 'Bäume'),
                 to_tsvector('german', 'viele Bäume') @@ plainto_tsquery('german', 'Bäume');
    to_tsvector    | plainto_tsquery | ?column? 
-------------------+-----------------+----------
 'baum':2 'viel':1 | 'baum'          | t
(1 row)

您在
to_tsvector
调用中明确使用了德语词典,但在
to_tsquery
plainto_tsquery
调用中没有使用德语词典。您的默认词典可能没有设置为
德语
;使用
SHOW default\u text\u search\u config
进行检查

比较:

regress=> select plainto_tsquery('simple', 'Bäume'),
                 plainto_tsquery('english','Bäume'), 
                 plainto_tsquery('german', 'Bäume');
 plainto_tsquery | plainto_tsquery | plainto_tsquery 
-----------------+-----------------+-----------------
 'bäume'         | 'bäume'         | 'baum'
(1 row)
语言设置会影响单词简化和根提取,因此一种语言的向量不一定与另一种语言的查询匹配:

regress=> SELECT to_tsvector('german', 'viele Bäume'), plainto_tsquery('Bäume'),
          to_tsvector('german', 'viele Bäume') @@ plainto_tsquery('Bäume');
    to_tsvector    | plainto_tsquery | ?column? 
-------------------+-----------------+----------
 'baum':2 'viel':1 | 'bäume'         | f
(1 row)
如果使用一致的语言设置,则一切正常:

regress=> SELECT to_tsvector('german', 'viele Bäume'), plainto_tsquery('german', 'Bäume'),
                 to_tsvector('german', 'viele Bäume') @@ plainto_tsquery('german', 'Bäume');
    to_tsvector    | plainto_tsquery | ?column? 
-------------------+-----------------+----------
 'baum':2 'viel':1 | 'baum'          | t
(1 row)

As-SQLFiddle:As-SQLFiddle:非常感谢!我不知道我怎么能监督。。。现在它工作得很好,这一天被拯救了:)非常感谢你!我不知道我怎么能监督。。。现在它可以完美地工作了,这一天就结束了:)