PostgreSQL全文搜索产生了奇怪的结果

时间:2017-02-15 10:43:39

标签: postgresql full-text-search finnish

我有这样的架构(简化):

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name NOT NULL
);
CREATE INDEX users_idx
ON users
USING GIN (to_tsvector('finnish', name));

但我的查询结果完全无效:

# select name from users where to_tsvector('finnish', name) @@ to_tsquery('lemmin');
 name 
------
(0 rows)

# select name from users where to_tsvector('finnish', name) @@ to_tsquery('lemmink');
       name                                       
--------------------
 Riitta ja Lemminki
 Riitta ja Lemminki
(2 rows)

# select name from users where name ilike 'lemmink%';
       name                  
----------------------
 Lemminkäinen Matilda
 Lemminkäinen Matias
 Lemminkäinen Kyösti
 Lemminkäinen Tuomas
(4 rows)

另一个例子:

# select name from users where to_tsvector('finnish', name) @@ to_tsquery('partu');
   name             
----------
 Partuuna
(1 row)

# select name from users where to_tsvector('finnish', name) @@ to_tsquery('partur');
         name                                    
------------------------
 Parturi-Kampaamo Raija
 Parturi-Kampaamo Siema
(2 rows)

我希望在两个查询中得到最后两个结果......

使用以下版本:

psql (9.4.6, server 9.5.2)
WARNING: psql major version 9.4, server major version 9.5.
         Some psql features might not work.

1 个答案:

答案 0 :(得分:-1)

我不会说芬兰语,但似乎是预期的结果。 FTS查找词汇,而不是单词的部分,例如do不是dog的词条,dogdogs的词句:

t=# select  to_tsvector('english', 'Dogs eats bone') @@ to_tsquery('do');
NOTICE:  text-search query contains only stop words or doesn't contain lexemes, ignored
 ?column?
----------
 f
(1 row)

t=# select  to_tsvector('english', 'Dogs eats bone') @@ to_tsquery('dog');
 ?column?
----------
 t
(1 row)

所以我相信Parturi最后i是可选结尾 - 对吗?

<强>更新 来自https://en.wiktionary.org/wiki/parturi: partur [i],partur [eita] =&gt; lexeme将成为